Q&A

  • 웹에서 다운받은 엑셀파일을 DB에 저장시키려면...
웹에서 다운받은 엑셀파일을 DB에 바로 저장시키려면 어떻게 해야 되남여 (고수님 제발가려켜 줘여 5일째 헤매고 있어여 )
이와 비슷한 내용의 소스가 있어면 공개좀해주시와여~~

#프로그램 설명
1단계:버튼을 클릭을 하면 어떤특정사이트의 다운로드방에서 다운로드(엑셀파일)을 지정한 경로에 다운로드 한다 (웹브라우즈 는 안뜨고여)
2단계:그리고 났어 DB에 같은 columns에 각각 저장시킴 (이또한 화면에 나타나지 않고여)
3단계:그리고 select 했어 DBgrid에 퍼뜨림

한번의 버튼클릭으로 이렇게 될수는 있는지 있어면
비슷한 소스좀 주시와여 제발여 고수님들~~~~흐흐흐 이문제 해결못하면 세상살기가 실어질것 같아여 이불쌍한 바둑이를 고수님들중에 구제 해주시와여...    
1  COMMENTS
  • Profile
    이추형 2003.03.06 22:55
    excel 처리관련 참조하세요
    unit main;

    interface

    uses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      Db, DBTables, StdCtrls, ExtCtrls, comobj,
      Buttons, ComCtrls, Grids ;

    type
      TForm1 = class(TForm)
        Database1: TDatabase;
        Choice_team: TQuery;
        Panel3: TPanel;
        SpeedButton1: TSpeedButton;
        SpeedButton2: TSpeedButton;
        Panel4: TPanel;
        Panel5: TPanel;
        Panel6: TPanel;
        Panel7: TPanel;
        Edit1: TEdit;
        Edit2: TEdit;
        Edit3: TEdit;
        Panel8: TPanel;
        Panel9: TPanel;
        ProgressBar1: TProgressBar;
        OpenDialog1: TOpenDialog;
        SpeedButton3: TSpeedButton;
        RichEdit1: TRichEdit;
        StringGrid1: TStringGrid;
        Panel1: TPanel;
        Panel2: TPanel;
        Edit4: TEdit;
        Panel10: TPanel;
        Panel11: TPanel;
        Edit5: TEdit;
        BitBtn1: TBitBtn;
        procedure FormShow(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure SpeedButton1Click(Sender: TObject);
        procedure SpeedButton2Click(Sender: TObject);
        procedure SpeedButton3Click(Sender: TObject);
      private
        { Private declarations }
      public
        Xlapp : variant ;
        { Public declarations }
      end;

    var
      Form1: TForm1;
      sql_String : string ;
      team_code : string ;
      how_many , bk_count : integer ;
    implementation

    {$R *.DFM}

    procedure TForm1.FormShow(Sender: TObject);
    var
      i : integer ;
    begin
    {
      sql_String := ' select * from tab' ;
      with Choice_team do begin
        close;
        sql.clear;
        sql.add(Sql_String);
        prepare;
        open;
      end;

      Choice_team.first ;
      for i := 1 to Choice_team.RecordCount do begin
        RichEdit1.Lines.Clear;
        RichEdit1.Lines.Add(Choice_team.fieldbyname('code_name11').asstring+'/'+Choice_team.fieldbyname('detail_code').asstring);
        Choice_team.next ;
      end;
      Choice_team.close;
    }
      Cursor := crHourGlass ;
      xlapp:= CreateOleObject('Excel.application');
      cursor := crDefault ;

    end;

    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
       // Excel OLE를 해제 시킵니다.
       XLApp.displayAlerts := False ; // Discard unsaved files ...
       xlapp.quit;

    end;

    procedure TForm1.SpeedButton1Click(Sender: TObject);
    var
      sheet : variant ;
      i, i2, how_many : integer ;
      excel_name : string ;
      buffer_txt : string ;
      buffer_rowtxt : string ;
      buffer_coltxt : string ;
    begin
      edit1.text := '0' ;
      edit2.text := '0' ;
      edit3.text := '0' ;

      if OpenDialog1.Execute then
        excel_name := OpenDialog1.FileName ;

      Edit4.Text := excel_name;
      {how_many := how_many + 1 ;
      if how_many >=  2 then
        xlapp.workbooks[1].close; }

      if excel_name <> '' then begin
        xlapp.workbooks.open(excel_name);
        sheet := xlapp.workbooks[1].worksheets['Sheet1'];
        RichEdit1.Lines.Clear;
      {if how_many > 1 then
         exit;                  // 동일 창 띄우지 않기 ... }

      for i := 1 to 65535 do
      begin
        edit1.text := inttostr( i ) ;

        buffer_coltxt := sheet.cells[1,i];
        if buffer_coltxt = '' then break ;

        StringGrid1.RowCount := i;

        for i2 := 1 to 65535 do begin
          buffer_txt := sheet.cells[i2,i] ;

          if buffer_txt = '' then break ;

          StringGrid1.ColCount := i2;

          if i2 = 1 Then
            buffer_rowtxt := buffer_txt
          else
            buffer_rowtxt := buffer_rowtxt + ';' + buffer_txt;

          StringGrid1.Cells[i2-1, i-1] := buffer_txt;

        end ;

        RichEdit1.Lines.Add(buffer_rowtxt);
      end;

      edit1.text :=  inttostr( i - 1 ) ;
    end;

    end;

    procedure TForm1.SpeedButton2Click(Sender: TObject);
    var
      j : integer ;
      sheet : variant ;
      max_value : integer ;
    begin
      sheet := xlapp.workbooks[1].worksheets['sample'];

        for j := 3 to strtoint(edit1.text) +  2 do begin
            ProgressBar1.Position := j ;
                sql_string := ' select * from tb_pa02mt ' +
                              ' where part_code = ' + '''' + team_code + '''' +
                              '   and name like ' + '''' + trim(sheet.cells[j,2]) + '''' ;

                  with Choice_team do begin
                    close;
                    sql.clear ;
                    sql.add(sql_String);
                    prepare;
                    open;
                  end ;

                         if  Choice_team.RecordCount <> 0 then begin
                              sql_string := ' update tb_pa02mt ' +
                                            '  set ' +
                                            ' unit_cost = ' + '''' + trim(sheet.cells[j,3]) + '''' +
                                            ' where ' +
                                            '     part_code = ' + '''' + Choice_team.fieldbyname('part_code').asstring  + '''' +
                                            ' and occur_year = ' + '''' + Choice_team.fieldbyname('occur_year').asstring + '''' +
                                            ' and seq_no = ' + '''' + Choice_team.fieldbyname('seq_no').asstring + '''' ;
                                     with Choice_team do begin
                                       close;
                                       sql.clear;
                                       sql.add(sql_string);
                                       prepare;
                                       ExecSQL;
                                     end;
                                    edit3.text := inttostr(strtoint(edit3.text) + 1 ) ;
                              end
                         else
                              begin
                              sql_string := ' select max(to_number(seq_no)) + 1 as max from tb_pa02mt ' +
                                            '  where part_code = ' + '''' + team_code + '''' ;
                                with Choice_team do begin
                                    close;
                                    sql.clear;
                                    sql.add(sql_string);
                                    prepare;
                                    open;
                                end;

                              if Choice_team.fieldbyname('max').asstring = '' then
                                 max_value := 1
                              else
                                 max_value := Choice_team.fieldbyname('max').asinteger ;

                              if trim(sheet.cells[j,2]) = '표준노무자' then
                                 max_value := 9999 ;

                              sql_string := ' insert into tb_pa02mt ' +
                                            ' ( part_code , occur_year , seq_no , unit_cost , name ) ' +
                                            ' values ' +
                                            ' ( ' + '''' + team_code + '''' +  
                                            ',''' + copy(datetostr(now),0,4) + '''' +
                                            ',''' + inttostr(max_value) + '''' +
                                            ',''' + trim(sheet.cells[j,3]) + '''' +
                                            ',''' + trim(sheet.cells[j,2]) + ''')' ;

                                           with Choice_team do begin
                                                close;
                                                sql.clear;
                                                sql.add(sql_String);
                                                prepare;
                                                ExecSQL;
                                           end;
                                         edit2.text := inttostr(strtoint(edit2.text) + 1 ) ;
                              end;



    end;

    end;

    procedure TForm1.SpeedButton3Click(Sender: TObject);
    begin
       XLApp.displayAlerts := False ; // Discard unsaved files ...
       xlapp.quit;
       close ;
    end;


    end.