poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lior Shliechkorn <liorshli...@yahoo.com>
Subject Re: Streaming XLS file to screen
Date Mon, 14 Apr 2003 17:02:37 GMT
Ok, it's still trying to open the original servlet ProcessReport not any .xls file. It's telling
me that it cannot open http://www.domain.com/servlet/ProcessReport which is really strange.

Nate <nmcminn@charter.net> wrote:Alrighty, I messed around with this for a second, and
it appears for some
reason the content type header is causing problems. Try setting it to
applicaton/vnd-ms.excel . This change allowed it to work properly for me.
On MS systems, this will cause the spreadsheet to open in the browser if
such things are enabled (by default they are), on non-ms platforms, this
should just open a save dialog, unless they have configured their mime types
to open excel with something (openoffice for example).

----- Original Message -----
From: "Lior Shliechkorn" 

To: "POI Users List" 

Sent: Monday, April 14, 2003 11:16 AM
Subject: Re: Streaming XLS file to screen


> Here you go. By the way, it seems to be wanting to save the 1st servlet's
name (ProcessReport) and open that in Excel, not a .xls file for some
reason. private void processRequest(HttpServletRequest request,
HttpServletResponse response) {
> response.setHeader("pragma", "no-cache");
> response.setHeader("Cache-Control", "no-cache");
> response.setHeader("Expires", "0");
> response.setContentType("application/octec-stream");
>
> HttpSession session = request.getSession(false);
> ServletOutputStream tobrowser = null;
> try{
> tobrowser = response.getOutputStream();
>
> * Here we create the workbook
> */
> wb = new HSSFWorkbook();
> HSSFSheet sheet = wb.createSheet("Daily Activity Report");
> sheet.setGridsPrinted(false); // turn off the gridlines in printing
>
> /*
> * Create the top row and put the header there
> */
> HSSFRow row = sheet.createRow((short) 0);
> String heading = "Daily Activity Report for " + adate;
> createHeaderCell(heading, row, (short) 0, HSSFCellStyle.ALIGN_LEFT);
> for (int i = 1; i <= 8; i++) {
> createHeaderCell("", row, (short) i, HSSFCellStyle.ALIGN_LEFT);
> }
> sheet.addMergedRegion(new Region(0,(short)0,0,(short)7));
> row = sheet.createRow((short) 1);
> globalRowCount = 2; // start on second row
> /*
> * Begin Populating Report
> */
> drs1 = dstmt1.executeQuery(asql);
> showTop = false;
> while(drs1.next()) {
> rcdnumAccount++; // increment account count
> getCurrentAccountInformation(sheet);
> } // end while
> GlobalSql.closeSR(dstmt1, drs1);
> /*
> * Finished generating all the report -> output to file
> */
> wb.write(tobrowser);
> } catch(Exception e) {
> System.err.println("Exception thrown in processRequest(): " +
e.getMessage());
> e.printStackTrace();
> }
> finally {
> try {
> GlobalSql.closeSR(dstmt1, drs1);
> tobrowser.flush();
> tobrowser.close();
> } catch (Exception sqlex) {
> System.err.println("SQLException thrown in processRequest()
finally: " + sqlex.getMessage());
> sqlex.printStackTrace();
> }
> }
> } // end DailyActivityReport
>
>
> Nate wrote:Gotcha. You should be able to do this
without saving to disk. Can you post
> the source? At least to the part of the servlet that sends the content to
> the browser? That would make things easier.
>
> ----- Original Message -----
> From: "Lior Shliechkorn"
>
> To: "POI Users List"
>
> Sent: Monday, April 14, 2003 10:54 AM
> Subject: Re: Streaming XLS file to screen
>
>
> > App Details: Wind2k && Tomcat 4.0.5I don't want to save the files
locally,
> since there are a few options for
> > each report to be run and I don't want to have a file create for each
> report
> > and for each user running a report. File sizes can vary drastically, and
I
> > don't want to have to take care of the storage and clean up of the
files.
> > So it's easier for the user to take care of that end. The process that
> creates the report is as follows:
> > 1. JSP page with a form for the report desired (with an option to view
as
> excel)
> > 2. Servlet to process which report servlet to pass the (req, res) to.
> > 3. Servlet for the report (2 flavors: 1) for HTML view 2) for excel
format
> view. I hope this gives you a better picture of what is being done. And
the
> higher ups of
> > course want this to happen and not be saved locally.
> >
> >
> > Nate wrote:You may have to set the content length.
> If this doesn't work for you
> > (without knowing the particulars of your app I can't say for sure). Just
> > write it out to a temp directory on the server, and then do a
> > response.sendRedirect(relative file path) to the saved file. For example
> >
> > tomcat app root
> > c:\tomcat\webapps\myapp
> >
> > save file to c:\tomcat\webapps\myapp\temp\12345.xls
> >
> > from the myapp context, redirect like this
> >
> > response.sendRedirect("temp/12345.xls");
> >
> > Is there any reason in particular that you don't want to save it to disk
> on
> > the server?
> >
> > ----- Original Message -----
> > From: "Lior Shliechkorn"
> >
> > To: "POI Users List"
> >
> > Sent: Monday, April 14, 2003 10:25 AM
> > Subject: Re: Streaming XLS file to screen
> >
> >
> > > Nate, Thanks again for the prompt resonse. I was not able to get this
to
> > work. The file download screen shows up and then an error message with
the
> > message that the internet site is unavailable pops up and terminates the
> > download. Any ideas why this would be happening? Lior
> > >
> > > Nate wrote:Well, doing this in a servlet, you have a
> > response object that you are
> > > passed in your servlet service methods (POST, GET, etc). code like the
> > > following should work
> > >
> > > //get an output stream to the browser
> > > ServletOutputStream tobrowser = response.getOutputStream();
> > >
> > > //set the response content type
> > > response.setContentType("application/octec-stream");
> > >
> > > //write the book out to the output stream
> > > WorkBook.write(tobrowser);
> > >
> > > //close streams and clean up (flush may not be needed)
> > > tobrowser.flush();
> > > tobrowser.close();
> > >
> > > ----- Original Message -----
> > > From: "Lior Shliechkorn"
> > >
> > > To: "POI Users List"
> > >
> > > Sent: Monday, April 14, 2003 9:58 AM
> > > Subject: Re: Streaming XLS file to screen
> > >
> > >
> > > > I'm very new to Java in general, would you be able to give me an
> example
> > > of what you're talking about. Do I need to put out.println("file
> output")
> > ?
> > > I'm not quite certain. Thanks again.
> > > >
> > > > Nate wrote:If this is being done through a web
> > > application, simply get the output
> > > > stream to the browser, write the constructed excel document out. Oh,
> and
> > > > make sure that you set the content type to application/octet-stream
> (or
> > > > alternately, if you want it to open in the browser for MS users, set
> the
> > > > content type to application/vnd.ms-excel)
> > > >
> > > > --Nathan McMinn
> > > >
> > > > ----- Original Message -----
> > > > From: "Lior Shliechkorn"
> > > >
> > > > To: "Poi"
> > > >
> > > > Sent: Monday, April 14, 2003 9:48 AM
> > > > Subject: Streaming XLS file to screen
> > > >
> > > >
> > > > > hello, I would like to be able to have the user save the file on
> their
> > > > system by outputting it to the screen, and not saving it to my disk
> > after
> > > it
> > > > has been generated. I'm using POI to generate reports for Excel
users,
> > and
> > > > would like to not have to save the file to my disk first and then
have
> > the
> > > > users be able to access it. Is there a way to have a pop up to ask
> them
> > to
> > > > open or save as so that it all happens on the user end? Thank you
very
> > > much
> > > > for your time,Lior
> > > > >
> > > > >
> > > > > ---------------------------------
> > > > > Do you Yahoo!?
> > > > > Yahoo! Tax Center - File online, calculators, forms, and more
> > > >
> > > >
> > > >
> > >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail: poi-user-help@jakarta.apache.org
> > > >
> > > >
> > > >
> > > > ---------------------------------
> > > > Do you Yahoo!?
> > > > Yahoo! Tax Center - File online, calculators, forms, and more
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: poi-user-help@jakarta.apache.org
> > >
> > >
> > >
> > > ---------------------------------
> > > Do you Yahoo!?
> > > Yahoo! Tax Center - File online, calculators, forms, and more
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: poi-user-help@jakarta.apache.org
> >
> >
> >
> > ---------------------------------
> > Do you Yahoo!?
> > Yahoo! Tax Center - File online, calculators, forms, and more
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: poi-user-help@jakarta.apache.org
>
>
>
> ---------------------------------
> Do you Yahoo!?
> Yahoo! Tax Center - File online, calculators, forms, and more



---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-user-help@jakarta.apache.org



---------------------------------
Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message