This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Converting Excel spread sheet generated at runtime to a zip file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Converting Excel spread sheet generated at runtime to a zip file" Watch "Converting Excel spread sheet generated at runtime to a zip file" New topic
Author

Converting Excel spread sheet generated at runtime to a zip file

Vishal Nadikudi
Greenhorn

Joined: Feb 09, 2010
Posts: 3
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.


Vishal
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41144
    
  45
See java.util.zip.GZIPOutputStream.


Ping & DNS - my free Android networking tools app
Vishal Nadikudi
Greenhorn

Joined: Feb 09, 2010
Posts: 3
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

Joined: Oct 02, 2003
Posts: 11168
    
  16

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?"

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting Excel spread sheet generated at runtime to a zip file
 
Similar Threads
Zip Directory Recursively
zip file does not contain any text file ??
Compress .zip using Java
Creation of .zip file???
ZipOutputStream