用EXCEL吧,这样方便点。
因时间问题,可能乱了点。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, Buttons;
type
TForm1 = class(TForm)
ADOQuery1: TADOQuery;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
procedure printf;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure Tform1.printf;
var
iCount, jCount,i: Integer;
XLApp: Variant;
Sheet: Variant;
begin
Screen.Cursor := crHourGlass;
if not VarIsEmpty(XLApp) then
begin
XLApp.DisplayAlerts := False;
XLApp.Quit;
VarClear(XLApp);
end;
try
XLApp := CreateOleObject('Excel.Application');
except
Screen.Cursor := crDefault;
Exit;
end;
xLApp.WorkBooks.Add[XLWBatWorksheet];
XLApp.WorkBooks[1].WorkSheets[1].Name := '';
Sheet := XLApp.Workbooks[1].WorkSheets[''];
if not Target.DataSource.DataSet.Active then
begin
Screen.Cursor := crDefault;
Exit;
end;
with adoquery1do
begin
close;
sql.Clear ;
sql.Append('select D1.A,D1.B,D1.C,D1.D,D2.h,....from D1,D2');
open;
if recordcount>0 then
begin
first;
for iCount := 0 to Fields.Count-1do
Sheet.cells[1, iCount + 1] :=Fields.FieldName;
jCount := 1;
while not Eofdo
begin
for iCount := 0 to Fields.Count-1do
Sheet.cells[jCount+1, iCount + 1] := fieldbyname(Fields.FieldName).AsString ;
Inc(jCount);
Next;
end;
jcount:=jcount+5;
//空五行
close;
sql.Clear ;
sql.Append('select D1.A,D1.B,D1.C,D1.D,D2.u,....from D1,D2');
open;
if recordcount>0 then
begin
first;
for iCount := 0 to Fields.Count-1do
Sheet.cells[jcount, iCount + 1] :=Fields.FieldName;
while not Eofdo
begin
for iCount := 0 to Fields.Count-1do
Sheet.cells[jCount+1, iCount + 1] := fieldbyname(Fields.FieldName).AsString ;
Inc(jCount);
Next;
end;
end;
end;
end;
Sheet.Columns.EntireColumn.AutoFit ;
Sheet.Range['A1','L2000'].HorizontalAlignment:= xlCenter ;
XlApp.Visible := True;
Screen.Cursor := crDefault;
end;