procedure TF_cusorder.Button1Click(Sender: TObject);
var
  myexcel:variant;
  i,j:integer;
  workbook:olevariant;
  worksheet:olevariant;
begin
  inherited;
  try
    Screen.Cursor:=crHourGlass;
    myexcel:=createoleobject('excel.application');
    myexcel.application.workbooks.add;
    myexcel.caption:='导入EXCEL';
    myexcel.visible:=true;
    workbook:=myexcel.Application.workbooks[1];
    worksheet:=workbook.worksheets[1];
  except
    messagedlg('无法启动EXCEL,请确认是否安装',mtinformation,[mbyes],0);
    exit;
  end;
   
    for j := 0 to dindandqry.FieldCount - 1 do
    begin
      i:=1;
      dindandqry.First;
      worksheet.cells[1,j+1]:=DBGrid1.Columns[j].Title.Caption;
      while not dindandqry.Eof do
      begin
       inc(i);
       worksheet.cells[i,j+1]:=dindandqry.fields[j].asstring;
       dindandqry.Next;
      end;
    end;
    Screen.Cursor:=crDefault;

转载于:https://www.cnblogs.com/lzming/archive/2008/12/11/1353135.html

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐