组建时超烂,
用OLE对象吧,控制起来感觉很爽的。

解决方案 »

  1.   

    哎?我也碰到这个问题,你和别的网友知道如何在delphi中用excel实现报表打印?呢都告诉我呢?
      

  2.   

    到http:/www.cnborn.com/delphi/excel.zip取控件
    使用方法:把控件取下后
    1.安装该控件至你Delphi
    2.把控件拖到你的窗体上取名Excel1
    3.把该控件的DBgrid属性指向你要导出数据的DBgrid。
    4.调用Excel1.SetDataToExcel方法。 
    试试吧,祝你好运。
      

  3.   

    var
      XLApp: Variant;
      Sheet: Variant;
      i, j: Integer;
      filename: Tfilename;
    const
      xlWBATWorksheet = -4167;
      wdDoNotSaveChanges = 0;
    begin
      if Savedialog1.Execute then
        filename := Savedialog1.FileName
      else
        abort;
      XLApp := CreateOleObject('Excel.Application');
      XLApp.Visible := True;
      XLApp.Workbooks.Add[XLWBatWorksheet];
      XLApp.Workbooks[1].Worksheets[1].Name := 'sheet1';
      Sheet := XLApp.Workbooks[1].Worksheets['sheet1']; 
      for i := 1 to stringgrid18.RowCount do
          for j := 1 to stringgrid18.ColCount do
            Sheet.Cells[i, j] := stringgrid18.Cells[j - 1, i - 1];
      end
      else
      begin
        for i := 1 to stringgrid14.RowCount do
          for j := 1 to stringgrid14.ColCount do
            Sheet.Cells[i, j] := stringgrid14.Cells[j - 1, i - 1];
      end;
      if not VarIsEmpty(XLApp) then begin
        XLApp.DisplayAlerts := False; // Discard unsaved files....
        xlApp.ActiveWorkBook.SaveAs(filename);
     //    XLApp.Quit;
      end;end;
      

  4.   

    谢谢1974同志,及众位的智慧,我想要向一book里添加一个sheet怎么办?
      

  5.   

    upup
    数据库与Excel文件的双向互导我都会.
      

  6.   


    添加新工作表:
    var Temp_Worksheet: _WorkSheet;
    begin
    Temp_Worksheet:=ExcelWorkbook1.
    WorkSheets.Add(EmptyParam,EmptyParam,EmptyParam,EmptyParam,0) as _WorkSheet;
    ExcelWorkSheet1.ConnectTo(Temp_WorkSheet);
    End;
      

  7.   

    ExcelApplication1.Connect;
    ExcelApplication1.Visible[0]:=True;ExcelApplication1.Workbooks.Add(NULL,0);
    ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
    ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Sheets[1] as _WorkSheet);for idx:=1 to 30 do begin
    ExcelWorksheet1.Cells.Item[idx,1]:='Hello '+IntToStr(idx);
    ExcelWorksheet1.Cells.Item[idx,2]:= idx; 
    end;ExcelWorksheet1.Cells.Item[31,2]:='=SUM(B1:B30)'; 
    ShowMessage('Total is '+ExcelWorksheet1.Cells.Item[31,2]); ExcelApplication1.Disconnect; 
    ExcelApplication1.Quit;