[英]How to read the Excel (xlsx) Header column Data Type using apache POI 4.X
[英]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.