| | |
| | | |
| | | private final String indexKey = "~index~"; |
| | | |
| | | public DynamicTableRenderPolicy(String replaceKey) { |
| | | public DynamicTableRenderPolicy(String replaceKey) { |
| | | this.replaceKey = replaceKey; |
| | | |
| | | } |
| | | |
| | | private List<MetaTemplate> metaTemplateList; |
| | | |
| | | |
| | | |
| | | @Override |
| | |
| | | if (i == 0) { |
| | | row = fieldRow; |
| | | } else { |
| | | int fieldRowIndex = xwpfTable.getRows().indexOf(fieldRow); |
| | | //创建一行在fieldRowIndex下面 |
| | | row = xwpfTable.insertNewTableRow(xwpfTable.getRows().size()); |
| | | row = xwpfTable.insertNewTableRow(fieldRowIndex + i); |
| | | PrintPoiUtil.copyTableRow(row, fieldRow); |
| | | } |
| | | //遍历字段每个字段创建一个单元格 |
| | |
| | | XWPFParagraph xwpfParagraph = cell.addParagraph(); |
| | | int index = cell.getParagraphs().indexOf(xwpfParagraph); |
| | | PrintPoiUtil.copyParagraph(xwpfParagraph, cell.getParagraphs().get(0)); |
| | | //设置段落文字对齐方式 |
| | | xwpfParagraph.setAlignment(cell.getParagraphs().get(0).getAlignment()); |
| | | //删除所有的run |
| | | for (int k = xwpfParagraph.getRuns().size() - 1; k >= 0; k--) { |
| | | xwpfParagraph.removeRun(k); |
| | |
| | | if (value == null) { |
| | | value = ""; |
| | | } |
| | | // if ("lx_flow_opinion".equals(this.replaceKey) && "opinion".equals(fieldNames[j])) { |
| | | // //将流程节点处理人加到意见栏中 |
| | | // value = "[" + map.get("actual_person") + "] " + value; |
| | | // } |
| | | xwpfRun.setText(value.toString(), 0); |
| | | if ("lx_flow_opinion".equals(this.replaceKey) && "opinion".equals(fieldNames[j]) && !StringUtils.isEmpty(map.get("sign_attachment_uuid"))) { |
| | | //意见框 插入签名图片到单元格右下角位置 |
| | | xwpfParagraph = cell.addParagraph(); |
| | | xwpfParagraph.setAlignment(ParagraphAlignment.RIGHT); |
| | | XWPFRun run = xwpfParagraph.createRun(); |
| | | String signAttachmentBase64 = map.get("sign_attachment_uuid").toString(); |
| | | //将base64转换字节流 |
| | | byte[] bytes = Base64.getDecoder().decode(signAttachmentBase64.split(",")[1]); |
| | | //将字节流转换为输入流 |
| | | InputStream inputStream = new ByteArrayInputStream(bytes); |
| | | try { |
| | | //换行插入图片 |
| | | run.addPicture(inputStream, XWPFDocument.PICTURE_TYPE_PNG, "sign.png", Units.toEMU(50), Units.toEMU(20)); |
| | | inputStream.close(); |
| | | } catch (InvalidFormatException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | if ("lx_flow_opinion".equals(this.replaceKey) && "opinion".equals(fieldNames[j])) { |
| | | if (!StringUtils.isEmpty(map.get("sign_attachment_uuid"))) { |
| | | //意见框 插入签名图片到单元格右下角位置 |
| | | xwpfParagraph = cell.addParagraph(); |
| | | xwpfParagraph.setAlignment(ParagraphAlignment.RIGHT); |
| | | XWPFRun run = xwpfParagraph.createRun(); |
| | | String signAttachmentBase64 = map.get("sign_attachment_uuid").toString(); |
| | | //将base64转换字节流 |
| | | byte[] bytes = Base64.getDecoder().decode(signAttachmentBase64.split(",")[1]); |
| | | //将字节流转换为输入流 |
| | | InputStream inputStream = new ByteArrayInputStream(bytes); |
| | | try { |
| | | //换行插入图片 |
| | | run.addPicture(inputStream, XWPFDocument.PICTURE_TYPE_PNG, "sign.png", Units.toEMU(50), Units.toEMU(20)); |
| | | run.addBreak(); |
| | | run.setText("" + map.get("deal_time").toString().substring(0, 16)); |
| | | inputStream.close(); |
| | | } catch (InvalidFormatException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } else { |
| | | xwpfParagraph = cell.addParagraph(); |
| | | xwpfParagraph.setAlignment(ParagraphAlignment.RIGHT); |
| | | XWPFRun run = xwpfParagraph.createRun(); |
| | | run.setText((String) map.get("actual_person")); |
| | | run.addBreak(); |
| | | run.setText(map.get("deal_time").toString().substring(0, 16)); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |