You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Jack Holt <ja...@gmail.com> on 2005/06/24 23:43:31 UTC

Sending an CSV file as an Excel file

I don't know whether I should be doing this at the Server side in the
servlet or in the Velocity Template, but let me get y'all's opinion.

On the server side, I am setting the response's content type to excel
[using  resp.setContentType("application/vnd.ms-excel")] and placing
lines of comma-separated text into a String variable (data) and
placing the variable into the Velocity context. I am then setting the
view to be displayed to a Velocity template that has nothing but the
following in it:

  $data

The generated text is appearing in the browser as if the content type
were "text/html".  Is there some way to set the content type in a
Velocity template?

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


RE: Sending an CSV file as an Excel file

Posted by Steve O'Hara <so...@pivotal-solutions.co.uk>.
The advice below is good but we've also found the the following header works
well;

response.addHeader("Content-disposition","inline; filename=export.xls" );

Another thing, you could be making much more use of Excel, because Excel
(also Word and Powerpoint) can be completely expressed using HTML.  Some
time ago, Office 2000 I think, Microsoft created a universal HTML/XML
specification for these products.  You can download the spec. from the MS
web site if you look for "Office HTML and XML Reference".  Even if you only
use a couple of the features e.g. line breaks within cells, you're going to
give your users a much more useful output.

Steve

-----Original Message-----
From:
velocity-user-return-16276-sohara=pivotal-solutions.co.uk@jakarta.apache
.org
[mailto:velocity-user-return-16276-sohara=pivotal-solutions.co.uk@jakart
a.apache.org]On Behalf Of Will Glass-Husain
Sent: 25 June 2005 00:07
To: Velocity Users List; Jack Holt
Subject: Re: Sending an CSV file as an Excel file


I generally find something like this works fine.

response.setContentType("application/vnd.ms-excel;charset=iso-8859-1");
response.addHeader("Content-disposition","attachment; filename=" +
"export.xls" );

Unfortunately, the extension in the content-disposition header apparently
needs to be "xls".  But the content can be csv, HTML, or xml as well.  HTML
is quite nice because you can do basic formatting.

WILL

----- Original Message -----
From: "Jack Holt" <ja...@gmail.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Friday, June 24, 2005 2:43 PM
Subject: Sending an CSV file as an Excel file


I don't know whether I should be doing this at the Server side in the
servlet or in the Velocity Template, but let me get y'all's opinion.

On the server side, I am setting the response's content type to excel
[using  resp.setContentType("application/vnd.ms-excel")] and placing
lines of comma-separated text into a String variable (data) and
placing the variable into the Velocity context. I am then setting the
view to be displayed to a Velocity template that has nothing but the
following in it:

  $data

The generated text is appearing in the browser as if the content type
were "text/html".  Is there some way to set the content type in a
Velocity template?

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


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






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


Re: Sending an CSV file as an Excel file

Posted by Will Glass-Husain <wg...@forio.com>.
I generally find something like this works fine.

response.setContentType("application/vnd.ms-excel;charset=iso-8859-1");
response.addHeader("Content-disposition","attachment; filename=" + 
"export.xls" );

Unfortunately, the extension in the content-disposition header apparently 
needs to be "xls".  But the content can be csv, HTML, or xml as well.  HTML 
is quite nice because you can do basic formatting.

WILL

----- Original Message ----- 
From: "Jack Holt" <ja...@gmail.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Friday, June 24, 2005 2:43 PM
Subject: Sending an CSV file as an Excel file


I don't know whether I should be doing this at the Server side in the
servlet or in the Velocity Template, but let me get y'all's opinion.

On the server side, I am setting the response's content type to excel
[using  resp.setContentType("application/vnd.ms-excel")] and placing
lines of comma-separated text into a String variable (data) and
placing the variable into the Velocity context. I am then setting the
view to be displayed to a Velocity template that has nothing but the
following in it:

  $data

The generated text is appearing in the browser as if the content type
were "text/html".  Is there some way to set the content type in a
Velocity template?

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


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