No - you will actually stream the output in the response, by getting the
response servletoutputstream and then doing print and println's.

Here's what I do - probably more complicated than you need it to be, but gives
you the idea:

         response.setContentType("csv");
         response.setHeader("Content-disposition", "attachment; filename=\"" +
filename + "\"");
         response.addHeader("Content-description", "Forms Report");
         ServletOutputStream stream = response.getOutputStream();

         for (Iterator i = data.getHeadings().iterator(); i.hasNext();)
         {
            stream.print("\"" + i.next() + "\"");
            if (i.hasNext())
            {
               stream.print(",");
            }
         }
         stream.println("");

         for (Iterator i = data.getRowData().iterator(); i.hasNext();)
         {
            ArrayList row = (ArrayList) i.next();

            for (Iterator j = row.iterator(); j.hasNext();)
            {
               stream.print("\"" + j.next() + "\"");
               if (j.hasNext())
               {
                  stream.print(",");
               }
            }
            stream.println("");
         }

         for (Iterator i = data.getTotals().iterator(); i.hasNext();)
         {
            stream.print("\"" + i.next() + "\"");
            if (i.hasNext())
            {
               stream.print(",");
            }
         }
         stream.println("");

         stream.flush();
         stream.close();
         return (null);

Cheers,

Dave





"Chen, Dean (Zhun)" <[EMAIL PROTECTED]> on 05/03/2002
11:38:19 AM

Please respond to "Struts Users Mailing List"
      <[EMAIL PROTECTED]>

To:   "'Struts Users Mailing List'"
      <[EMAIL PROTECTED]>
cc:    (bcc: David Hay/Lex/Lexmark)
Subject:  RE: Excel Export



I have a simple question regarding these implementations?

After a bean is populated by the Action class, do I write the contents of
the bean to a temporary xls file and then do:

Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader ("CONTENT-DISPOSITION", "attachment; filename =file.xls")

in the Action class?


Or do I build the JSP using contents of the bean but setting

response.setHeader("Content-Disposition","attachment;filename=data.csv");
response.setHeader("Content-Type", "application/ms-excel");

Will the file created by the JSP be called data.csv?

Thanks,

Dean Chen



-----Original Message-----
From: Ajay Chitre [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 29, 2002 3:16 PM
To: Struts Users Mailing List
Subject: RE: Excel Export


I really liked Vic's suggestion regarding SOAP.  I am going to explore that
myself.  In the mean time here's a quick & dirty Test.jsp that you can
use....


HTH!




<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML>
<HEAD>
<Title>Excel Format</Title>
<%


response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition","inline" );

ServletOutputStream outStream = response.getOutputStream();

PrintWriter pw = response.getWriter();



pw.println("<HTML>");
pw.println("<HEAD>");
pw.println("</HEAD>");
pw.println("<BODY>");
pw.println("<TABLE border=0 cellpadding=0 cellspacing=0>");
pw.println("<TR>");
pw.println("<TD>Custom Reports Process - xxx Report</TD><!--- Cell :
A1 --->");
pw.println("<TD></TD><!--- Cell : B1 --->");
pw.println("</TR>");
pw.println("<TR>");
pw.println("<TD>Selection Criteria</TD><!--- Cell : A2 --->");
pw.println("<TD>&nbsp;</TD><!--- Cell : B2 --->");
pw.println("</TR>");
pw.println("</TABLE>");
pw.println("<p>This is a test<br>");
pw.println("</BODY>");
pw.println("</HTML>");

pw.println("Testing$$$$$$$");
pw.flush();
pw.close();


%>


</BODY>
</HTML>


>-- Original Message --
>Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>From: "Galbreath, Mark" <[EMAIL PROTECTED]>
>To: 'Struts Users Mailing List' <[EMAIL PROTECTED]>
>Subject: RE: Excel Export
>Date: Mon, 29 Apr 2002 13:44:00 -0400
>
>
>This is way too complicated.  All you have to do is set the MIME type in
>the
>setContentType() declaration in the servlet delivering the output to
>"application/vnd.msExcel" and the browser will automatically display the
>output in an Excel spreadsheet.
>
>Mark
>
>-----Original Message-----
>From: Struts Newsgroup [mailto:[EMAIL PROTECTED]]
>Sent: Monday, April 29, 2002 1:40 PM
>To: [EMAIL PROTECTED]
>Subject: Re: Excel Export
>
>
>Subject: Re: Excel Export
>From: Vic C <[EMAIL PROTECTED]>
> ===
>Struts is Java. Excel is VBA. They don't like each other. One good way

>is to expose your Java (Form) beans via SOAP.
>Then in Excel (using Pocket Soap client for example) write a VBA macro

>that gets the SOAP XML data.
>You will need to add SOAP interface to you web app server.
>
>SOAP is good for most distributed  or diverse applications and good for

>hetrogenous enviroments. (There is a news list on soap at
>news.strutsplus.com)
>
>Vic
>
>
>Chen, Dean (Zhun) wrote:
>> This might be a little of topic, however, does struts support a
>standardized
>> way to export results from queries in a comma delimited format, for
>> importing into excel?
>> Thanks,
>>
>> Dean Chen
>>
>> --
>> To unsubscribe, e-mail:
><mailto:[EMAIL PROTECTED]>
>> For additional commands, e-mail:
><mailto:[EMAIL PROTECTED]>
>>
>
>
>
>--
>To unsubscribe, e-mail:
><mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail:
><mailto:[EMAIL PROTECTED]>
>
>--
>To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>

Ajay Chitre

Diligent Team, Inc.
(Where Diligent People Work as a Team)

http://www.DiligentTeam.com


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>








--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to