An exception indicates that something is happening with your InputStream. However, if you have a file, then transfer it directly to the POI !. Using an InputStream requires buffering everything in memory that eats space. Since you do not need to do this buffering, do not do this! By avoiding this buffering, you should still fix your problem.
If you use the latest POI nightly builds, then it is very simple. Your code will look like this:
File file = new File("test.xlsx"); OPCPackage opcPackage = OPCPackage.open(file); XSSFWorkbook workbook = new XSSFWorkbook(opcPackage);
Otherwise, it is very similar:
File file = new File("test.xlsx"); OPCPackage opcPackage = OPCPackage.open(file.getAbsolutePath()); XSSFWorkbook workbook = new XSSFWorkbook(opcPackage);
If you are not sure if your file is HSSFWorkbook or XSSFWorkbook, you can use WorkbookFactory to open the corresponding file for you:
File file = new File("test.xlsx"); Workbook workbook = WorkbookFactory.create(file);
Gagravarr
source share