使用Java Apache POI从只读xlsm文件读取数据 [英] Read data from read only xlsm file using Java Apache POI
问题描述
我正在尝试使用java apache poi从只读xlsm读取数据,但是当我使用XSSF工作簿时,它似乎无法访问该文件,而HSSF工作簿仅适用于xls文件.我的代码如下:
I'm trying to read data from a read only xlsm using java apache poi, but when I use XSSF workbook it doesn't seem to be able to access the file and HSSF workbooks only work for xls files. My code looks like this:
try {
FileInputStream file = new FileInputStream(new File("file.xlsm"));
System.out.println("found file");
XSSFWorkbook workbook = new XSSFWorkbook(file);
System.out.println("in workbook");
XSSFSheet sheet = workbook.getSheet("Shipments");
System.out.println("got sheet");
该代码永远不会到达工作簿中"的打印行,我不确定为什么.请帮忙!
The code never reaches the "in workbook" print line and I'm not sure why. Please help!
推荐答案
我复制了您的代码,并给出了文件的 绝对路径 ,预期的结果.
I copied your code and gave the absolute path of the file, and I was able to get the expected result.
FileInputStream file = new FileInputStream(new File("C:\\Users\\user\\Desktop\\filet.xlsm"));
System.out.println("found file");
XSSFWorkbook workbook = new XSSFWorkbook(file);
System.out.println("in workbook");
XSSFSheet sheet = workbook.getSheet("Shipments");
System.out.println("got sheet");
您的引用似乎有问题.因此,请在尝试创建文件资源时检查引用文件的方式.
It seems like a problem with your referencing. Therefore check the way you refer to the files when you try to create the file resource.
这篇关于使用Java Apache POI从只读xlsm文件读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!