简体   繁体   English

Delphi MS Word Automation页面设置并保存在Windows 10中

[英]Delphi Ms word Automation Page setup and save in windows 10

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

The code below will create a document with a specified papersize and save it under a specified name: 以下代码将创建具有指定纸张尺寸的文档,并将其保存为指定名称:

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 is an import unit of the MS Word type library (there are other versions - see the Servers subfolder under the OCX folder in your Delphi set-up). Word2000.Pas是MS Word类型库的导入单元(还有其他版本-请参见Delphi设置中OCX文件夹下的Servers子文件夹)。 In it, search for 在其中搜索

wdPaperSize

, which you will find declared as a TOleEnum . ,您将发现该声明为TOleEnum Immediately below that you will find a list of constants that let you specify particular paper sizes. 紧随其后的是一个常数列表,可用于指定特定的纸张尺寸。

{ 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM