簡體   English   中英

如何使用apache poi讀取xlsx類型的excel文件的單元格內容?

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

似乎我有點不高興,我閱讀了有關使用hssf讀取xls文件的各種主題,但是我似乎找不到很好的xssf教程,因為它們的語句不同,所以這真的很難。 我的代碼應該讀取第2行,第2列,但出現“類型XSSFComment的getContents()未定義”錯誤

我的代碼是這樣的:

import java.io.FileOutputStream; 
import java.io.IOException; 
import java.io.InputStream; 

import org.apache.poi.xssf.usermodel.XSSFCell; 
import org.apache.poi.xssf.usermodel.XSSFRow; 
import org.apache.poi.xssf.usermodel.XSSFSheet; 
import org.apache.poi.xssf.usermodel.XSSFWorkbook; 

public class parsing{ 

public static void main(String[] args) throws IOException { 
InputStream ExcelFileToRead = new FileInputStream("C:/test.xlsx"); 
XSSFWorkbook wb = new XSSFWorkbook(ExcelFileToRead); 
XSSFSheet sh = wb.getSheetAt(0); 
System.out.println(sh.getCellComment(1,1).getContents()); 
} 
}

錯誤:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    The method getContents() is undefined for the type XSSFComment
    at parsing.main(parsing.java:18)

根據最新Apache POI的文檔,類XSSFComment根本沒有getContents()方法。

而是嘗試使用getString()方法獲取Comment內容。 查看Apache POI XSSFComment的文檔

還要查看Apache PoI快速指南中提供的Cell Comment示例。

代替使用getContents()方法,使用getString()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM