小编Fei*_*Fei的帖子

Java Word Appache POI - 垂直对齐单元格内容/删除文本后的空格

我的表格如下所示: Word POI 表

正如您所看到的,文本与单元格的顶部对齐。我想让它垂直居中或与单元格底部对齐。我试图实现它,cell.setVerticalAlignment(XWPFVertAlign.CENTER);但它不会改变任何东西。我可以通过 table.setCellMargin() 为单元格添加边距。它在单元格顶部添加了边距,但文本下方的空白区域使单元格太大。也许有办法让单元格宽度适合文本高度?我的预期结果如下所示: 预期结果

这是我的代码的一部分:`

XWPFTable table = document.createTable();
CTTblWidth tableIndentation = table.getCTTbl().getTblPr().addNewTblInd();
tableIndentation.setW(BigInteger.valueOf(720));
tableIndentation.setType(STTblWidth.DXA);

XWPFTableRow tableRowOne = table.getRow(0);
XWPFParagraph paragraphTable = tableRowOne.getCell(0).addParagraph();
table.setCellMargins(0, 50, 0, 0);
XWPFRun runT = paragraphTable.createRun();

runT.setBold(true);
runT.setColor("ffffff");
runT.setText("REFERENCE ACTIVITIES PROVIDED: " + String.valueOf(def.format(c.getEarnedSum())) + " POINTS EARNED");
runT = tableRowOne.addNewTableCell().addParagraph().createRun();
runT = tableRowOne.addNewTableCell().addParagraph().createRun();

tableRowOne.getCell(0).getCTTc().addNewTcPr().addNewShd().setFill("8dc63f");
tableRowOne.getCell(1).getCTTc().addNewTcPr().addNewShd().setFill("8dc63f");
tableRowOne.getCell(2).getCTTc().addNewTcPr().addNewShd().setFill("8dc63f");
tableRowOne.getCell(0).removeParagraph(0);
tableRowOne.getCell(1).removeParagraph(0);
tableRowOne.getCell(2).removeParagraph(0);`
Run Code Online (Sandbox Code Playgroud)

java ms-word apache-poi

2
推荐指数
1
解决办法
2167
查看次数

标签 统计

apache-poi ×1

java ×1

ms-word ×1