Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Writing to Excel with POI

Writing to Excel with POI

Writing to Excel with POI


I am trying to generate an excel file with POI Library, so far here is a piece of code, I get about 150,000 registers between 2 dates

FileInputStream fis = new FileInputStream(new File(my_template));
XSSFWorkbook workbook = new XSSFWorkbook (fis);
XSSFSheet sheet = workbook.getSheetAt(0);

FileOutputStream fos1 =new FileOutputStream(new File(path_to_report));

while (date1 <= date2 )
{ ...
row1 = sheet.createRow(ln_excel);
... (about 15 columns)

my process takes too much time,

Any hint to improve my code?

Thank in advance.

RE: Writing to Excel with POI

The only improvement I can think of is putting the flush out of the loop. How much time is is taking? Is this the code that consumes all the time or the database query is also slow?


RE: Writing to Excel with POI

Hello Dian

My query is also very slow because I make several UNIONs it takes between 30 and 40 minutes, I make JDBC connection but I think the result is not that big, The code above sometimes give me OutOfMemory Error when it is creating excel file but sometimes not.

Right now I am trying with this:

Workbook wb = new SXSSFWorkbook(500) instead of XSSFWorkbook workbook = new XSSFWorkbook (fis);

but it is said that it is only used to write, I cannot update my file this way.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close