首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Delphi Ms word自动化页面设置并保存在windows 10中

Delphi Ms word自动化页面设置并保存在windows 10中
EN

Stack Overflow用户
提问于 2018-07-15 17:28:14
回答 1查看 829关注 0票数 1

如何能够在Delphi自动化中设置诸如legal、A4等页面--在CreateOleObject('Word.Application')之后,并在C驱动器中保存delphi创建的具有特定名称的Word文档。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-15 18:03:54

下面的代码将创建一个具有指定纸张大小的文档,并以指定的名称保存它:

代码语言:javascript
复制
uses ... Word2000;

procedure TForm1.CreateDocWithPaperSize;
var
  MSWord,
  Document,
  PageSetUp: OleVariant;
  AFileName : String;
  iDocument : WordDocument;
begin
  MsWord := CreateOleObject('Word.Application');
  MsWord.Visible := True;

  Document := MSWord.Documents.Add;
  MSWord.Selection.Font.Size := 22;
  MSWord.Selection.Font.Bold := true;
  MSWord.Selection.TypeText(#13#10);

  // the following is to get the WordDocument interface 'inside' the
  //  Document variant, so that we can use code completion on
  // iDocument in the IDE to inspect its properties
  iDocument := IDispatch(Document) as WordDocument;

  PageSetUp := iDocument.PageSetup;
  PageSetUp.PaperSize := wdPaperLegal;
  MSWord.Selection.TypeText('Hello Word.');

  AFileName := 'C:\Temp\Test.Docx';
  Document.SaveAs(FileName := AFileName);
end;

Word2000.Pas是import类型库的一个导入单元(还有其他版本--参见Delphi设置中OCX文件夹下的Servers子文件夹)。在里面,寻找

wdPaperSize

,您会发现它被声明为TOleEnum。在此下面,您将找到一个常量列表,这些常量允许您指定特定的纸张大小。

代码语言:javascript
复制
{ From Word2000.Pas }
// Constants for enum WdPaperSize
type
  WdPaperSize = TOleEnum;
const
  wdPaper10x14 = $00000000;
  wdPaper11x17 = $00000001;
  wdPaperLetter = $00000002;
  wdPaperLetterSmall = $00000003;
  wdPaperLegal = $00000004;
  wdPaperExecutive = $00000005;
  wdPaperA3 = $00000006;
  wdPaperA4 = $00000007;
  wdPaperA4Small = $00000008;
  wdPaperA5 = $00000009;
  wdPaperB4 = $0000000A;
  wdPaperB5 = $0000000B;
  wdPaperCSheet = $0000000C;
  // etc
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51350563

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档