0

I'm not able to read xlsm file using Apache POI. I'm getting the error java.lang.StringIndexOutOfBoundsException: String index out of range:-1.

My program looks like:

FileInputStream file=new FileInputStream(new File(path));
out.print("aaaaaa");
Workbook workbook=null;out.print("1111111");
workbook=WorkbookFactory.create(file);
out.print("222222");

The 22222 never prints and I get the exception. The aaaaaaa and 111111 print.

I have downloaded all the latest jars as per Error while reading an xlsm file using POI Framework in Java I have tried with XSSFWorkbook. I have tried passing File object instead of FileInputStream as seen in some SO answers.

It's a read only xlsm My Java version 1.7.

The program worked fine when i tried with a new xlsm file, also worked fine with other readonly xlsm file(also protected, but having different template).

Could it mean that maybe there is some issue with my particular xlsm file template? Or am I missing anything else? Can someone help in fixing this?

UPDATE: I put my code block in a small java class and directly copied to server into a folder outside my web application folder and it works fine there... Could it be svn related issue?

schan
  • 51
  • 6

1 Answers1

0

My program is working fine now. The problem was that in my test server there were several versions of the poi, poi-ooxml and poi-ooxml-schemas jars lying scattered across several folders. So I removed all of them, added only the latest version jars(3.17) in a single path, added to classpath, added the jars dependecies too(just in case) and all is well. Hope this helps someone.

schan
  • 51
  • 6