Delphi - EXCEL 작업

6712 단어 Delphi
이 가능하다, ~할 수 있다,...
EXCEL 내보내기
var

  h,k:integer;

  Excelid: OleVariant;

  s: string;

begin



  try

    Excelid := CreateOLEObject('Excel.Application');

  except

    Application.MessageBox('Excel    !', '    ', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);

    Exit;

  end;

  try

   Tblrs.Close;

   Tblrs.SQL.Clear;

   Tblrs.SQL.Add('select * from rszl');

   Tblrs.Open;

   k:=Tblrs.RecordCount;





   Excelid.Visible := True;

   Excelid.WorkBooks.Add;



   Excelid.worksheets[1].range['A1:C1'].Merge(True);    //A1 C1        

   Excelid.WorkSheets[1].Cells[1,1].Value :='   ' ;  // A1 C1          TITLE



   Excelid.WorkSheets[1].Cells[2,1].Value :='  ' ;

   Excelid.WorkSheets[1].Cells[2,2].Value :='  ' ;

   Excelid.WorkSheets[1].Cells[2,3].Value :='  ' ;



   // A1 C1               

   Excelid.worksheets[1].Range['A1:C1'].Font.Name := '  ';

   Excelid.worksheets[1].Range['A1:C1'].Font.Size := 14;

   Excelid.worksheets[1].Range['A1:C1'].Font.Bold:=true;





    //    

    h:=3;

    Tblrs.First;

    while not Tblrs.Eof do

    begin

      Excelid.WorkSheets[1].Cells[h,1].Value := Tblrs.FieldByName('ygbh').AsString;

      Excelid.WorkSheets[1].Cells[h,2].Value := Tblrs.FieldByName('mc').AsString;

      Excelid.WorkSheets[1].Cells[h,3].Value := Tblrs.FieldByName('sex').AsString;

      Inc(h);

      Tblrs.Next;

    end;



    except

        Application.MessageBox('      !            !', '    ', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);

    end;



    MessageBox(GetActiveWindow(), 'EXCEL      !', '    ', MB_OK +MB_ICONWARNING);

좋은 웹페이지 즐겨찾기