一般都应装,不装不正常。
例:
procedure Tform1.NewDocument;
var
Template, NewTemplate, ItemIndex, DocumentType, Visible: OleVariant;
begin
Template := EmptyParam;
NewTemplate := false; //True;
DocumentType := $00000000; // $00000001;
Visible := true;
ItemIndex := 1;
WordApp.Documents.Add(Template, NewTemplate, DocumentType, Visible);
Doc.ConnectTo(WordApp.Documents.Item(ItemIndex));
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Pars: Paragraphs;
ARange: Range;
n:Integer;
DefaultTableBehavior, AutoFitBehavior, count, ex_Var: OleVariant;
begin
try
WordApp.Connect;
except
MessageDlg('Word可能没有安装!', mtError, [mbOk], 0);
Abort;
end;
WordApp.Connect;
WordApp.Visible := True;
WordApp.Caption := 'Delphi automation';
NewDocument;
Pars := Doc.Paragraphs;
n := pars.Get_Count;
Pars.Add(EmptyParam);
ARange := Pars.Item
.Range;
ARange.Text:='严禁复制';
Pars.Add(EmptyParam);
n:=n+1;
ARange := Pars.Item
.Range;
ARange.Text:='用后返回';
ARange.Font.Name := '黑体';
ARange.Font.size := 12;
ARange.Font.Bold := integer(True);
DefaultTableBehavior := wdWord9TableBehavior;
AutoFitBehavior := wdAutoFitContent;
Pars.Add(EmptyParam);
ARange := Pars.Item(pars.Get_Count).Range;
doc.Tables.Add(aRange, 1, 1, DefaultTableBehavior, AutoFitBehavior);
ARange.Font.size := 16;
Doc.Tables.Item(1).Cell(1, 1).Range.InsertAfter('绝 密');
ARange.Font.size := 16;
ARange.ParagraphFormat.Alignment := wdAlignParagraphCenter;
Doc.Tables.Item(1).Rows.LeftIndent := 11 * 28.35;
n := pars.Get_Count;
Pars.Add(EmptyParam);
ARange := Pars.Item
.Range;
ARange.Text:='严禁复制';
Pars.Add(EmptyParam);
n:=n+1;
ARange := Pars.Item
.Range;
ARange.Text:='用后返回';
ARange.ParagraphFormat.LineSpacingRule := wdLineSpaceExactly;
ARange.ParagraphFormat.LineSpacing :=20;//设置行间距
ARange.ParagraphFormat.LineSpacingRule := wdLineSpaceSingle;
end;