小弟做了一段程序,将ADOquery中的数据倒出为Excel文件,代码如下:try
    ExcelApplication1.Connect;
    ExcelApplication1.Caption:='test';
    ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks.Add('e:\mod1.xlt',0));
    ExcelWorkSheet1.ConnectTo(ExcelWorkbook1.Sheets[1] as _WorkSheet);    i:=4;
    with PubDataModule.Pub_AdoQuery do
    begin
      First;
      while not eof do
      begin
        ExcelWorksheet1.Cells.Item[i,1]:=FieldByName('f1').AsString;
        ExcelWorksheet1.Cells.Item[i,2]:=FieldByName('f2').AsInteger;
        ExcelWorksheet1.Cells.Item[i,3]:=FieldByName('f3').AsInteger;
        ExcelWorksheet1.Cells.Item[i,4]:=FieldByName('f4').AsString;
        ExcelWorksheet1.Cells.Item[i,5]:=FieldByName('f5').AsString;
        ExcelWorksheet1.Cells.Item[i,6]:=FieldByName('f6').AsString;
        Next;
        Inc(i);
      end;
      Close;
    end;
    ExcelWorksheet1.SaveAs(rFileName);
    Application.ProcessMessages;
    ExcelApplication1.Visible[0]:=true;
  finally
    ExcelApplication1.Disconnect;
  end;  但在执行时,却再现如下问题,数据倒出成功,但Excel屏幕没有正文窗口,只显示上面的工具条,击“预览”可显示出表单内容,处于半死机状态,问题出在什么地方呢,对了,我不是想导出Excel文件后就将Excel关闭,而是由程序切换到Excel中进行后续编辑,这一点请在解答时注意,谢谢!

解决方案 »

  1.   

    http://www.csdn.net/develop/read_article.asp?id=15417
      

  2.   

    我是这样实现的,你试试 
         ExcelApplication1.Connect;
          ExcelApplication1.Visible[0]:=True;
          ExcelApplication1.Workbooks.Add(NULL,0);
          ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
          ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Sheets[1] as _WorkSheet);
          i:=5;
          ExcelWorksheet1.Cells.Font.Size:='10';
          ExcelWorksheet1.Cells.Font.Name:=FontName;
          ExcelWorksheet1.Cells.ITEM[2,1].Font.FontStyle:='Bold';
    ....
    ....
            ExcelWorksheet1.PageSetup.FirstPageNumber := 1;
            ExcelWorksheet1.PageSetup.zoom:=75;
            ExcelApplication1.Disconnect;
      

  3.   

    不用这么麻烦,excel文件也是个jet格式的ado的数据库
    一个sql语句就搞定了
      

  4.   

    befree(似有似无)说的正确,这样实现更方便快捷,不过,可能数据格式控制方面不是太灵活