java - 替代 Apache POI 中已弃用的 .getCell 来获取该列的行内容

标签 java apache-poi

FileInputStream file = new FileInputStream(new File("/Users/srivaans/Desktop/Trytoread.xlsx"));
        XSSFWorkbook workbook = new XSSFWorkbook(file);
            XSSFSheet sheet = workbook.getSheetAt(0);

        int totalnoofrows = sheet.getPhysicalNumberOfRows();
        int totalnoofcell = sheet.getRow(0).getPhysicalNumberOfCells();

        System.out.println("No. of rows: " +totalnoofrows);
            System.out.println("No. of cells= " +totalnoofcell);
        for (int row = 0; row<totalnoofrows; row++){
            for( int cell =0;cell<totalnoofcell; cell++){
                System.out.print(sheet.getCell(cell, row).getContents() + "\t");
            }

        }

这是我的代码。我必须获取以下列的行数据。 .getCell()方法仅适用于.xls(HSSF)类型的文件,不适用于.xlsx(XSSF)类型的文件。

有人可以帮我做同样的事情吗? 提前致谢!

最佳答案

    sheet.getRow(int rownum).getCell(int cellnum).getXXX();

其中 XXX 是您需要的任何内容。一切都在java文档中。有 getStringCellValue()、getBooleanCellValue()、样式内容、公式内容。

还有。你可能应该做一个谷歌,特别是搜索堆栈溢出。这是相关的:

How do I read the cell contents using apache poi for xlsx type of excel file

关于java - 替代 Apache POI 中已弃用的 .getCell 来获取该列的行内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49170094/

相关文章:

java - 具有属性和文本内容的复杂类型的 JAXB 反编码

java - 在Excel中创建下拉列表

java - 如何使用 SXSSF 写入现有文件?

java - 如何使用 apache poi selenium webdriver java 将 excel 中的两个或多个值与 li 中的值进行比较并报告同一 excel 中的通过或失败

java - 初始化节点错误

java - Google Maps Android API 如何检查是否达到配额限制?

java - 为什么从 XAResource 抛出 XAException 仍然不允许事务提交成功?

java for循环以 "true"作为停止条件?

apache - 在使用 apache poi 替换 Microsoft 2007 (HWPFDocument) 文档的内容时需要帮助

java - 有没有可以与java集成的语言可以有效地读取大型XLSX文件?