• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generate large excel using POI

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am using the following code to generate excel.

http://www.docjar.com/html/api/org/apache/poi/xssf/usermodel/examples/BigGridDemo.java.html
OR
http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/BigGridDemo.java

How to use it for multiple sheets?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does this help? http://poi.apache.org/spreadsheet/quick-guide.html#NewSheet

BTW, the link you posted is broken.
 
Jwala Prakash
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Does this help? http://poi.apache.org/spreadsheet/quick-guide.html#NewSheet

BTW, the link you posted is broken.




Thanks for reply.
I modified the link.

It is "http://www.docjar.com/html/api/org/apache/poi/xssf/usermodel/examples/BigGridDemo.java.html"
 
Jwala Prakash
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got the Solution.

 
Greenhorn
Posts: 3
Mac OS X IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just want to point out a small bug in the above code:


Having "sheets" File:s being temp files inhibited med to File.delete() those due to "zip" not being closed. Adding the "zip.close()" sovled this problem.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the ranch.

Thanks for pointing out that bug it may help someone else in the future.
To improve that code further wherever streams are used they should be wrapped in a try-catch clause with the close() done in a finally clause to ensure it is always called.
 
Tommy Svensson
Greenhorn
Posts: 3
Mac OS X IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Absolutely! I didn't want to seem to picky :-)

My version of the code looks like this:



 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Absolutely! I didn't want to seem to picky :-)


Don't worry about correcting errors, that's how we all learn to be better programmers. Just remember to be nice when doing so.

BTW In your code, zos.close() could throw an exception which would mean zip.close() was never called.
You don't show it but I assume you have also added try-catch-finally clauses to the input streams.

 
Tommy Svensson
Greenhorn
Posts: 3
Mac OS X IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

BTW In your code, zos.close() could throw an exception which would mean zip.close() was never called.



Oh (beeep)! You are of course right, and no, you assumed wrong! But I've fixed it and it now it looks like this:



I let all IOExceptions be thrown uppward where they eventually will be handled and logged. I don't think it is a good idea to swallow them on failed close() just because you are done for the moment since if this happens there is obvously something wrong.

One interesting (and non relevant :-)) question here is if both close() statements throw an IOException, which will be delivered ? I guess the second one.
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

One interesting (and non relevant :-)) question here is if both close() statements throw an IOException, which will be delivered ? I guess the second one.


You can read the exact details in the JLS http://docs.oracle.com/javase/specs/jls/se7/html/jls-14.html#jls-14.20.2
But yes you are correct, if an exception is thrown in a finally block then any pre-existing exception is discarded.
 
Not so fast naughty spawn! I want you to know about
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic