河北报告定制化改动

This commit is contained in:
2025-12-02 13:52:07 +08:00
parent 9ab5d42439
commit 9f11f7ec11
2 changed files with 113 additions and 8 deletions

View File

@@ -1600,18 +1600,37 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
// 获取现有行的样式
Tr existingRow = (Tr) tbl.getContent().get(rows.size() - 1);
// 获取现有样式
TrPr trPr = existingRow.getTrPr();
JAXBElement<Tc> element = (JAXBElement<Tc>) existingRow.getContent().get(0);
TcPr tcPr = element.getValue().getTcPr();
TblWidth cellWidth = factory.createTblWidth();
cellWidth.setType("dxa");
cellWidth.setW(BigInteger.valueOf(5000 / tableKeys.size()));
tcPr.setTcW(cellWidth);
// 获取每个单元格的TcPr保留各单元格独立的边框设置
List<TcPr> tcPrList = new ArrayList<>();
RPr templateRPr = null;
for (Object cellObj : existingRow.getContent()) {
if (cellObj instanceof JAXBElement) {
JAXBElement<Tc> cellElement = (JAXBElement<Tc>) cellObj;
Tc templateCell = cellElement.getValue();
TcPr tcPr = templateCell.getTcPr();
// 设置单元格宽度
if (tcPr == null) {
tcPr = factory.createTcPr();
}
TblWidth cellWidth = factory.createTblWidth();
cellWidth.setType("dxa");
cellWidth.setW(BigInteger.valueOf(5000 / tableKeys.size()));
tcPr.setTcW(cellWidth);
tcPrList.add(tcPr);
// 从第一个单元格获取字体样式
if (templateRPr == null && !templateCell.getContent().isEmpty() && templateCell.getContent().get(0) instanceof P) {
P templateP = (P) templateCell.getContent().get(0);
templateRPr = Docx4jUtil.getTcPrFromParagraph(templateP);
}
}
}
tbl.getContent().remove(existingRow);
// 迭代增加行,需要填充的表格keys在tableKeys集合中
for (Map<String, String> stringStringMap : dataList) {
Tr newRow = Docx4jUtil.createCustomRow(factory, stringStringMap, tableKeys, trPr, tcPr, true);
Tr newRow = Docx4jUtil.createCustomRow(factory, stringStringMap, tableKeys, trPr, tcPrList, templateRPr, true);
tbl.getContent().add(newRow);
}
} else {