请问关于如何将query里的查询结果导为EXECL文件,请详细说明,不好意思我比较笨

解决方案 »

  1.   

    http://expert.csdn.net/Expert/topic/1467/1467372.xml?temp=.5300867
      

  2.   

    uses ComObj;
    .
    .
    .
    var
       XlApp,Sheet:Variant;  
    try
          XLApp:=CreateOleObject('Excel.Application');
          XLApp.Visible:=True;
          XLApp.Workbooks.Add(emptyParam);
          XLApp.Workbooks[1].WorkSheets[1].Name:='sheet1';
        Except
          application.MessageBox('导出到Excel失败,请检查Excel是否正确安装!','错误',0);
          Exit;
        end;    //向电子表格添入数据
        Sheet:=XLApp.WorkBooks[1].WorkSheets['sheet1'];
        Row:=2;
        Sheet.Cells[1,1]:='代码';
        Sheet.Cells[1,2]:='名称';
        query1.first;
        while not query1.Eof do
        begin
            Sheet.Cells[Row,1]:=query1.fieldbyname('ccode').asstring;
            Sheet.Cells[Row,2]:=query1.fieldbyname('cName').asstring;
            query1.next;  
        end;