unit Unit1;测试通过~~interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, Grids, DBGridEh, DB, ADODB, StdCtrls, Excel2000, OleServer, ExcelXP, GridsEh;type TForm1 = class(TForm) ADOConnection1: TADOConnection; ADOQuery1: TADOQuery; DataSource1: TDataSource; DBGridEh1: TDBGridEh; Panel1: TPanel; ComboBox1: TComboBox; Edit1: TEdit; Button1: TButton; Button2: TButton; ExcelApplication1: TExcelApplication; ExcelWorksheet1: TExcelWorksheet; ExcelWorkbook1: TExcelWorkbook; procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementationuses ExportMultiTitle;{$R *.dfm}procedure TForm1.Button2Click(Sender: TObject);var i,j:Integer; dT,dL,dR,dB:Integer; Ra:Variant;begin Try ExcelApplication1.Connect; ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks.Add(EmptyParam,0)); ExcelWorkSheet1.ConnectTo(ExcelWorkBook1.Sheets[1] as _WorkSheet); ExcelApplication1.Caption := '调用 Microsoft Excel'; ExcelApplication1.Visible[0]:=True; ExportMyCell(ADOQuery1.Fields); for i:=0 to r-1 do for j:=0 to c-1 do if MyCells[i,j].Used then begin if (MyCells[i,j].Rect.Top=MyCells[i,j].Rect.Bottom) and (MyCells[i,j].Rect.Left=MyCells[i,j].Rect.Right) then begin dT:=MyCells[i,j].Rect.Top+1; dL:=MyCells[i,j].Rect.Left+1; ExcelWorksheet1.Cells.Item[dt,dl]:=MyCells[i,j].Text; end else begin dT:=MyCells[i,j].Rect.Top+1; dL:=MyCells[i,j].Rect.Left+1; dR:=MyCells[i,j].Rect.Right+1; dB:=MyCells[i,j].Rect.Bottom+1; ExcelWorksheet1.Cells.Item[dt,dl]:=MyCells[i,j].Text; Ra:=ExcelWorksheet1.Range[ExcelWorksheet1.Cells.Item[dt,dl],ExcelWorksheet1.Cells.Item[db,dr]]; Ra.MergeCells:=True; end; end; ExcelWorkSheet1.Columns.AutoFit; Finally ExcelWorkSheet1.Disconnect; ExcelWorkBook1.Disconnect; ExcelApplication1.Disconnect; Ra:=Unassigned; end;end;end.