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 file a proper path and it worked.
My version:
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");
I think it has something to do with your pathing, or the file itself.