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,

Full Threads Newest First

Showing messages 1 through 5 of 5.

  • File increase size problem
    2007-08-31 00:06:37  Subhash1027 [View]

    Hi Raj,
    I am also facing the same problem. Also when the open the file(double sized file), it is getting opened in repaired mode. Did you find any fix for this? If so, please let me know.
    Thanks in advance.

    Thanks & Regards,
  • File increase size problem
    2008-01-14 07:05:54  Hifzur [View]

    Hi Raj,
    We have a similar project requirement in which I have to use an existing template & write the data into excel file.
    But I am new to POI Api.
    Could you share the code snippet.

    • File increase size problem
      2008-02-25 22:47:29  VJeba [View]


      I am new to POI, and in my current project I need to export a SWT Table data into an .xls template.

      Please give me a sample code.

  • File increase size problem
    2008-06-11 07:16:59  anil47 [View]

    Hi Raj,
    I am able to read and write general values from excel file by using POI But i am unable to read macros in excel file. So,please tell me the code to read macros in excel values
    Thanks in Advance,

  • How to read images and macros from excel sheet by using poi
    2008-06-13 05:22:06  anil47 [View]

    can you please tell me how to read images and macros from excel sheet by using poi. Please,send me the program to my mail id.

    Thanks in Advance