|
|
|
|
@ -6,10 +6,8 @@ import com.deepoove.poi.policy.DynamicTableRenderPolicy;
|
|
|
|
|
import com.deepoove.poi.policy.TableRenderPolicy;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
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.CTTcBorders;
|
|
|
|
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
|
|
|
|
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@ -24,11 +22,6 @@ public class ErpContractApprovalTablePolicy extends DynamicTableRenderPolicy {
|
|
|
|
|
*/
|
|
|
|
|
private static final int DETAIL_START_ROW = 1;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 审批记录列数:序号、审批人、审批意见、审批时间
|
|
|
|
|
*/
|
|
|
|
|
private static final int COLUMN_COUNT = 4;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void render(XWPFTable table, Object data) throws Exception {
|
|
|
|
|
if (data == null) {
|
|
|
|
|
@ -49,28 +42,21 @@ public class ErpContractApprovalTablePolicy extends DynamicTableRenderPolicy {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XWPFTableRow templateRow = table.getRow(DETAIL_START_ROW);
|
|
|
|
|
if (templateRow == null) {
|
|
|
|
|
log.warn("合同审批记录模板行不存在,跳过表格渲染");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
CTRow templateCtRow = CTRow.Factory.newInstance();
|
|
|
|
|
templateCtRow.set(templateRow.getCtRow());
|
|
|
|
|
table.removeRow(DETAIL_START_ROW);
|
|
|
|
|
for (int i = 0; i < rows.size(); i++) {
|
|
|
|
|
RowRenderData rowData = rows.get(i);
|
|
|
|
|
int rowIndex = DETAIL_START_ROW + i;
|
|
|
|
|
XWPFTableRow newRow = table.insertNewTableRow(rowIndex);
|
|
|
|
|
for (int j = 0; j < COLUMN_COUNT; j++) {
|
|
|
|
|
XWPFTableCell cell = newRow.createCell();
|
|
|
|
|
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
|
|
|
|
|
setCellBorder(cell);
|
|
|
|
|
}
|
|
|
|
|
TableRenderPolicy.Helper.renderRow(table.getRow(rowIndex), rowData);
|
|
|
|
|
// 动态插入行如果不复制模板行样式,Word 会退回默认字体,导致审批记录区和模板字体不一致
|
|
|
|
|
newRow.getCtRow().set(templateCtRow);
|
|
|
|
|
TableRenderPolicy.Helper.renderRow(newRow, rowData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setCellBorder(XWPFTableCell cell) {
|
|
|
|
|
if (cell.getCTTc().getTcPr() == null) {
|
|
|
|
|
cell.getCTTc().addNewTcPr();
|
|
|
|
|
}
|
|
|
|
|
CTTcBorders borders = cell.getCTTc().getTcPr().addNewTcBorders();
|
|
|
|
|
borders.addNewTop().setVal(STBorder.SINGLE);
|
|
|
|
|
borders.addNewBottom().setVal(STBorder.SINGLE);
|
|
|
|
|
borders.addNewLeft().setVal(STBorder.SINGLE);
|
|
|
|
|
borders.addNewRight().setVal(STBorder.SINGLE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|