Java replace specified text using the new text in a Word document

        The creation of a copy, often high-frequency use certain words, such as names, names, characters and other positions, if the expression is wrong, we need to replace a whole. The text describes how to use Spire.Doc for Java, replace the specified text in a Word document in Java programs.

Tools / materials

  •  IntelliJ IDEA

Jar file and obtain import

Method 1 : start with the official website to download jar package .

Introduction step:

After the download, unzip the file and the lib folder under the Spire.Doc.jar file into java program. Import reference to the following effects:

Method 2 : by maven mounted introducing warehouse.

Java code examples:

Import com.spire.doc *. ;
 public  class ReplaceText {
     public  static  void main (String [] args) {
         // Load Word document 
        the Document Document = new new the Document ( "C: \\ Test1 the Users \\ \\ \\ Tang Desktop Mount town the .docx " ;) 

        // replace the specified text in the document with the new text 
        Tangmo" "Tangmo document.replace (" " to false , to true ); 

        // save the document 
        document.saveToFile (" ReplaceAllMatchedText.docx " , FileFormat.Docx_2013); 
    } 
}

Alternatively longitudinal effect is as follows:

 

Guess you like

Origin www.cnblogs.com/eLaura/p/11445656.html