You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by gvn <gv...@cora.be> on 2002/04/02 16:06:02 UTC

How to Generate .xls file from struts app.

Hi all,

I would like to generate a .xls (excel) file data from a result set.

What I have to do ? 

Thanks,

Geoffrey.

Re: How to Generate .xls file from struts app.

Posted by Jim Crossley <jc...@ifleet.com>.
"gvn" <gv...@cora.be> writes:
>
> I would like to generate a .xls (excel) file data from a result set.
> =20
> What I have to do ?=20

One simple approach is to generate a CSV (Comma-Separated-Values) file
instead, and then set the response's content type to
"application/vnd.ms-excel".  That way, you exploit the fact that Excel
transparently handles CSV files and rely on the browser to invoke
Excel. 

Your action amounts to something not quite as trivial as this:

  PrintWriter out = response.getWriter();
  while (youHaveRows)
    while (youHaveColumns)
      out.print(yourCell+",");
  out.close();
  response.setContentType("application/vnd.ms-excel");

-- 
Jim Crossley
http://www.lads.com/~jim

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>