简体   繁体   English

word2003中如何使用POI获取表格信息?

[英]How do I get table information in word2003 using POI?

I try to get the width of each cell and then calculate their greatest common divisor to get the colspan of each cell, but how do I get the cell Rowspan?我尝试获取每个单元格的宽度,然后计算它们的最大公约数以获取每个单元格的 colspan,但是如何获取单元格 Rowspan? I tried using the method TableRow.getRowHeight(), but no matter what the table looks like, it's always going to be 0. I am trying to use this method to convert to HTML, if you have a better way to convert complex tables to HTML, please help me, thanks!我尝试使用 TableRow.getRowHeight() 方法,但无论表格看起来如何,它始终为 0。我正在尝试使用此方法转换为 HTML,如果您有更好的方法将复杂表格转换为HTML,请帮助我,谢谢!

public static Integer getRowspan(TableCell cell, int rowNum, int colNum, Table table) {
    int rowSpan = 0;
    if (cell.isVerticallyMerged()) {
        if (cell.isFirstVerticallyMerged()) {
            for (int i = rowNum + 1; i < table.numRows(); i++) {
                TableCell tableCell = table.getRow(i).getCell(colNum);
                if (tableCell.isFirstVerticallyMerged() || !tableCell.isVerticallyMerged()) {
                    rowSpan = i - rowNum;
                    break;
                } else if (i == table.numRows() - 1) {
                    rowSpan = i - rowNum + 1;
                }
            }
        }
    }
    return rowSpan;
}


public static Integer getColspan(TableCell cell, int rowNum, int colNum, Table table) {
    int colSpan = 0;
    if (cell.isMerged()) {
        if (cell.isFirstMerged()) {
            for (int i = colNum + 1; i < table.numRows(); i++) {
                TableCell tableCell = table.getRow(rowNum).getCell(i);
                if (tableCell.isFirstMerged() || !tableCell.isMerged()) {
                    colSpan = i - colNum;
                    break;
                } else if (i == table.numRows() - 1) {
                    colSpan = i - colNum + 1;
                }
            }
        }
    }
    return colSpan;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM