diff --git a/com.actionsoft.apps.coe.pal/lib/com.actionsoft.apps.coe.pal.jar b/com.actionsoft.apps.coe.pal/lib/com.actionsoft.apps.coe.pal.jar index dfcd0479..b79e7c37 100644 Binary files a/com.actionsoft.apps.coe.pal/lib/com.actionsoft.apps.coe.pal.jar and b/com.actionsoft.apps.coe.pal/lib/com.actionsoft.apps.coe.pal.jar differ diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/output/util/OutputWordUtil.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/output/util/OutputWordUtil.java index f577c265..6bce5dc5 100755 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/output/util/OutputWordUtil.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/output/util/OutputWordUtil.java @@ -546,13 +546,18 @@ public class OutputWordUtil { } } + // 在第一页的末尾插入分页符 + //section.addParagraph().appendBreak(BreakType.Page_Break); + + + + + document.saveToFile(outFile.getPath(), FileFormat.Docx_2013); } - String suffix = fileName.substring(fileName.lastIndexOf(".") + 1); - if (suffix.equals("xml")) { // 输出文档路径及名称 File sourceFile = new UtilFile(path + fileName); @@ -570,39 +575,187 @@ public class OutputWordUtil { //保存为xml格式 String substring = fileName.substring(0, fileName.lastIndexOf(".xml")); + //保存为Word doc.saveToFile(docPath + substring + ".docx", FileFormat.Docx);//支持.doc - - } - if (suffix.equals("xml")) { //保存为xml格式 String substring = fileName.substring(0, fileName.lastIndexOf(".xml")); //保存为Word - document.insertTextFromFile(docPath + substring + ".docx", FileFormat.Docx_2013); + /*document.insertTextFromFile(docPath + substring + ".docx", FileFormat.Docx_2013); + document.saveToFile(outFile.getPath(), FileFormat.Docx_2013);*/ + + + Document document1 = new Document(outFile.getPath()); + Document document2 = new Document(docPath + substring + ".docx"); + + // 获取最后第一节 + Section section = document1.getLastSection(); + // 获取该节第三段 + Paragraph paragraph = section.getParagraphs().get(3); + // 在段落的末尾添加分页符 + paragraph.appendBreak(BreakType.Page_Break); + // 在第二个文档中循环获取所有节 + for (Object sectionObj : (Iterable) document2.getSections()) { + Section sec = (Section) sectionObj; + // 在所有节中循环获取所有子对象 + for (Object docObj : (Iterable) sec.getBody().getChildObjects()) { + DocumentObject obj = (DocumentObject) docObj; + + // 获取第一个文档的最后一节 + Section lastSection = document1.getLastSection(); + + // 将所有子对象添加到第一个文档的最后一节中 + Body body = lastSection.getBody(); + body.getChildObjects().add(obj.deepClone()); + } + } + + //保存结果文档 + document1.saveToFile(outFile.getPath(), FileFormat.Docx_2013); + + + + // 获取第一个节的第一个表格 + Section threesection = document1.getSections().get(1); + Table table3 = threesection.getTables().get(2); + //遍历表格单元格 + for (int i = 0;i< table3.getRows().getCount();i++) { + TableRow rows = table3.getRows().get(i); + for (int j = 0; j< rows.getCells().getCount(); j++){ + for (int z= 0; z < rows.getCells().get(j).getParagraphs().getCount();z++){ + Paragraph p = rows.getCells().get(j).getParagraphs().get(z); + p.getFormat().setLineSpacing(12f);//设置边距为1.0 + for (int k = 0; k < p.getItems().getCount(); k++) { + DocumentObject item = p.getItems().get(k); + if (item instanceof TextRange) { + TextRange textRange = (TextRange) item; + textRange.getCharacterFormat().setFontName("宋体"); + textRange.getCharacterFormat().setFontSize(10.5f); + } + } + } + } + } + + + // 获取第一个节的第一个表格 + Section fourection = document1.getSections().get(1); + + Table table4 = fourection.getTables().get(3); + //遍历表格单元格 + for (int i = 0;i< table4.getRows().getCount();i++) { + TableRow rows = table4.getRows().get(i); + for (int j = 0; j< rows.getCells().getCount(); j++){ + for (int z= 0; z < rows.getCells().get(j).getParagraphs().getCount();z++){ + Paragraph p = rows.getCells().get(j).getParagraphs().get(z); + p.getFormat().setLineSpacing(12f);//设置边距为1.0 + for (int k = 0; k < p.getItems().getCount(); k++) { + DocumentObject item = p.getItems().get(k); + if (item instanceof TextRange) { + TextRange textRange = (TextRange) item; + textRange.getCharacterFormat().setFontName("宋体"); + textRange.getCharacterFormat().setFontSize(10.5f); + } + } + } + } + } + document1.saveToFile(outFile.getPath(), FileFormat.Docx_2013); + + } else if (suffix.equals("doc") || suffix.equals("docx")) { - document.insertTextFromFile(path + fileName, FileFormat.Docx_2013); - } else if (suffix.equals("pptx")) { + //document.insertTextFromFile(path + fileName, FileFormat.Doc); + + + Document document1 = new Document(outFile.getPath()); + Document document2 = new Document(path + fileName); + + // 获取最后第一节 + Section section = document1.getLastSection(); + // 获取该节第三段 + Paragraph paragraph = section.getParagraphs().get(3); + // 在段落的末尾添加分页符 + paragraph.appendBreak(BreakType.Page_Break); + // 在第二个文档中循环获取所有节 + for (Object sectionObj : (Iterable) document2.getSections()) { + Section sec = (Section) sectionObj; + // 在所有节中循环获取所有子对象 + for (Object docObj : (Iterable) sec.getBody().getChildObjects()) { + DocumentObject obj = (DocumentObject) docObj; + + // 获取第一个文档的最后一节 + Section lastSection = document1.getLastSection(); + + // 将所有子对象添加到第一个文档的最后一节中 + Body body = lastSection.getBody(); + body.getChildObjects().add(obj.deepClone()); + } + } + + //保存结果文档 + document1.saveToFile(outFile.getPath(), FileFormat.Docx_2013); + + + + // 获取第一个节的第一个表格 + Section threesection = document1.getSections().get(1); + + if(threesection.getTables().getCount()>3){ + Table table3 = threesection.getTables().get(2); + //遍历表格单元格 + for (int i = 0;i< table3.getRows().getCount();i++) { + TableRow rows = table3.getRows().get(i); + for (int j = 0; j< rows.getCells().getCount(); j++){ + for (int z= 0; z < rows.getCells().get(j).getParagraphs().getCount();z++){ + Paragraph p = rows.getCells().get(j).getParagraphs().get(z); + p.getFormat().setLineSpacing(12f);//设置边距为1.0 + for (int k = 0; k < p.getItems().getCount(); k++) { + DocumentObject item = p.getItems().get(k); + if (item instanceof TextRange) { + TextRange textRange = (TextRange) item; + textRange.getCharacterFormat().setFontName("宋体"); + textRange.getCharacterFormat().setFontSize(10.5f); + } + } + } + } + } + + + Table table4 = threesection.getTables().get(3); + //遍历表格单元格 + for (int i = 0;i< table4.getRows().getCount();i++) { + TableRow rows = table4.getRows().get(i); + for (int j = 0; j< rows.getCells().getCount(); j++){ + for (int z= 0; z < rows.getCells().get(j).getParagraphs().getCount();z++){ + Paragraph p = rows.getCells().get(j).getParagraphs().get(z); + p.getFormat().setLineSpacing(12f);//设置边距为1.0 + for (int k = 0; k < p.getItems().getCount(); k++) { + DocumentObject item = p.getItems().get(k); + if (item instanceof TextRange) { + TextRange textRange = (TextRange) item; + textRange.getCharacterFormat().setFontName("宋体"); + textRange.getCharacterFormat().setFontSize(10.5f); + } + } + } + } + } + document1.saveToFile(outFile.getPath(), FileFormat.Docx_2013); + } + + + + }else if (suffix.equals("pptx")) { isPPT = true; } if (isPPT == false) { - try { - //保存结果文档 - document.saveToFile(outFile.getPath(), FileFormat.Docx_2013); - } catch (Exception e) { - e.printStackTrace(); - } finally { - // 关闭文档对象 - if (document != null) { - document.close(); - document.dispose(); - } - } //复制页眉页脚操作 try { @@ -666,10 +819,6 @@ public class OutputWordUtil { } } - - - - doc2.saveToFile(outFile.getPath(), FileFormat.Docx_2013); } catch (Exception e) {