楚
楚辞
Unregistered / Unconfirmed
GUEST, unregistred user!
Button1: TButton; Button2: TButton; Button3: TButton; Memo1: TMemo; WordApplication1: TWordApplication; WordDocument1: TWordDocument; WordFont1: TWordFont;procedure TForm1.FormCreate(Sender: TObject);begin button1.Caption:='插入到word'; button2.Caption :='打印'; button3.Caption :='退出'; button1.Enabled :=false; button2.Enabled :=false;end;procedure TForm1.Button1Click(Sender: TObject);vartemplate,newtemplate,itemindexlevariant; procedure setfont;begin wordfont1.ConnectTo(worddocument1.Sentences.Last.Font ); wordfont1.Bold :=1; wordfont1.Italic :=1; wordfont1.Shadow :=1; WordFont1.Size := 12;end; begin try template:=emptyparam; newtemplate:=true; itemindex:=1; try Wordapplication1.Connect; except MessageDlg('无法连接,也许没有安装Word', mtError, [mbOk], 0); abort; end; Wordapplication1.Visible := False;WordApplication1.Caption := 'Delphi Word'; //file://建立一个新文档Template := EmptyParam;NewTemplate := False;//报错地方 WordApplication1.Documents.Add(template, newtemplate);//[Error] Unit1.pas(74): Not enough actual parameters//file://建立WordDocument连接WordDocument1.ConnectTo(WordApplication1.Documents.Item(ItemIndex));//file://因为Word进行拼写检查需要很多时间,所以首先关闭检查WordApplication1.Options.CheckSpellingAsYouType:= False;WordApplication1.Options.CheckGrammarAsYouType := False;//file://将Memo1的内容拷贝到Word中 SetFont;WordDocument1.Range.InsertAfter('Memo1的文本: '+#13+Memo1.Text+#13);Button2.Enabled :=True;Button3.Enabled :=True;Button1.Enabled :=False;excepton E:Exception dobeginShowMessage(E.Message);WordApplication1.Disconnect;end; end;procedure TForm1.Button2Click(Sender: TObject);beginWordDocument1.PrintOut;end;procedure TForm1.Button3Click(Sender: TObject); varSaveChanges,OriginalFormat,RouteDocument,SavePath: OleVariant;beginSaveChanges := WdDoNotSaveChanges;OriginalFormat := UnAssigned;RouteDocument := UnAssigned;trySavePath:='c:/samp.doc';//这个地方我没WordDocument1.SaveAs(SavePath);WordDocument1.Close;WordDocument1.Disconnect;WordApplication1.Quit(SaveChanges, OriginalFormat, RouteDocument);WordApplication1.Disconnect;close;excepton E: Exception dobeginShowmessage(E.Message);WordApplication1.Disconnect;end;end;end;