我喜欢用EXECEL输出,这是我文档管理的报表代码,DELPHI可以直接调用EXECEL对象
WORD行的,不过我这里没资料有EXECLE的,因为EXECEL就是做报表的嘛
记得USE里用到comobj, 在说下两个变量v,sheet:variant;是窗体类里申明了的
procedure Tfmsearch.expbtClick(Sender: TObject);
var
range:variant;
i,j:integer;
begin
if dm1.qrinfo.RecordCount=0 then
begin
MessageBox(handle,Pchar('没有记录可输出'),'输出提示',0+48);
exit;
end;
v:=createoleobject('excel.application');
v.workbooks.add;
v.workbooks[1].worksheets[1].name:='文章清单';
sheet:=V.workbooks[1].worksheets[1];
v.visible:=true;
range:=sheet.range['A1:E1'];
range.merge;
range.borders.linestyle:=0;
range.formular1c1:='文 章 清 单';
range.horizontalalignment:=3;
range.verticalalignment:=2;
range.characters.font.name:='宋体';
range.characters.font.fontstyle:='加粗';
range.characters.font.size:=15;
range.characters.font.colorindex:=2;
range.interior.color:=$00bbbbbb;
//
range:=sheet.range['A2:E2'];
range.merge;
range.borders.linestyle:=0;
range.formular1c1:='输出用户:'+curuser+
' 输出日期:'+formatdatetime('yyyy"年"m"月"d"日"',Date);
range.horizontalalignment:=3;
range.verticalalignment:=2;
range.characters.font.name:='宋体';
range.characters.font.size:=10;
range.characters.font.colorindex:=2;
range.interior.color:=$00Bbbbbb;
//
sheet.cells[3,1]:='编号';
sheet.cells[3,2]:='文章名称';
sheet.cells[3,3]:='录入日期';
sheet.cells[3,4]:='录入用户';
sheet.cells[3,5]:='保密性';
//
for i:=1 to 5 do
begin
sheet.cells[3,i].borders.linestyle:=1;
sheet.cells[3,i].horizontalalignment:=3;
end;
dm1.qrinfo.First;
j:=3;
while not dm1.qrinfo.Eof do
begin
inc(j);
sheet.cells[j,1]:=dm1.qrinfotextid.AsString;
sheet.cells[j,2]:=dm1.qrinfotextname.AsString;
sheet.cells[j,3]:=dm1.qrinforecdate.AsDateTime;
sheet.cells[j,4]:=dm1.qrinforecuser.AsString;
sheet.cells[j,5]:=dm1.qrinfotextsec.AsString;
dm1.qrinfo.next;
if dm1.qrinfo.Eof then break;
end;
range:=sheet.range['A4:'+'E'+inttostr(j)];
range.borders.linestyle:=1;
//
sheet.cells.entirecolumn.autofit;
sheet.pagesetup.printtitlerows:='$1:$3';
sheet.pagesetup.rightheader:='execel报表';
sheet.pagesetup.leftheader:='共'+inttostr(dm1.qrinfo.RecordCount)+'篇文章';
sheet.pagesetup.centerfooter:='共&N页'+'/第&P页';
sheet.pagesetup.centerhorizontally:=true;
sheet.pagesetup.orientation:=1;
sheet.pagesetup.draft:=false;
sheet.pagesetup.blackandwhite:=true;
sheet.pagesetup.zoom:=100;
v.displayalerts:=false;
sheet.printpreview;
end;