1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| @Slf4j public class TemplateGksxTablePolicy extends DynamicTableRenderPolicy {
@Override public void render(XWPFTable table, Object data) throws Exception { if(data == null){ log.error("待渲染管控事项数据为空。"); return; } GksxTableData gksxTableData = (GksxTableData) data; List<GksxRowData> problemList = gksxTableData.getGksxRowDataList();
Style style = getStyle(); int startRow = 2; for (int i = 0; i < problemList.size(); i++) { XWPFTableRow insertNewTableRow = table.insertNewTableRow(startRow+i); for (int j = 0; j < 4; j++) insertNewTableRow.createCell();
GksxRowData gksxRowData = problemList.get(i); RowRenderData templateGksxRow = Rows.of( new TextRenderData(gksxRowData.getProblemTypeDesc(),style) ,new TextRenderData(gksxRowData.getNum(),style), new TextRenderData(gksxRowData.getProblemContent(),style), new TextRenderData(String.valueOf(gksxRowData.getProblemScore()),style)) .center() .create(); TableRenderPolicy.Helper.renderRow(table.getRow(startRow+i), templateGksxRow); }
GksxRowData firstRowData = problemList.get(0); if(firstRowData.getTypeOneSize() > 1){ TableTools.mergeCellsVertically(table, 0, startRow, startRow+firstRowData.getTypeOneSize()-1); } if(firstRowData.getTypeTwoSize() > 1){ TableTools.mergeCellsVertically(table, 0, startRow+firstRowData.getTypeOneSize(), startRow+firstRowData.getTypeOneSize()+firstRowData.getTypeTwoSize()-1); } TableTools.mergeCellsHorizonal(table, startRow+firstRowData.getTypeOneSize()+firstRowData.getTypeTwoSize(), 0, 2); }
private Style getStyle(){ final Style style = new Style(); style.setFontFamily("FangSong"); style.setFontSize(12); style.setBold(false); return style; } }
|