The following code: public static void main(String[] aArgs) throws IOException { InputStream in = PoiTest.class.getResourceAsStream("KW_d.xls"); HSSFWorkbook workBook = new HSSFWorkbook(in); int nbSheets = workBook.getNumberOfSheets(); System.out.println("The Excel document has "+nbSheets+" sheet"); System.out.println("The names are:"); for( int i=0; i<nbSheets; ++i) { System.out.println( ""+i+". "+workBook.getSheetName(i)); } OutputStream out = new FileOutputStream ("C:/temp/ExcelTest.xls"); workBook.write( out ); out.close(); } Throws the following exception: java.lang.ArrayIndexOutOfBoundsException at org.apache.poi.util.StringUtil.putUncompressedUnicode (StringUtil.java:175) at org.apache.poi.hssf.record.UnicodeString.serialize (UnicodeString.java:299) at org.apache.poi.hssf.record.Record.serialize(Record.java:168) at org.apache.poi.hssf.record.SSTRecord.serialize(SSTRecord.java:541) at org.apache.poi.hssf.model.Workbook.serialize(Workbook.java:664) at org.apache.poi.hssf.usermodel.HSSFWorkbook.getBytes (HSSFWorkbook.java:505) at org.apache.poi.hssf.usermodel.HSSFWorkbook.write (HSSFWorkbook.java:465) at com.consultens.poi.PoiTest.main(PoiTest.java:72) Exception in thread "main"
Do you need additional information to tackle this bug? All our corporate excelsheets I try to use ends in this or a simillary error. Perhaps I'm using a wrong excel version, which excel version should be used with POI? I hope you can soon fix this bug, because otherwise we have to look for another solution for our excel sheets. Although I would like to use a 100% java solution like POI. Thanks. Dieter
They actual excel file causing the crash would be handy.
Created attachment 1852 [details] Excel Sheet which reproduces the exception
I'll look at it. You must use Excel 97 or newer. This file has =Embed(blabla) functions in it. I've never seen such a thing. Secondly it has embedded graphics. My money is on the =Embed(blabla). Regardless I'll look at it probably this weekend. This is 2.0 stuff. (we don't claim to support embedded graphics or formulas)
Hi Andy, thanks for your answer. Which version of Excel is now exactly supported? I don't think, that the Image is the problem. Probably the =Embed(blabla). I didn't created the excel sheets, so I don't know what the =Embed(blabla) stuff is at all. Do you know how they can be removed?
I said Excel 97+. Delete the =Embed(xx) (and probably the image with it) and paste the image directly.
Created attachment 1857 [details] Excelsheet without the picture
I removed the picture from the excel sheet and saved the file with Excel 2000. The same error still occures.
Looks like it might be something to do with the characterset. Need to investigate more.
is this possibly more RTF problems? (rich text)
Nope, rtf's generally cause problems with reading. a unicode problem i think.
so are you looking at this or do you want me to? I'm about to commit changes to the record generator to make it autodefine tests.
Andy was right. It's an rich text problem. Deleting cell F8 fixed the problem. I didn't spot is straight away because it's doesn't look obviously formatted. We don't support this one yet. I think it was planned for 2.0 but maybe some kind sole will post a workaround that we may be able to put in 1.5.1.
Hi Glen, how can I see which cells are wrong formatted? I see no differences from this cell to the other cells?
I had a hard time spotting it too. I only discovered it through debugging the workbook. It doesn't appear formatted to me but it's definately being stored as rich text.