Posts Tagged ‘lost document summary information’

Apache POI Lost Document Summary Information

April 24, 2013

Being working on Intranet projects, lot of my work runs around exporting records into excel and pdf files. For excel exporting mostly we use Apache POI, the awesome tool to deal with Office files. Recently I came around a problem, where after generating the excel file, while trying to open it , it gave error and the log file states : “Lost document summary information.”.

On inspecting my code, I came across these lines :

byte[] b = report.getBytes();

I was using this byte array to flush to the output. In fact this was causing the problem. On detail research I found out that getBytes() method will not give the complete bytes and some of the bytes are lost. Unfortunately those lost bytes are of the summary information, which was causing Excel to throw error. As a workaround, you can do like this, which solved my problem :

ByteArrayOutputStream bos = new ByteArrayOutputStream();
report.write(bos);
byte[] b = bos.toByteArray();

That’s all for now. Happy Coding. 🙂


%d bloggers like this: