2024年2月3日发(作者:)
poi 3.8 poi-scratchpad 3.8 poi-ooxml 3.81. 上代码public static void mergeWord(List wordList, OutputStream outputStream) throws IOException,XmlException { if (y(wordList)) { return; } // docx XWPFDocument newDocument = null; CTBody newCtBody = null; Map headMap = new HashMap<>(30); String newString = null; String prefix = null; StringBuilder mainPart = new StringBuilder(); for (int i = 0; i < (); ++i) { try (InputStream word = (i)) { XWPFDocument xwpfDocument = new XWPFDocument(word); if (i != () - 1) { XWPFRun run = tParagraph().createRun(); ak(); } CTBody ctBody = ument().getBody(); if (i == 0) { newDocument = xwpfDocument; newCtBody = ctBody; newString = t(); prefix = ing(0, f('>') + 1); (newString, f('>') + 1, dexOf('<')); } else {
} else { mergeOther2First(newDocument, mainPart, xwpfDocument, ctBody, headMap); } } catch (IOException | InvalidFormatException e) { tackTrace(); } } String sufix = null; if (newString != null) { sufix = ing(dexOf('<')); } if (newCtBody != null) { ((prefix + ng() + sufix)); } if (newDocument != null) { (outputStream); }}public static void mergeWord1(List wordList, OutputStream outputStream) throws IOException,XmlException { if (y(wordList)) { return; } XWPFDocument newDocument = null; CTBody newCtBody = null; Map headMap = new HashMap<>(30); String newString = null; String prefix = null; StringBuilder mainPart = new StringBuilder(); for (int i = 0; i < (); ++i) { try (InputStream word = (i)) { XWPFDocument xwpfDocument = new XWPFDocument(word); if (i != () - 1) { XWPFRun run = tParagraph().createRun(); ak(); } CTBody ctBody = ument().getBody(); if (i == 0) { newDocument = xwpfDocument; newCtBody = ctBody; newString = t(); prefix = ing(0, f('>') + 1); (newString, f('>') + 1, dexOf('<')); } else { mergeOther2First(newDocument, mainPart, xwpfDocument, ctBody, headMap); } } catch (IOException | InvalidFormatException e) { tackTrace(); } } String sufix = null; if (newString != null) { sufix = ing(dexOf('<')); } if (newCtBody != null) { ((prefix + ng() + sufix));
Iterator iterator = or();while (t()) {InputStream is = ();if (is != null) {if (target == null) {OutputStream os = new FileOutputStream(generated);(Array(is));();target = (generated);} else {insertDoc(nDocumentPart(), Array(is), chunkId++); }}}if (target != null) {(generated);FileInputStream fileInputStream = new FileInputStream(generated); saveTemplate(fileInputStream,out);}}private void insertDoc(MainDocumentPart mainDocumentPart, byte[] bytes, int chunkId) {try {PartName partName = new PartName("/part" + chunkId + ".docx");AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(partName); aryData(bytes); Relationship relationship = getPart(afiPart); CTAltChunk chunk = ObjectFactory().createCTAltChunk(); (()); ect(chunk);} catch (Exception e) { tackTrace();}}private void saveTemplate(InputStream targetStream, OutputStream out) {
发布评论