src/main/java/com/product/print/util/DynamicTableRenderPolicy.java
@@ -1,5 +1,6 @@
package com.product.print.util;
import cn.hutool.core.io.IoUtil;
import com.deepoove.poi.exception.RenderException;
import com.deepoove.poi.render.RenderContext;
import com.deepoove.poi.template.run.RunTemplate;
@@ -8,12 +9,18 @@
import com.product.core.exception.BaseException;
import com.product.print.config.CmnCode;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.util.Units;
import org.apache.poi.xwpf.usermodel.*;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
@@ -133,9 +140,7 @@
            XWPFTableCell cell;
            //判断row中第j个单元格是否存在
            if (row.getTableCells().size() > j) {
               cell = row.getTableCells().get(j);
               //清空单元格内容
               cell.removeParagraph(0);
               cell = row.getCell(j);
            } else {
               cell = row.createCell();
            }
@@ -149,8 +154,41 @@
            if (value == null) {
               value = "";
            }
            //设置单元格的值
            String text = cell.getText();
            //删除单元格中的旧内容
            if (!StringUtils.isEmpty(text)) {
               List<XWPFParagraph> paragraphs = cell.getParagraphs();
               if (paragraphs.size() > 1) {
                  cell.removeParagraph(1);
               }
               List<XWPFRun> runs = paragraphs.get(0).getRuns();
               //清空文字
               for (int k = 0; k < runs.size(); k++) {
                  runs.get(k).setText("", 0);
               }
            }
            cell.setText(value.toString());
            if ("lx_flow_opinion".equals(this.replaceKey) && "opinion".equals(fieldNames[j]) && !StringUtils.isEmpty(map.get("sign_attachment_uuid"))) {
               //意见框 插入签名图片到单元格右下角位置
               XWPFParagraph 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();
               }
            }
         }
      }
      //删除起始行
@@ -248,6 +286,7 @@
         }
         copyTableCell(cell1, cell2);
      }
   }
   /**