首页 文章

具有双倍高度的Apache POI XWPFTableRow绘图

提问于
浏览
0

我试图使用Apache POI XWPF在word文档中绘制一个表 . 但是这张 table 正在绘制像这样的双高度行
enter image description here

这是我的来源

XWPFTable table = document.createTable(5, 1);
            for (Test t : tests) {
                    XWPFTableRow row = table.getRow(k - 1);
                    XWPFTableCell cell = row.getCell(0);
                    XWPFParagraph ansParagraph = new XWPFParagraph(cell.getCTTc().insertNewP(0), cell);
                    XWPFRun ansRun = ansParagraph.createRun();
                    ansRun.setText(k + ") ");
                    cell.addParagraph(ansParagraph);
                    k++;
                }

怎么能减少行的高度 .

1 回答

  • 1

    在Apache POI XWPF中创建表时,每个单元格中都有一个空白段落 . 您正在获得双倍高度的行,因为您还在其中添加了一个段落 .

    所以你更换线

    XWPFParagraph ansParagraph = new XWPFParagraph(cell.getCTTc().insertNewP(0), cell);
    

    XWPFParagraph ansParagraph = cell.getParagraphs().get(0);
    

    并删除该行

    cell.addParagraph(ansParagraph);
    

    然后它会工作正常 .

相关问题