poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Shumway" <Andrew.Shum...@issinc.com>
Subject RE: Launch Excel and load memory resident HSSFWorkbook
Date Mon, 15 May 2006 21:36:07 GMT

Steaming the HSSFWorkbook out to the web client after changing the mime type
works for servlet type applications.

It's the Swing client that I'm having difficulty with.  Sorry for not
mentioning that in the original post.

--andrew shumway

-----Original Message-----
From: Sumit_Machwe@external.mckinsey.com
[mailto:Sumit_Machwe@external.mckinsey.com] 
Sent: Monday, May 15, 2006 3:26 PM
To: POI Users List
Subject: Re: Launch Excel and load memory resident HSSFWorkbook

Andrew,
        Following code snippet might be helpful... what we are doing here 
is that we are streaming the BLOB object from the database and setting it 
in the http response. In your case, you can simply use the HSSFWorkBook's 
"write" method along with the POIFSFileSystem to do the streaming. 

http://jakarta.apache.org/poi/apidocs/org/apache/poi/hssf/usermodel/HSSFWork
book.html#write(java.io.OutputStream)

remember that in each of these cases, the end user will see a window's 
dialogbox asking the user to either save / open / cancel / help options. 
If the user opts for "open" then Ms-Excel will be launched and your excel 
opened.

{
        String mimeType = "";
        mimeType = "Application/vnd.ms-excel";
 
response.setHeader("Content-Disposition","attachment;filename="+fileName+".x
ls");
 
        response.setContentType(mimeType);
        servOut = response.getOutputStream();

        InputStream in = dataBlob.getBinaryStream();
        long len = dataBlob.length();
        writeBuffer = dataBlob.getBytes(1,(int)len);
        int numRead = 0;
        int bufLength = in.read(readBuffer);

        while(bufLength != -1)
        {
                System.arraycopy(readBuffer, 0, writeBuffer, numRead, 
bufLength);
                servOut.write(writeBuffer, numRead, bufLength);
                numRead += bufLength ;
                bufLength = in.read(readBuffer);
        }
 
        in.close();
        servOut.flush();
        servOut.close();
}

I hope this is what you are looking for... 

Regards,
Sumit Machwe




"Andrew Shumway" <Andrew.Shumway@issinc.com> 
05/15/2006 04:25 PM
Please respond to
"POI Users List" <poi-user@jakarta.apache.org>


To
"'POI Users List'" <poi-user@jakarta.apache.org>
cc

Subject
Launch Excel and load memory resident HSSFWorkbook






Hello

I have an HSSFWorkbook object that is created within my application.  I 
now
want to launch Excel and display this Workbook so that the user can view,
update and possibly save.

I've been searching thru the FAQ and JavaDocs but I don't see a hook for
this. If I have to I can create a temp file but I'd rather not as it leads
to cleanup issues.  Even in this case though I'm not sure how to launch
excel on the client given that different versions install differently etc.

Any ideas?


--andrew shumway
 



---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/





+=========================================================+
This message may contain confidential and/or privileged
information.  If you are not the addressee or authorized to
receive this for the addressee, you must not use, copy,
disclose or take any action based on this message or any
information herein.  If you have received this message in
error, please advise the sender immediately by reply e-mail
and delete this message.  Thank you for your cooperation.
+=========================================================+



---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/


Mime
View raw message