许鹏程
2023-08-04 a26fbe729817216bcf53b13945fe6300caa89997
src/main/java/com/product/print/util/DynamicTableRenderPolicy.java
@@ -9,6 +9,7 @@
import com.product.print.config.CmnCode;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xwpf.usermodel.*;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -133,9 +134,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 +148,21 @@
            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());
         }
      }
      //删除起始行
@@ -248,6 +260,7 @@
         }
         copyTableCell(cell1, cell2);
      }
   }
   /**