我用Table控件查询出来数据想把这些数据导到Excel.!

解决方案 »

  1.   

    我只会直接写入:
    procedure TForm1.aa;
    var
      i,j:integer;
      excel_sheet:variant;
    begin
      try
        excel_sheet:=CreateOleObject('Excel.Application');
      except
        showmessage('无法启动 MS Excel');
        exit;
      end;
      With table1 do
      begin
        first;
        Excel_sheet.WorkBooks.Add;
        for i:=0 to RecordCount-1 do 
        begin
          for j:=0 to FieldCount-1 do excel_sheet.cells.item[i+1,j+1]:=Fields[j].AsString;
          next;
        end;
        excel_sheet.ActiveWorkBook.saveas(文件路径);
        excel_sheet.application.quit;               
      end;
    end;
      

  2.   

    从stringGrid中导入的方法:
    procedure Tearningstool.Button1Click(Sender: TObject);
    var xlapp,xlbook,xlsheet:variant;
    i,j:integer;
    begin
    self.Cursor:=crHourGlass;
    xlapp:=createoleobject('excel.application');
    xlbook:=xlapp.workbooks.add;
    xlsheet:=xlbook.worksheets[1];
    xlsheet.cells[1,3]:='标题';
    xlsheet.cells[2,1]:='name1';
    xlsheet.cells[2,2]:='name2';
    ...
    i:=3;
    for j:=1 to self.StringGrid2.rowcount-1 do
    begin
        xlsheet.cells[i,1]:=''''+trim(self.StringGrid2.Cells[0,j]);
        xlsheet.cells[i,2]:=trim(self.StringGrid2.Cells[1,j]);
        xlsheet.cells[i,3]:=trim(self.StringGrid2.Cells[2,j]);
        xlsheet.cells[i,4]:='';
        xlsheet.cells[i,5]:=''''+trim(self.StringGrid2.Cells[4,j]);
        xlsheet.cells[i,6]:=trim(self.StringGrid2.Cells[5,j]);
        xlsheet.cells[i,7]:=trim(self.StringGrid2.Cells[6,j]);
        i:=i+1;
    end;
    self.Cursor:=crDefault;
    xlapp.visible:=true;
    end;
      

  3.   

    TO  flp(会说话的哑巴) :
    如果不是Table,而是查询的adoquery或者adostoredproc,会不会有限制?
    我这边只能出现255条记录