Apache POI - output excel file size gets doubled
807605Aug 17 2007 — edited Aug 17 2007Hi,
Greetings!! I am using Apache POI package for a Java application to read and write excel files. I am facing one specific problem.
I have a excel template which contains complex macros, images and complex formatting. I used HSSFWorkbook to read the input template file and filled in data in the template, and created the output file using FileOutputStream. The output file is created with all the required data and the formatting remains same and the output file looks just like the template file with all formatting and the required data. But the problem is, my input template file size is 831KB. But the output file size is 1919KB. The output file size is getting doubled. Is there any solution to fix this issue?
Another thing I tried is, If I open the bigger output file (1919KB) in MS-Excel and saved the file manually, then the file size reduces to normal size (850KB). I couldn't understand why the size increased tremendously if the file contains macros.
I checked the same program with an input file which does NOT contain any macros. The output size is normal and it did not increased.
I have given the code below:
HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(templateFileName), true);
HSSFSheet sheet = wb.getSheet("Adjustment Request");
HSSFRow row = sheet.getRow(10);
HSSFCell cell = row.getCell((short)3);
if (cell == null) {
cell = row.createCell((short)3);
}
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue("This is test");
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream(destFileName);
wb.write(fileOut);
fileOut.close();
I have tried jXLS package also. Since it uses POI as underlying framework, the problem remains same. The output file created by jXLS is also double the size of input file.
I also tried to use JExcel (jxl) package but it could NOT even read the input file with complex macros.
Please give me some suggestions to resolve the issue.
Thanks and Regards,
Raj