Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Generate large excel using POI  RSS feed

 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
I got the Solution.

 
Greenhorn
Posts: 3
IntelliJ IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • 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: 3315
86
  • Mark post as helpful
  • send pies
  • 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
IntelliJ IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • 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: 3315
86
  • Mark post as helpful
  • send pies
  • 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
IntelliJ IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • 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: 3315
86
  • Mark post as helpful
  • send pies
  • 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.
 
machines help you to do more, but experience less. Experience this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!