| | |
| | | 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; |
| | |
| | | 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(); |
| | | } |
| | |
| | | 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()); |
| | | |
| | | } |
| | | } |
| | | //删除起始行 |
| | |
| | | } |
| | | copyTableCell(cell1, cell2); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |