Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Converting Excel spread sheet generated at runtime to a zip file

 
Vishal Nadikudi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a problem in on of our applications, we are creating a HTML file that happens to be readable by Excel and now I have to compress the same to a zip file, below is the source code.

try {

DokumentSession dokumentSession = null;
byte[] resultBytes = null;
try {
dokumentSession = (DokumentSession) IPAContextHelper.getIPAContext().lookup(DokumentSession.class.getName());
} catch (NamingException e) {
LocalSystem.logError(e.getMessage());
e.printStackTrace();
}

// result bytes which gets the tagged html formatted data

resultBytes = dokumentSession.getXlsZuAuftrag(ts);
if (resultBytes != null && resultBytes.length > 0) {
// Wir lassen das XLS anzeigen
response.setContentType("application/vnd.ms-excel");
// byte Array wird in ein OutputStream geschrieben
ServletOutputStream out = response.getOutputStream();
out.write(resultBytes);
out.flush();
out.close();
}

Is there any way I can generate a zip out of this file, as the documents run huge, that is why we are planning to compress the same and give it to the user.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See java.util.zip.GZIPOutputStream.
 
Vishal Nadikudi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:See java.util.zip.GZIPOutputStream.


Hi,

Thanks for posting the api details, I already had a look at ZipOutputStream too, is it possible for you to provide me any small sample code which I can check for. Another information is, we are trying to do this change as the excel sheets generated are coming as too huge(> 50 MB) so if we can compress(zip) the file and give it back, it would possible to reduce the size of the file and also which could increase the portability.

Any help would be appreciated
 
fred rosenberger
lowercase baba
Bartender
Posts: 12127
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vishal Nadikudi wrote:is it possible for you to provide me any small sample code

That's not how we generally do things here. We strive to help you learn to do it yourself. Why don't you give it a try, and then if you have problems come back here. You can say "I tried this, expected that, but got something else. Any tips on where I went wrong?"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic