Parse 03 version (.doc) word:
DOC = HWPFDocument null ; // Version HWPFDocument 03 corresponding to word the try { DOC = new new HWPFDocument ( new new the FileInputStream ( "F.: \\ \\ template_03.doc Upload" )); // get the word template to replace the Range Range = DOC. getRange (); // range word acquired in the content for (of Map.Entry <String, String> entry: replaceContent.entrySet ()) {// replace the contents of the Map key value stored content to be replaced by a Map Map value the value stored content to be replaced, the last cycle is achieved by a range.replaceText (entry.getKey (), entry.getValue ()); } } the catch (IOException E) { e.printStackTrace (); } return doc;
Parse 07 (.docx) word:
Docx = XWPFDocument null ; the try { docx = new new XWPFDocument ( new new the FileInputStream ( "F.: \\ \\ template_07.docx Upload" )); List <XWPFParagraph> = the Paragraphs docx.getParagraphs (); // Version 07 must first obtain paragraphs ; and finally obtaining the divided minimum unit format RUN for (XWPFParagraph paragraph: the Paragraphs) { List <XWPFRun> = the runs paragraph.getRuns (); for (RUN XWPFRun: the runs) { String STR = run.getText (run.getTextPosition ( )); // get the strings run for (Map.Entry<String,String> entry:replaceContent.entrySet()){ str=str.replace(entry.getKey(),entry.getValue()); } run.setText(str,0); } } } catch (IOException e) { e.printStackTrace(); } return docx;