Apache POI XWPFTableRow remove column Word



我正在尝试在 Java 中创建一个函数,该函数从标题为"严重"的 Word 表中删除一列。请在下面找到此功能。当我运行代码时,没有任何反应。有没有人在使用removeCell功能时遇到任何问题?

public static void remCells(XWPFTable table) {
    for (int rowIndex = 0; rowIndex < table.getNumberOfRows(); rowIndex++) {
        XWPFTableRow row = table.getRow(rowIndex);
        for (int colIndex = 0; colIndex < row.getTableCells().size()-1; colIndex++) {
            XWPFTableCell cell = row.getCell(colIndex);
            if(table.getRow(5).getCell(colIndex).getText().equals("Serious")) {
                row.removeCell(colIndex);
            }
        }
    }
}

在这里找到解决方案:https://www.codota.com/code/java/methods/org.apache.poi.xwpf.usermodel.XWPFTableRow/removeCell

我们必须做

row.getCtRow().removeTc(colIndex);

以前

row.removeCell(colIndex);

最新更新