Word := CreateOLEobject('Word.Application')
Word.Visible := False
firstdoc:=Word.Documents.Add
GColCount :=DBSGdataset.FieldCount;
GRowCount :=DBSGDataSet.RecordCount
progressbar.MaxValue:=Growcount;
//设置第一段的内容,字体,字体粗细,字体的颜色及大小
firstdoc.Paragraphs.Item(1).Range.Text:=title;
firstdoc.Paragraphs.Item(1).Range.Bold :=True;
firstdoc.Paragraphs.Item(1).Range.Font.Size :=30;
firstdoc.Paragraphs.Item(1).Range.Font.Name:='宋体';
firstdoc.Paragraphs.Item(1).Range.Font.ColorIndex:=0;//Red
//增加一段
firstdoc.Paragraphs.Add;
//通过下面的赋值语句,使得Variant变量seconddoc等同于firstdoc.Paragraphs.Item(2).Range对象
seconddoc:=firstdoc.Paragraphs.Item(2).Range;
//
seconddoc.Font.Size :=12;
seconddoc.PageSetup.Orientation := 1
seconddoc.Tables.Add( seconddoc,GRowCount+1,GColCount);
seconddoc.InsertAfter('报表时间 ' +Datetimetostr(Now)+' 报表人 '+who);
for y := 1 to GColCount do
seconddoc.Tables.Item(1).Cell(1,y).Range.
InsertAfter(DBSGdataset.Fields[y-1].DisplayLabel)
//insertafter(adataset.Cells[y-1,0]);
progressbar.Progress:=progressbar.Progress+1;
with DBSGdataset do
begin
first;
for x:=1 to Growcount do
begin
for y:=1 to GcolCount do
begin
seconddoc.Tables.Item(1).Cell(x+1,y).Range.
//InsertAfter(Adataset.Cells[y-1,x]);
InsertAfter(vartostr(fields[y-1].Value))
end;
next;
progressbar.Progress:=progressbar.Progress+1;
end;
end;
seconddoc.Tables.Item(1).UpdateAutoFormat
Word.Visible := true
finally
screen.Cursor:=crdefault;
BackPanel.Free;
//Progressbar.Free;
end
这是将DATASET在WORD中生成报表的程序段