如题,我想用delphi控制word,如何替换word中页眉文字?

解决方案 »

  1.   

    调用word功能,先搜索,再替换,可参考:
    var 
    FindText, MatchCase, MatchWholeWord, MatchWildcards, MatchSoundsLike, 
    MatchAllWordForms, Forward, Wrap, Format, ReplaceWith, Replace: OleVariant; 
    begin 
    FindText := '<#Name>'; 
    MatchCase := False; 
    MatchWholeWord := True; 
    MatchWildcards := False; 
    MatchSoundsLike := False; 
    MatchAllWordForms := False; 
    Forward := True; 
    Wrap := wdFindContinue; 
    Format := False; 
    ReplaceWith := 'Delphi'; 
    Replace := True; WordDocument.Range.Find.Execute( FindText, MatchCase, MatchWholeWord, 
    MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward, 
    Wrap, Format, ReplaceWith, Replace ); end; 
      

  2.   

    用Word录制个宏,参考宏里面的代码
      

  3.   

        ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
        ActiveDocument.AttachedTemplate.BuildingBlockEntries(" 空白").Insert Where:= _
            Selection.Range, RichText:=True
        Selection.TypeText Text:="就这样明白吧"
        ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument这是vb的转下delphi  一看就知吧