| | |
| | | newTableRenderData.setRows(new ArrayList<>(firstTwoRows)); |
| | | //设置样式 |
| | | TableStyle tableStyle = new TableStyle(); |
| | | for (int i = 1; i <= max; i++) { |
| | | // 根据减压那结果个数修改长度 |
| | | switch (i) { |
| | | case 1: |
| | | tableStyle.setColWidths(new int[]{650, 2000, 2000, 850, 2200, 2100, 1200}); |
| | | break; |
| | | case 2: |
| | | tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 2100, 1200, 1200, 1200}); |
| | | break; |
| | | case 3: |
| | | tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 1500, 1000, 1000, 1000, 1200}); |
| | | break; |
| | | case 4: |
| | | tableStyle.setColWidths(new int[]{650, 1200, 1200, 850, 1400, 850, 850, 850, 850, 1200}); |
| | | break; |
| | | case 5: |
| | | tableStyle.setColWidths(new int[]{650, 1100, 1100, 850, 1350, 750, 750, 750, 750, 750, 1200}); |
| | | break; |
| | | } |
| | | } |
| | | // for (int i = 1; i <= max; i++) { |
| | | // } |
| | | // 根据检验结果个数修改长度 |
| | | tableStyle.setColWidths(calcTableColWidths(max)); |
| | | // switch (max) { |
| | | // case 1: |
| | | // tableStyle.setColWidths(new int[]{650, 2000, 2000, 850, 2200, 2100, 1200}); |
| | | // break; |
| | | // case 2: |
| | | // tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 2100, 1200, 1200, 1200}); |
| | | // break; |
| | | // case 3: |
| | | // tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 1500, 1000, 1000, 1000, 1200}); |
| | | // break; |
| | | // case 4: |
| | | // tableStyle.setColWidths(new int[]{650, 1200, 1200, 850, 1400, 850, 850, 850, 850, 1200}); |
| | | // break; |
| | | // case 5: |
| | | // tableStyle.setColWidths(new int[]{650, 1100, 1100, 850, 1350, 750, 750, 750, 750, 750, 1200}); |
| | | // break; |
| | | // } |
| | | tableStyle.setWidth("10000"); |
| | | tableStyle.setAlign(TableRowAlign.CENTER); |
| | | BorderStyle borderStyle = new BorderStyle(); |
| | |
| | | } |
| | | tableRenderData.getRows().add(row); |
| | | } |
| | | if (!tableRenderData.getRows().isEmpty() && tableRenderData.getRows().size() != 3) { |
| | | TableStyle tableStyle = new TableStyle(); |
| | | if (tableRenderData.getRows().size() != 3) { |
| | | //设置样式 |
| | | TableStyle tableStyle = new TableStyle(); |
| | | for (int i = 1; i <= max; i++) { |
| | | // 根据减压那结果个数修改长度 |
| | | switch (i) { |
| | | case 1: |
| | | tableStyle.setColWidths(new int[]{650, 2000, 2000, 850, 2200, 2100, 1200}); |
| | | break; |
| | | case 2: |
| | | tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 2100, 1200, 1200, 1200}); |
| | | break; |
| | | case 3: |
| | | tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 1500, 1000, 1000, 1000, 1200}); |
| | | break; |
| | | case 4: |
| | | tableStyle.setColWidths(new int[]{650, 1200, 1200, 850, 1400, 850, 850, 850, 850, 1200}); |
| | | break; |
| | | case 5: |
| | | tableStyle.setColWidths(new int[]{650, 1100, 1100, 850, 1350, 750, 750, 750, 750, 750, 1200}); |
| | | break; |
| | | } |
| | | } |
| | | tableStyle.setWidth("10000"); |
| | | tableStyle.setAlign(TableRowAlign.CENTER); |
| | | BorderStyle borderStyle = new BorderStyle(); |
| | | borderStyle.setColor("000000"); |
| | | borderStyle.setType(XWPFTable.XWPFBorderType.THICK); |
| | | borderStyle.setSize(14); |
| | | tableStyle.setLeftBorder(borderStyle); |
| | | tableStyle.setTopBorder(borderStyle); |
| | | tableStyle.setRightBorder(borderStyle); |
| | | tableStyle.setBottomBorder(borderStyle); |
| | | tableRenderData.setTableStyle(tableStyle); |
| | | tables1.add(tableRenderData); |
| | | // for (int i = 1; i <= max; i++) { |
| | | // } |
| | | // 根据检验结果个数修改长度 |
| | | tableStyle.setColWidths(calcTableColWidths(max)); |
| | | // switch (max) { |
| | | // case 1: |
| | | // tableStyle.setColWidths(new int[]{650, 2000, 2000, 850, 2200, 2100, 1200}); |
| | | // break; |
| | | // case 2: |
| | | // tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 2100, 1200, 1200, 1200}); |
| | | // break; |
| | | // case 3: |
| | | // tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 1500, 1000, 1000, 1000, 1200}); |
| | | // break; |
| | | // case 4: |
| | | // tableStyle.setColWidths(new int[]{650, 1200, 1200, 850, 1400, 850, 850, 850, 850, 1200}); |
| | | // break; |
| | | // case 5: |
| | | // tableStyle.setColWidths(new int[]{650, 1100, 1100, 850, 1350, 750, 750, 750, 750, 750, 1200}); |
| | | // break; |
| | | // } |
| | | } |
| | | tableStyle.setWidth("10000"); |
| | | tableStyle.setAlign(TableRowAlign.CENTER); |
| | | BorderStyle borderStyle = new BorderStyle(); |
| | | borderStyle.setColor("000000"); |
| | | borderStyle.setType(XWPFTable.XWPFBorderType.THICK); |
| | | borderStyle.setSize(14); |
| | | tableStyle.setLeftBorder(borderStyle); |
| | | tableStyle.setTopBorder(borderStyle); |
| | | tableStyle.setRightBorder(borderStyle); |
| | | tableStyle.setBottomBorder(borderStyle); |
| | | tableRenderData.setTableStyle(tableStyle); |
| | | tables1.add(tableRenderData); |
| | | tables1.forEach(table -> { |
| | | Map<String, Object> tableMap = new HashMap<>(); |
| | | tableMap.put("table", table); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 计算表格列宽度 |
| | | * @param max 最大检验个数 |
| | | * @return |
| | | */ |
| | | private static int[] calcTableColWidths(int max){ |
| | | int[] colWidths = null; |
| | | switch (max) { |
| | | case 1: |
| | | colWidths = new int[]{650, 2000, 2000, 850, 2200, 2100, 1200}; |
| | | break; |
| | | case 2: |
| | | colWidths = new int[]{650, 1400, 1400, 850, 2100, 1200, 1200, 1200}; |
| | | break; |
| | | case 3: |
| | | colWidths = new int[]{650, 1400, 1400, 850, 1500, 1000, 1000, 1000, 1200}; |
| | | break; |
| | | case 4: |
| | | colWidths = new int[]{650, 1200, 1200, 850, 1400, 850, 850, 850, 850, 1200}; |
| | | break; |
| | | case 5: |
| | | colWidths = new int[]{650, 1100, 1100, 850, 1350, 750, 750, 750, 750, 750, 1200}; |
| | | break; |
| | | } |
| | | if(ObjectUtils.isNull(colWidths)){ |
| | | List<Integer> defaultColWidths = new ArrayList<>(Arrays.asList(650, 1100, 1100, 850, 1350)); |
| | | int totalWidth = 3000;//总宽度 |
| | | int byOneWidth = totalWidth/max;//每一个的宽度 |
| | | int realWidth = 0;//实际宽度 |
| | | for (int i = 0; i < max; i++) { |
| | | realWidth+=byOneWidth; |
| | | defaultColWidths.add(byOneWidth); |
| | | } |
| | | defaultColWidths.add(1200+(totalWidth-realWidth)); |
| | | return defaultColWidths.stream().mapToInt(Integer::intValue).toArray(); |
| | | } |
| | | return colWidths; |
| | | } |
| | | |
| | | /** |
| | | * 调整高度 |
| | | * @param row |
| | | * @param rowHeight |
| | |
| | | // 获取检测内容判断是否超出 |
| | | if (StringUtils.isNotBlank(dataText) && dataText.contains("@")) { |
| | | double number = 1; |
| | | double chinaLength = 0; |
| | | double englishLength = 0; |
| | | double valueLength = 0; |
| | | double chinaLength = 14; |
| | | double englishLength = 28; |
| | | double valueLength = 6; |
| | | // 根据线芯个数判断距离 |
| | | switch (max) { |
| | | case 1: |