如何读取在WORD中的"姓名:"二字..也就是说,我想实现如下效果,就是说,先在WORD中找到"姓名:"二字,然后再回车下面自动将姓名补上去.不知该如何操作?

解决方案 »

  1.   

    //就是一个查找替换的功能,例如查找姓名: 替换为姓名:张三var  
              wordApp   :   Variant;  
              wdReplaceAll;  
      begin  
              try  
                      wordApp   :=   CreateOleObject('Word.Application');  
                      wordApp.visible   :=   true;  
              except  
                      MessageBox(0,'请确定是否安装了Word',MB_OK+MB_ICONINFORMATION);  
                      Exit;  
              end;  
              wordApp.Documents.Open('c:\test.doc',False,False,False,'','',false);  
              wordApp.Selection.Find.ClearFormatting;  
              wordApp.Selection.Find.Replacement.ClearFormatting;  
              wordApp.Selection.Find.Text   :=   '1234';  
              wordApp.Selection.Find.Replacement.Text   :='4321';  
              wordApp.Selection.Find.Forward   :=True;  
              wdFindContinue   :=   1;  
              wordApp.Selection.Find.Wrap   :=   wdFindContinue;  
              wordApp.Selection.Find.Format   :=False;  
              wordApp.Selection.Find.MatchCase   :=False;  
              wordApp.Selection.Find.MatchWholeWord   :=False;  
              wordApp.Selection.Find.MatchByte   :=True;  
              wordApp.Selection.Find.MatchWildcards   :=False;  
              wordApp.Selection.Find.MatchSoundsLike   :=False;  
              wordApp.Selection.Find.MatchAllWordForms   :=False;  
              wdReplaceAll   :=   2;  
       
              //下面这句最重要,是将文档中所有为1234的字符替换成4231,在Delphi中调用Word的宏命令  
              //如果有缺省参数可以不写后面直接打逗号  
              wordApp.Selection.Find.Execute('1234',,,,,,,wdFindContinue,,'4231',wdReplaceAll);  
      end;
      

  2.   

    回车#13
    换行#10
    wordApp.Selection.Find.Replacement.Text   := #13 + '4321'
      

  3.   

    现在出现个问题,以上的回复都是有关WORD中的替换功能,一旦要在姓名下面加入一段文字的时候,就会提示"文字参数太长"这样的错误.我想能否实现先找到"姓名"二字,然后在这两个字的下面把一段很长的段落追加上去?
      

  4.   

    也就是把Selection.TypeText Text:="dsafsadfdasf"转换成DELPHI语言怎么转?
      

  5.   

    用servers下面的wodapplication.
    WordApplication1.Selection.TypeText('asdfasdfasdf');