河北报告定制化改动
This commit is contained in:
@@ -1232,16 +1232,34 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
Tr existingRow = (Tr) tbl.getContent().get(rows.size() - 1);
|
Tr existingRow = (Tr) tbl.getContent().get(rows.size() - 1);
|
||||||
// 获取现有样式
|
// 获取现有样式
|
||||||
TrPr trPr = existingRow.getTrPr();
|
TrPr trPr = existingRow.getTrPr();
|
||||||
JAXBElement<Tc> element = (JAXBElement<Tc>) existingRow.getContent().get(0);
|
// 获取每个单元格的TcPr(保留各单元格独立的边框设置)
|
||||||
TcPr tcPr = element.getValue().getTcPr();
|
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();
|
TblWidth cellWidth = factory.createTblWidth();
|
||||||
cellWidth.setType("dxa");
|
cellWidth.setType("dxa");
|
||||||
cellWidth.setW(BigInteger.valueOf(5000 / tableKeys.size()));
|
cellWidth.setW(BigInteger.valueOf(5000 / tableKeys.size()));
|
||||||
tcPr.setTcW(cellWidth);
|
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);
|
tbl.getContent().remove(existingRow);
|
||||||
// 迭代增加行,需要填充的表格keys在tableKeys集合中
|
// 迭代增加行,需要填充的表格keys在tableKeys集合中
|
||||||
for (Map<String, String> stringStringMap : dataList) {
|
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);
|
tbl.getContent().add(newRow);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -93,18 +93,19 @@ public class BookmarkUtil {
|
|||||||
idx = idx + 1;
|
idx = idx + 1;
|
||||||
parentContent.add(idx, p);
|
parentContent.add(idx, p);
|
||||||
}
|
}
|
||||||
else if (textFromP.startsWith(PowerIndexEnum.IMBV.getDesc())
|
// else if (textFromP.startsWith(PowerIndexEnum.IMBV.getDesc())
|
||||||
|| textFromP.startsWith(PowerIndexEnum.HV.getDesc())
|
// || textFromP.startsWith(PowerIndexEnum.HV.getDesc())
|
||||||
|| textFromP.startsWith(PowerIndexEnum.HI.getDesc())
|
// || textFromP.startsWith(PowerIndexEnum.HI.getDesc())
|
||||||
|
//
|
||||||
) {
|
// ) {
|
||||||
// 另起一页
|
// // 另起一页
|
||||||
P pagePara = Docx4jUtil.getPageBreak();
|
// P pagePara = Docx4jUtil.getPageBreak();
|
||||||
idx = idx + 1;
|
// idx = idx + 1;
|
||||||
parentContent.add(idx, pagePara);
|
// parentContent.add(idx, pagePara);
|
||||||
idx = idx + 1;
|
// idx = idx + 1;
|
||||||
parentContent.add(idx, element);
|
// parentContent.add(idx, element);
|
||||||
}else if(textFromP.startsWith("注:基波电流幅值5.000A,基波频率50.0Hz,各次间谐波电流含有率均为3.0%。")){
|
// }
|
||||||
|
else if(textFromP.startsWith("注:基波电流幅值5.000A,基波频率50.0Hz,各次间谐波电流含有率均为3.0%。")){
|
||||||
idx = idx + 1;
|
idx = idx + 1;
|
||||||
parentContent.add(idx, element);
|
parentContent.add(idx, element);
|
||||||
P pagePara = Docx4jUtil.getPageBreak();
|
P pagePara = Docx4jUtil.getPageBreak();
|
||||||
|
|||||||
@@ -322,17 +322,20 @@ public class Docx4jUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据已知信息创建新航
|
* 根据已知信息创建新行
|
||||||
*
|
*
|
||||||
* @param factory 工厂
|
* @param factory 工厂
|
||||||
* @param valueMap 数据
|
* @param valueMap 数据
|
||||||
* @param tableKeys keys
|
* @param tableKeys keys
|
||||||
* @param trPr 行样式
|
* @param trPr 行样式
|
||||||
* @param tcPr 单元格样式
|
* @param tcPrList 每个单元格的样式列表(用于保留各单元格独立的边框设置)
|
||||||
|
* @param templateRPr 模板中的字体样式(可为null,为null时使用默认宋体10号)
|
||||||
|
* @param centerFlag 是否居中
|
||||||
*/
|
*/
|
||||||
public static Tr createCustomRow(ObjectFactory factory, Map<String, String> valueMap, List<String> tableKeys, TrPr trPr, TcPr tcPr, boolean centerFlag) {
|
public static Tr createCustomRow(ObjectFactory factory, Map<String, String> valueMap, List<String> tableKeys, TrPr trPr, List<TcPr> tcPrList, RPr templateRPr, boolean centerFlag) {
|
||||||
Tr row = factory.createTr();
|
Tr row = factory.createTr();
|
||||||
for (String tableKey : tableKeys) {
|
for (int i = 0; i < tableKeys.size(); i++) {
|
||||||
|
String tableKey = tableKeys.get(i);
|
||||||
Tc cell = factory.createTc();
|
Tc cell = factory.createTc();
|
||||||
P paragraph = factory.createP();
|
P paragraph = factory.createP();
|
||||||
R run = factory.createR();
|
R run = factory.createR();
|
||||||
@@ -341,20 +344,41 @@ public class Docx4jUtil {
|
|||||||
text.setValue(value);
|
text.setValue(value);
|
||||||
run.getContent().add(text);
|
run.getContent().add(text);
|
||||||
paragraph.getContent().add(run);
|
paragraph.getContent().add(run);
|
||||||
// 字体
|
|
||||||
// 设置字体
|
// 从模板复制字体样式
|
||||||
RPr rPr = factory.createRPr();
|
RPr rPr = factory.createRPr();
|
||||||
|
if (templateRPr != null) {
|
||||||
|
// 复制字体
|
||||||
|
if (templateRPr.getRFonts() != null) {
|
||||||
|
RFonts rFonts = factory.createRFonts();
|
||||||
|
rFonts.setEastAsia(templateRPr.getRFonts().getEastAsia());
|
||||||
|
rFonts.setAscii(templateRPr.getRFonts().getAscii());
|
||||||
|
rFonts.setHAnsi(templateRPr.getRFonts().getHAnsi());
|
||||||
|
rPr.setRFonts(rFonts);
|
||||||
|
}
|
||||||
|
// 复制字号
|
||||||
|
if (templateRPr.getSz() != null) {
|
||||||
|
HpsMeasure sz = factory.createHpsMeasure();
|
||||||
|
sz.setVal(templateRPr.getSz().getVal());
|
||||||
|
rPr.setSz(sz);
|
||||||
|
}
|
||||||
|
if (templateRPr.getSzCs() != null) {
|
||||||
|
HpsMeasure szCs = factory.createHpsMeasure();
|
||||||
|
szCs.setVal(templateRPr.getSzCs().getVal());
|
||||||
|
rPr.setSzCs(szCs);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 默认使用宋体10号
|
||||||
RFonts rFonts = factory.createRFonts();
|
RFonts rFonts = factory.createRFonts();
|
||||||
if (containsChinese(value)) {
|
|
||||||
rFonts.setEastAsia("宋体");
|
rFonts.setEastAsia("宋体");
|
||||||
rFonts.setAscii("宋体");
|
rFonts.setAscii("宋体");
|
||||||
rFonts.setHAnsi("宋体");
|
rFonts.setHAnsi("宋体");
|
||||||
} else {
|
|
||||||
rFonts.setEastAsia("Arial");
|
|
||||||
rFonts.setAscii("Arial");
|
|
||||||
rFonts.setHAnsi("Arial");
|
|
||||||
}
|
|
||||||
rPr.setRFonts(rFonts);
|
rPr.setRFonts(rFonts);
|
||||||
|
HpsMeasure sz = factory.createHpsMeasure();
|
||||||
|
sz.setVal(new BigInteger("20"));
|
||||||
|
rPr.setSz(sz);
|
||||||
|
}
|
||||||
|
|
||||||
// 设置段落居中
|
// 设置段落居中
|
||||||
if (centerFlag) {
|
if (centerFlag) {
|
||||||
PPr pPr = factory.createPPr();
|
PPr pPr = factory.createPPr();
|
||||||
@@ -363,20 +387,19 @@ public class Docx4jUtil {
|
|||||||
pPr.setJc(jc);
|
pPr.setJc(jc);
|
||||||
paragraph.setPPr(pPr);
|
paragraph.setPPr(pPr);
|
||||||
}
|
}
|
||||||
if (value.equals("不合格")) {
|
// 不合格标红
|
||||||
|
if (value != null && value.equals("不合格")) {
|
||||||
Color color = factory.createColor();
|
Color color = factory.createColor();
|
||||||
// 红色
|
|
||||||
color.setVal("FF0000");
|
color.setVal("FF0000");
|
||||||
rPr.setColor(color);
|
rPr.setColor(color);
|
||||||
run.setRPr(rPr);
|
|
||||||
}
|
}
|
||||||
HpsMeasure sz = factory.createHpsMeasure();
|
run.setRPr(rPr);
|
||||||
// 10号字体 = 20 half-points
|
|
||||||
sz.setVal(new BigInteger("20"));
|
|
||||||
rPr.setSz(sz);
|
|
||||||
|
|
||||||
cell.getContent().add(paragraph);
|
cell.getContent().add(paragraph);
|
||||||
cell.setTcPr(tcPr);
|
// 使用对应位置的单元格样式(保留边框设置)
|
||||||
|
if (tcPrList != null && i < tcPrList.size()) {
|
||||||
|
cell.setTcPr(tcPrList.get(i));
|
||||||
|
}
|
||||||
row.getContent().add(cell);
|
row.getContent().add(cell);
|
||||||
row.setTrPr(trPr);
|
row.setTrPr(trPr);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user