| | |
| | | import org.apache.poi.xwpf.usermodel.XWPFDocument; |
| | | import org.apache.poi.xwpf.usermodel.XWPFNumbering; |
| | | import org.apache.poi.xwpf.usermodel.XWPFParagraph; |
| | | import org.apache.poi.xwpf.usermodel.XWPFRun; |
| | | import org.apache.poi.xwpf.usermodel.XWPFTable; |
| | | import org.apache.poi.xwpf.usermodel.XWPFTableCell; |
| | | import org.apache.poi.xwpf.usermodel.XWPFTableRow; |
| | | import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber; |
| | | import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNumLvl; |
| | | import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNumPr; |
| | |
| | | } |
| | | document.getTables().forEach(table -> table.getRows().forEach(row -> |
| | | row.getTableCells().forEach(cell -> sanitizeCell(document, cell, normalizeDangerDetail)))); |
| | | if (normalizeDangerDetail) { |
| | | boldSummaryRows(document, "综合得分"); |
| | | } |
| | | document.getHeaderList().forEach(header -> header.getParagraphs().forEach(WordNumberingSanitizer::sanitizeParagraph)); |
| | | document.getFooterList().forEach(footer -> footer.getParagraphs().forEach(WordNumberingSanitizer::sanitizeParagraph)); |
| | | } |
| | |
| | | row.getTableCells().forEach(innerCell -> sanitizeCell(document, innerCell, normalizeDangerDetail)))); |
| | | } |
| | | |
| | | private static void boldSummaryRows(XWPFDocument document, String markerText) { |
| | | if (document == null || markerText == null || markerText.isBlank()) { |
| | | return; |
| | | } |
| | | |
| | | for (XWPFTable table : document.getTables()) { |
| | | for (XWPFTableRow row : table.getRows()) { |
| | | boolean summaryRow = row.getTableCells().stream() |
| | | .map(XWPFTableCell::getText) |
| | | .anyMatch(text -> text != null && text.contains(markerText)); |
| | | if (!summaryRow) { |
| | | continue; |
| | | } |
| | | for (XWPFTableCell cell : row.getTableCells()) { |
| | | for (XWPFParagraph paragraph : cell.getParagraphs()) { |
| | | for (XWPFRun run : paragraph.getRuns()) { |
| | | run.setBold(true); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private static void normalizeDangerDetailHeadingNumbering(XWPFDocument document, List<XWPFParagraph> paragraphs) { |
| | | boolean inDangerDetail = false; |
| | | boolean pendingNewGroup = false; |