在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
delphi操作word 一、Delphi程序启动Word 二、Delphi程序新建Word文稿 举例:Doc_Handle:=Word_Ole.Documents.Add(Template:='C:/Temlate.dot',NewTemplate:=False); 三、Delphi程序打开Word文稿 FileName: 文档名(包含路径) 举例: 四、Delphi程序保存Word文稿 FileName: 文件名。默认为当前文件夹和文件名。 举例: 设置纸张大小 Wordapplication1.ActiveDocument.PageSetup.PageWidth:=XXX; Wordapplication1.ActiveDocument.PageSetup.PageHeight:=XXX; Wordapplication1.ActiveDocument.PageSetup.LeftMargin := XX; //设置左边距 Wordapplication1.ActiveDocument.PageSetup.rightMargin := XX; 插入页码 var fpage,pagea:olevariant; fpage:=true; pagea:=wdAlignPageNumberCenter; Wordapplication1.activedocument.sections.item(1).Footers.item(1).PageNumbers.Add(pagea,fpage); 设置页面横向打印 s:=Wordapplication1.selection.start; e:=Wordapplication1.selection.start; aa:=wdSectionBreakNextPage; Wordapplication1.ActiveDocument.Range(s,e).InsertBreak(aa); Wordapplication1.Selection.Start:=Wordapplication1.Selection.Start + 1; s:=Wordapplication1.Selection.start; e:=Wordapplication1.ActiveDocument.Content.End_; Wordapplication1.ActiveDocument.Range(S,e).PageSetup.Orientation:=wdOrientLandscape; 设置字体、字号 Wordapplication1.Selection.Font.Size:=18; Wordapplication1.Selection.Font.Name := '黑体'; Wordapplication1.Selection.TypeParagraph; Wordapplication1.Selection.ParagraphFormat.Alignment:= wdAlignParagraphCenter; Wordapplication1.Selection.TypeParagraph; Wordapplication1.Selection.TypeText(dbedit4.text); 插入表格 Wordapplication1.Selection.Font.Size :=10; adoquery2.Active:=false; adoquery2.active:=true; doc:=Wordapplication1.activedocument; counts:=adoquery2.RecordCount; //记录数决定表格的行数 t:=doc.tables.Add(Wordapplication1.selection.range,counts+1,5);//5列 t.cell(1,1).range.text:= '单位'; t.Cell(1,1).Width:=120; t.cell(1,1).range.Paragraphs.Alignment:= wdAlignParagraphCenter; t.cell(1,2).range.text:= '姓名'; ... ... //依次写入其他字段的表头 for i:=2 to counts+1 do begin t.cell(i,1).range.text:=adoquery2.field byname('dw').asstring; t.Cell(i,1).Width:=120; t.cell(i,1).range.Paragraphs.Alignment:= wdAlignParagraphCenter; t.cell(i,2).range.text:=adoquery2.field byname('xm').asstring; ... ... Adoquery2.next; End;
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论