去掉多余输出

This commit is contained in:
zhaolei 2025-09-19 21:18:04 +08:00
parent 1fc509abb5
commit 34bb69598d
2 changed files with 9 additions and 27 deletions

View File

@ -239,13 +239,6 @@ public class OutputWordUtil {
mergeMRWord(outFile.getPath(),repositoryId,dataMap);
Document doc = new Document(outFile.getPath());
Section section = doc.getLastSection();
UpFileDao upFileDao = new UpFileDao();
@ -434,7 +427,6 @@ public class OutputWordUtil {
Document docs1 = new Document();
docs1.loadFromFile(outFile.getPath());
Document docs2 = new Document();
System.out.println("fileDCContext.getFilePath()======="+fileDCContext.getFilePath());
docs2.loadFromFile(fileDCContext.getFilePath());
@ -443,11 +435,8 @@ public class OutputWordUtil {
// 删除最后一个节
docs1.getSections().remove(lastSection1);
System.out.println("嘻嘻嘻嘻嘻嘻休息休息=");
// 提取所有表格
List<Table> allTables = extractAllTables(docs2);
System.out.println("找到11111111 " + allTables.size() + " 个表格");
if (allTables.size() >= 4) {
// 拆分表格前2个表格后2个表格
@ -459,15 +448,19 @@ public class OutputWordUtil {
// 在前面插入前2个表格
insertTablesBeforeText(docs1, firstTwoTables, position);
// 6. 获取docs2中剩余的内容除了前两个表格
// 获取docs2中剩余的内容除了前两个表格
List<DocumentObject> remainingContent = extractRemainingContent(docs2, firstTwoTables.size());
// 7. 将剩余内容插入到docs1的最后一节
// 将剩余内容插入到docs1的最后一节
insertContentToLastSection(docs1, remainingContent);
// 保存合并后的文档
docs1.saveToFile(outFile.getPath(), FileFormat.Docx);
docs1.dispose();
docs2.dispose();
System.out.println("文档合并成功!");
} else {
System.out.println("未找到文本'流程图'");
@ -476,8 +469,7 @@ public class OutputWordUtil {
System.out.println("源文档中的表格数量不足4个当前只有: " + allTables.size());
}
docs1.dispose();
docs2.dispose();
@ -3192,7 +3184,6 @@ public class OutputWordUtil {
docs1.getSections().remove(lastSection1);
// 定位插入位置根据text判断是流程图前还是活动说明后表格后
Paragraph targetPara = null;
Section targetSection = null;
@ -3296,8 +3287,10 @@ public class OutputWordUtil {
// 在目标文档末尾添加分节符确保新节可以有不同的页面设置
Section lastSection=docs1.addSection();
//设置页面方向为竖向
lastSection.getPageSetup().setOrientation(PageOrientation.Portrait);
//设置页面页眉页脚不连续
lastSection.getHeadersFooters().setLinkToPrevious(false); // 关键步骤
@ -3365,8 +3358,6 @@ public class OutputWordUtil {
HeaderFooter targetFooter = lastSection.getHeadersFooters().getFooter();
targetFooter.getChildObjects().clear();
HeaderFooter footer = lastSection.getHeadersFooters().getFooter();
Paragraph fpara= footer.addParagraph();
@ -3399,15 +3390,6 @@ public class OutputWordUtil {
docs1.dispose();
docs2.dispose();
}
}