Reading and Writing Excel Files with POI
Subject:   File increase size problem
Date:   2007-08-17 04:59:15
From:   raj7711
Response to: File increase size problem


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 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.setCellValue("This is test");
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream(destFileName);

Thanks and Regards,

1 to 4 of 4
1 to 4 of 4