procedure TForm1.Button1Click(Sender: TObject);
var FTable: Table;
VarWord: Variant;// 创建 WORD时所用
FRowNum, FColNum: Integer;
a
levariant;
begin
a:=OpenDialog2.FileName;//已经存在的文档
FRowNum:=5;
FColNum:=8;
wordapplication1.Documents.Open(a,
EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam);
VarWord:=Wordapplication1.activedocument;
Wordapplication1.ActiveDocument.PageSetup.PageWidth:=600;
//Wordapplication1.ActiveDocument.PageSetup.PageHeight:=23;
Wordapplication1.ActiveDocument.PageSetup.topMargin:=55;
Wordapplication1.ActiveDocument.PageSetup.LeftMargin:=45;
Wordapplication1.ActiveDocument.PageSetup.rightMargin:=45;
Wordapplication1.ActiveDocument.PageSetup.bottomMargin:=45;
Wordapplication1.Selection.TypeText(' '+trim(memo1.text));
Wordapplication1.visible := true;
FTable:=WORDAPPLICATION1.Selection.Tables.Add(WORDAPPLICATION1.Selection.Range,FRowNum,FColNum,EmptyParam,EmptyParam);
FTable.Range.Font.Size:=12;
FTable.PreferredWidthType:=wdPreferredWidthPercent;
FTable.PreferredWidth:=100;
with FTable do
begin
//-----如果不是,设置为无边框-------
TopPadding:=WORDAPPLICATION1.CentimetersToPoints(0);
BottomPadding:=WORDAPPLICATION1.CentimetersToPoints(0);
LeftPadding:=WORDAPPLICATION1.CentimetersToPoints(0);
RightPadding:=WORDAPPLICATION1.CentimetersToPoints(0);
Spacing:=0;
AllowPageBreaks:=True;
AllowAutoFit:=False;
Cell(1,1).Range.Text:='名称';
Cell(1,1).Width:=50;//20能放下一个字
Cell(1,2).Range.Text:='规格型号';
Cell(1,3).Range.Text:='测量范围';
Cell(1,4).Range.Text:='不确定度/准确度';
Cell(1,5).Range.Text:='证书编号';
Cell(2,1).Range.Text:='名称';
Cell(2,1).Width:=50;
Cell(2,2).Range.Text:=memo2.text;
Cell(2,3).Range.Text:='测量范围';
Cell(2,4).Range.Text:='不确定度/准确度';
Cell(2,5).Range.Text:='证书编号';
Cell(3,1).Width:=50;
Cell(4,1).Width:=50;
Cell(5,1).Width:=50;
//------设置表格对齐方式---------------
FTable.Columns.PreferredWidthType:=wdPreferredWidthAuto;
FTable.Range.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
Range.Cells.VerticalAlignment:=wdCellAlignVerticalCenter;
Rows.Alignment:=wdAlignRowCenter;
Wordapplication1.Selection.TypeText(' '+trim(memo3.text));
worddocument1.Disconnect;
wordapplication1.Disconnect;
end;
end;