以前做过一个,是发到Word里再打,有段例程,你看看。
procedure Tdhfy_win.DbGrid_to_Word(DbGrid:TDbGrid;
Rowcount, ColCount:integer;
Title:string);
var
Lang: string;
MSWord: Variant;
c,r,j:integer;
begin
try
MsWord := CreateOleObject('Word.Basic');
except
ShowMessage('不能启动Microsoft Word!');
Exit;
end;
try
{ Return Application Info. This call is the same for English and
French Microsoft Word. }
Lang := MsWord.AppInfo(Integer(16));
except
try
{ for German Microsoft Word the procedure name is translated }
Lang := MsWord.AnwInfo(Integer(16));
except
{ if this proceduredo
es not exist there is a different translation of
Microsoft Word }
ShowMessage('Microsoft Word version is not German, French or English.');
Exit;
end;
end;
with DbGriddo
begin
try
r:=rowcount+1;
c:=ColCount;
{ if (Lang = 'English (US)') or (Lang = 'English (UK)') or (Lang = '简体中文(中国)') then
begin
}
MsWord.AppShow;
MSWord.FileNew;
MsWord.MsgBox('正在创建报表...请稍候','',-1);
msword.screenupdating(1);
msword.startofdocument;
//title
try
DataSource.DataSet.First;
msword.insert('桂林电子工业学院用户电话号码表'+#13);
MSWord.LineUp(1, 1);
msword.centerpara;
msword.endofdocument;
msword.insert('制表日期:'+datetostr(date)+#13);
msword.leftpara;
msword.insert(Title+#13);
msword.leftpara;
msword.endofdocument;
msword.tableinserttable(0, c, r, 0, 0, 16, 166);
for j:=0 to 4do
begin
msword.insert(Fields[j].DisplayLabel);
msword.nextcell;
end;
While not DataSource.DataSet.Eofdo
begin
for j:=0 to 4do
begin
msword.insert(Fields[j].AsString);
msword.nextcell;
end;
DataSource.DataSet.Next;
end;
msword.tabledeleterow;
msword.endofdocument;
msword.leftpara;
msword.insert(#13#13);
finally
end;
// msword.startofdocument;
// msword.tableselectrow;
// msword.tableheadings(1);
// msword.centerpara;
msword.screenrefresh;
msword.screenupdating(1);
{ MSWord.Insert(S);
MSWord.LineUp(L, 1);
MSWord.TextToTable(ConvertFrom := 2, NumColumns := 3);
}
MsWord.MsgBox('创建报表完毕!','',-1);
{end;
}
finally
// Close;
end;
end;
end;