首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用POI读取excel文件

使用POI读取excel文件
EN

Stack Overflow用户
提问于 2015-03-13 15:24:18
回答 2查看 57关注 0票数 0

在从excel文件中读取数据时,我们可以使用

no_of_rows = sheet.getPhysicalNumberOfRows();

来获取包含数据的行数。有没有一种方法可以得到在工作表的第一列中有数据的行数?

EN

Stack Overflow用户

发布于 2015-03-13 16:07:54

让每一列都有不同的行号?

int rows;//行数= sheet.getPhysicalNumberOfRows();

代码语言:javascript
运行
复制
int cols = 0; // No of columns
int tmp = 0;
for (int i = 0; i < rows; i++) {
    row = sheet.getRow(i);
    if (row != null) {
        tmp = sheet.getRow(i).getPhysicalNumberOfCells();
        if (tmp > cols) {
            cols = tmp;
        }
    }
}

if (cols == 23) {
    row = sheet.getRow(0);
    if ("I.D.Number".equals(row.getCell(0).toString())) {
        if ("Name".equals(row.getCell(1).toString())) {
            if ("Surname".equals(row.getCell(2).toString())) {
                                          applicaple = true;
                                                                                            }
                                                                                        }

                }

}


Iterator rowsExcel = sheet.rowIterator();

XSSFRow row2 = null;
if (uygunluk == true) {
    while (rowsExcel.hasNext()) {

        row2 = (XSSFRow) rowsExcel.next();
        if (row2.getRowNum() != 0) {
             if (fmt.formatCellValue(row2.getCell(0)) == null || (fmt.formatCellValue(row2.getCell(0)).trim().equalsIgnoreCase(""))) {
               System.out.print.ln("warn!!");
                return;
            } else if (fmt.formatCellValue(row2.getCell(0)) != null || !(fmt.formatCellValue(row2.getCell(0)).trim().equalsIgnoreCase(""))) {
                idInfo = fmt.formatCellValue(row2.getCell(0);
            }
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29026852

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档