加为好友
发送私信
在线聊天
sjg30317
等级:
可用分等级:长工
总技术分:47
总技术分排名:134355
发表于:2008-11-07 13:33:44 16 楼 得分:37
//启动Word try wordapplication1.connect; except messagedlg('word may not be installed', mterror, [mbok], 0); abort; end; //打开文档 procedure TForm1.OpenWord(Sfile: string); var FileName, ConfirmConversions, ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, Format, Encoding, Visible, OpenAndRepair, DocumentDirection, NoEncodingDialog: OleVariant; ItemIndex: OleVariant; begin FileName := sfile; ConfirmConversions := False; ReadOnly := False; AddToRecentFiles := False; PasswordDocument := ''; PasswordTemplate := ''; Revert := True; WritePasswordDocument := ''; WritePasswordTemplate := ''; Format := wdOpenFormatDocument; //打开文件 WordApplication1.Documents.Open(FileName, ConfirmConversions, ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, Format, Encoding, Visible, OpenAndRepair, DocumentDirection, NoEncodingDialog); ItemIndex := 1; WordDocument1.ConnectTo(WordApplication1.Documents.Item(ItemIndex)); WordApplication1.Options.CheckSpellingAsYouType := False; WordApplication1.Options.CheckGrammarAsYouType := False; WordApplication1.Connect; WordApplication1.Visible := True; WordApplication1.Disconnect; end; //设置页眉页脚 procedure TForm1.Button5Click(Sender: TObject); var mmm, nnn, aaa: OleVariant; begin mmm := wdLine; nnn := 1; aaa := wdFieldPage; worddocument1.ActiveWindow.ActivePane.View.SeekView := wdSeekCurrentPageHeader; worddocument1.activewindow.Selection.Move(mmm, nnn); worddocument1.activewindow.Selection.ParagraphFormat.Alignment := wdAlignParagraphCenter; worddocument1.activewindow.Selection.InsertAfter('第'); mmm := wdCharacter; worddocument1.activewindow.Selection.Move(mmm, nnn); worddocument1.activewindow.Selection.Fields.Add(worddocument1.activewindow.Selection.Range, aaa, mmm, nnn); aaa := wdFieldNumPages; worddocument1.activewindow.Selection.InsertAfter('页/第'); worddocument1.activewindow.Selection.Move(mmm, nnn); worddocument1.activewindow.Selection.Fields.Add(worddocument1.activewindow.Selection.Range, aaa, mmm, nnn); worddocument1.activewindow.Selection.InsertAfter('页'); mmm := wdWord; nnn := 2; worddocument1.activewindow.Selection.Move(mmm, nnn); worddocument1.activewindow.activepane.selection.insertafter(#13+'武汉大学中南医院'); //结束编辑 worddocument1.ActiveWindow.ActivePane.View.SeekView := wdSeekMainDocument; end; //替换页眉 procedure TForm1.Button6Click(Sender: TObject); var FindText, MatchCase, MatchWholeWord, MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward, Wrap, Format, ReplaceWith, Replace, MatchKashida, MatchDiacritics, MatchAlefHamza, MatchControl:olevariant; i:Single; begin matchcase := false; matchwholeword := true; matchwildcards := false; matchsoundslike := false; matchallwordforms := false; forward := true; wrap := wdfindcontinue; format := false; replace := true; MatchKashida:=True; MatchDiacritics:=True; MatchAlefHamza:=True; MatchControl:=True; findtext := '武汉'; //' <#姓名>' replacewith := '1234'; worddocument1.ActiveWindow.ActivePane.View.SeekView := wdSeekCurrentPageHeader; worddocument1.activewindow.activepane.selection.Find.Execute(Findtext, matchcase, matchwholeword, matchwildcards, matchsoundslike, matchallwordforms, forward, wrap, format, replacewith, replace,MatchKashida, MatchDiacritics, MatchAlefHamza, MatchControl); //结束编辑 worddocument1.ActiveWindow.ActivePane.View.SeekView := wdSeekMainDocument; end;
修改
删除
举报
引用
回复