You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by swatik_2000 <sw...@yahoo.co.uk> on 2011/08/31 12:21:24 UTC
Existing xls file containing images corrupted beyond repair when
modifying with POI.
Hello,
This is the first time I have been working with an excel file containing
images. I have used POI 3.8 beta 2 for xls and xlsx file manipulations
rather effectively so far. However, the current problem has me stumped.
I have downloaded an xls file (Excel 97-2003) for tax returns. This file is
password protected and contains macros and a few images apart from empty
cells that need to be filled for tax. I cannot makes any changes to this
file since the format in which data needs to be presented is fixed.
I have been trying to use POI to fill in the tax values, however, when I try
opening the file, I get an excel error message saying that the file is
corrupted beyond repair. When the file opens up, the cell that I modified,
shows up with the right value, but the images, the macros and all formatting
is lost.
Based on what google threw up, I am assuming that the problem occurs because
of the images in the file. I tried manipulating another similar file minus
the images and got that working. I have seen people report similar errors,
but on builds as old as the POI 3.0 release. The code I have written is
pretty straightforward. I used the byteArrayOutputStream based on something
I read on google, but honestly, I don't fully understand how that works.
ByteArrayOutputStream bos = new ByteArrayOutputStream();
FileOutputStream fos = new
FileOutputStream("C:\\Swati\\sample.xls");
try {
String fiscalYr = request.getParameter("fiscalYear");
String fiscalMon = request.getParameter("fiscalMonth");
FileInputStream inputExcelStream = new FileInputStream(new
File("C:\\Swati\\Reports\\ACES-EFiling-ER1.xls"));
HSSFWorkbook wb = new HSSFWorkbook(inputExcelStream);
List lop = wb.getAllPictures();
System.out.println(lop);
System.out.println(lop.size());
HSSFSheet er1Sheet = wb.getSheetAt(0);
er1Sheet.getRow(6).getCell(6).setCellValue("AQBCDE1234DXF001");
wb.write(bos);
bos.writeTo(fos);
inputExcelStream.close();
bos.close();
fos.close();
} catch (Exception e){
System.out.println(e.getMessage());
} finally {
bos.close();
fos.close();
}
Any help would be greatly appreciated.
Thanks and Regards,
Swati
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Existing-xls-file-containing-images-corrupted-beyond-repair-when-modifying-with-POI-tp4753633p4753633.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org