procedure TForm1.MakeWordFile(const UserID : string);
var
Bookmark: TBookmark;
RangeW: Word97.Range;
v1: Variant;
ov1: OleVariant;
Row1: Word97.Row;
sQANDD : string;//问题与难点
sMemo : string;//备注
sSender:string;//提交人
sPOSTDATE :string;//提交日期
fName : OleVariant;
sUserName : string;//
sfName : string;
i , j : integer;
begin
// insert title
WordDocument1.Range.Text := '文档标题';
//格式必须在最后设置
WordDocument1.PageSetup.Orientation := wdOrientLandscape;//横向
WordDocument1.Range.Font.Size := 14;
WordDocument1.Range.Font.Bold := 0;
WordDocument1.Tables.Add (WordDocument1.Words.Last,Table1.RecordCount+1,5,EmptyParam,EmptyParam);
WordDocument1.Tables.Item(1).Cell(1,1).Range.Text := '格1';
WordDocument1.Tables.Item(1).Cell(1,2).Range.Text := '格2';
WordDocument1.Tables.Item(1).Cell(1,3).Range.Text := '格3';
WordDocument1.Tables.Item(1).Cell(1,4).Range.Text := '格4';
WordDocument1.Paragraphs.Last.Range.Text := ' ';//必须填这句,否则两个表格就粘合在一起了
WordDocument1.Tables.Item(1).Cell(1,5).Range.Text := '格5';
Table1.First;
for i := 1 to Table1.RecordCount do
begin
WordDocument1.Tables.Item(1).Cell(1+i,1).Range.Text := Table1.FieldByName('ITEM').AsString;
WordDocument1.Tables.Item(1).Cell(1+i,2).Range.Text := Table1.FieldByName('Description').AsString;
WordDocument1.Tables.Item(1).Cell(1+i,3).Range.Text := Table1.FieldByName('Result').AsString;
WordDocument1.Tables.Item(1).Cell(1+i,4).Range.Text := Table1.FieldByName('MEASURE').AsString;
WordDocument1.Tables.Item(1).Cell(1+i,5).Range.Text := Table1.FieldByName('POSTDATE').AsString;
Table1.Next;
end;
WordDocument1.Tables.Add(WordDocument1.Words.Last,Table2.RecordCount +1,2,EmptyParam,EmptyParam);
WordDocument1.Tables.Item(2).Cell(1,1).Range.Text := '其它';
WordDocument1.Tables.Item(2).Cell(1,2).Range.Text := '备注';
Table2.First;
for i := 1 to Table2.RecordCount do
begin
WordDocument1.Tables.Item(2).Cell(1+i,1).Range.Text := Table2.FieldByName ('QANDD').AsString;
WordDocument1.Tables.Item(2).Cell(1+i,2).Range.Text := Table2.FieldByName ('MEMO').AsString;
Table2.Next;
end;
//***********************设置标题文字格式*********************************
WordDocument1.Paragraphs.Item(1).Range.Select;
WordDocument1.Paragraphs.Item(1).Range.Font.Size := 30;
WordDocument1.Application.Selection.ParagraphFormat.Alignment := wdAlignParagraphCenter;
//****************************保存文件****************************************
sUserName := lstUser.Items[lstUser.ItemIndex];
ZipStr(sUserName, #10);
sfName := Trim(edFileDir.Text)+'/' + sUserName + ' ' + Trim(edDate.Text)+'.doc';
fName := sfname;
//保存
WordDocument1.SaveAs2000(fname);
WordDocument1.Close;//关闭
end;
var
Bookmark: TBookmark;
RangeW: Word97.Range;
v1: Variant;
ov1: OleVariant;
Row1: Word97.Row;
sQANDD : string;//问题与难点
sMemo : string;//备注
sSender:string;//提交人
sPOSTDATE :string;//提交日期
fName : OleVariant;
sUserName : string;//
sfName : string;
i , j : integer;
begin
// insert title
WordDocument1.Range.Text := '文档标题';
//格式必须在最后设置
WordDocument1.PageSetup.Orientation := wdOrientLandscape;//横向
WordDocument1.Range.Font.Size := 14;
WordDocument1.Range.Font.Bold := 0;
WordDocument1.Tables.Add (WordDocument1.Words.Last,Table1.RecordCount+1,5,EmptyParam,EmptyParam);
WordDocument1.Tables.Item(1).Cell(1,1).Range.Text := '格1';
WordDocument1.Tables.Item(1).Cell(1,2).Range.Text := '格2';
WordDocument1.Tables.Item(1).Cell(1,3).Range.Text := '格3';
WordDocument1.Tables.Item(1).Cell(1,4).Range.Text := '格4';
WordDocument1.Paragraphs.Last.Range.Text := ' ';//必须填这句,否则两个表格就粘合在一起了
WordDocument1.Tables.Item(1).Cell(1,5).Range.Text := '格5';
Table1.First;
for i := 1 to Table1.RecordCount do
begin
WordDocument1.Tables.Item(1).Cell(1+i,1).Range.Text := Table1.FieldByName('ITEM').AsString;
WordDocument1.Tables.Item(1).Cell(1+i,2).Range.Text := Table1.FieldByName('Description').AsString;
WordDocument1.Tables.Item(1).Cell(1+i,3).Range.Text := Table1.FieldByName('Result').AsString;
WordDocument1.Tables.Item(1).Cell(1+i,4).Range.Text := Table1.FieldByName('MEASURE').AsString;
WordDocument1.Tables.Item(1).Cell(1+i,5).Range.Text := Table1.FieldByName('POSTDATE').AsString;
Table1.Next;
end;
WordDocument1.Tables.Add(WordDocument1.Words.Last,Table2.RecordCount +1,2,EmptyParam,EmptyParam);
WordDocument1.Tables.Item(2).Cell(1,1).Range.Text := '其它';
WordDocument1.Tables.Item(2).Cell(1,2).Range.Text := '备注';
Table2.First;
for i := 1 to Table2.RecordCount do
begin
WordDocument1.Tables.Item(2).Cell(1+i,1).Range.Text := Table2.FieldByName ('QANDD').AsString;
WordDocument1.Tables.Item(2).Cell(1+i,2).Range.Text := Table2.FieldByName ('MEMO').AsString;
Table2.Next;
end;
//***********************设置标题文字格式*********************************
WordDocument1.Paragraphs.Item(1).Range.Select;
WordDocument1.Paragraphs.Item(1).Range.Font.Size := 30;
WordDocument1.Application.Selection.ParagraphFormat.Alignment := wdAlignParagraphCenter;
//****************************保存文件****************************************
sUserName := lstUser.Items[lstUser.ItemIndex];
ZipStr(sUserName, #10);
sfName := Trim(edFileDir.Text)+'/' + sUserName + ' ' + Trim(edDate.Text)+'.doc';
fName := sfname;
//保存
WordDocument1.SaveAs2000(fname);
WordDocument1.Close;//关闭
end;