gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 11:32:52 26 4
gpt4 key购买 nike

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com