You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Tahir Akhtar <ta...@spectrum-tech.com> on 2007/03/16 08:48:07 UTC

RE: Excel Export

Hi Dragan,

 

Although I don’t exactly remember what I said in the thread you mentioned,
here are few questions for you to answer

*	As the file opens correctly when opened directly or through other
tomcat server, the problem is not likely in the file. 
Do you save these files on server hard disk first or stream directly from
server?
*	The problem could be in the headers being sent by server to browser
When you open the attached excel file through the Linux SuSE + tomcat, does
the garbage shows up in MS Excel or directly in the browser window?

 

I tried your file through following combinations

 

Windows XP + Tomcat 4.1 

Internet Explorer: Garbage in IE6 Window (excel does not launch)

Firefox 2 Opens correctly

 

Windows XP + Tomcat 5.5 

Internet Explorer: Garbage in IE6 Window (excel does not launch)

Firefox 2 Opens correctly

 

I inspected HTTP headers returned by tomcat and found that tomcat does not
return any MIME type header by default. I am using Tomcat directly (i-e not
behind Apache Webserver or IIS). My assessment after this test is that the
bug lies in Internet Explorer (as usual :-). It appears to me that IE fails
to detect the file type correctly in some cases in absence of proper MIME
headers. 

 

You can try following approaches:

1. Add a mime-mapping in tomcat/conf/web.xml. I tried this and excel file
started opening correctly in IE6 (Restart tomcat and delete temporary
internet files from IE). 

    <mime-mapping>

        <extension>xls</extension>

        <mime-type>application/octet-stream</mime-type>

    </mime-mapping>

2. Instead of letting Tomcat serve the file create a custom servlet and set
HTTP headers manually like 
        response.setContentType("application/octet-stream");

        response.setHeader("Content-Disposition", "attachment;
filename=report.xls"  );

 

Wassalam

 

Tahir Akhtar

 

  _____  

From: Dragan.Krnic@bahn.de [mailto:Dragan.Krnic@bahn.de] 
Sent: Friday, March 16, 2007 3:02 AM
To: tahir@spectrum-tech.com
Subject: Re: Excel Export

 


Hello, Tahir, 

I've seen your name in an Apache/Tomcat thread regarding a problem 
which I also have from time to time. Some very simple Excel sheets 
show as garbage through a Tomcat 5.0.28 and 4.1.27  running under 
Linux SuSE 10.1 but the same file display just fine when opened 
directly or through a Tomcat 4.1 running under Windows XP. 

In one case I was able to restore proper Excel view by saving the 
same file from Excel 2002 but in other cases that didn't help either. 

I am enclosing one such file in the hope that you might find out 
what is wrong. Is it OK with you? 





I've even saved the file under a different name but it behaves just 
like this one - it displays as garbage in the IE6 browser. The new 
file is slightly bigger (exactly 512 bytes) than the original file here. 

Do you see anything wrong with this file? 
Why does it not display properly? 

I have thousands of such Excel sheets which do display OK, 
but from time to time there is such a file which just won't 
display properly through a Linux Tomcat server but displays 
perfectly thgough a Windows XP Tomcat. 

It drives me nuts. 


Dragan Krnic
DB Fernverkehr AG
P.TVN5 
Stephensonstraße 1/I-01/27, 60326 Frankfurt
Tel. +49 (0)69/265-59612, Fax (0)69/265-7550
________________________________________________________________
Internetauftritt der Deutschen Bahn AG >> http://www.db.de


Re: Excel Export

Posted by David Fisher <df...@jmlafferty.com>.
Hi Dragen,

We serve POI written XLS all the time through TOmcat 4.1.31 - we  
learned the hard way the following:

Do not serve through a JSP - write a Servlet:

(1) JSP is supposed to be TEXT only.
(2) In JSP it is easy to insert a space in your output before setting  
the header and that makes the output have mimetype=text/plain.

public class ExportXlsServlet extends HttpServlet {

     protected void doGet(HttpServletRequest request,  
HttpServletResponse response) throws ServletException, IOException {
         response.setHeader("Expires","Thu, 01 Dec 1994 16:00:00 GMT");
         response.setDateHeader("Last-Modified",  
System.currentTimeMillis() );
         response.setHeader("Pragma","no-cache");
         response.setHeader("Content-disposition",  
"attachment;filename=served.xls");
         response.setContentType("application/vnd.ms-excel");

         write the XLS to response.getOutputStream());
     }
}

This works well with IE 6 / IE 7 / Firefox 1.5 & 2.0 / Safari etc.

     <servlet>
         <servlet-name>exportxls</servlet-name>
         <servlet-class>com.mysevlets.ExportXlsServlet</servlet-class>
     </servlet>

Then your url is /exportxls?parms=whatever

When you open your Excel file from the Web in IE - DO NOT let it open  
it in the Browser - Save it and Open. If anyones knows an easy  
ubiquitous way to unset that, I'd love to know.

If you use application/octet-stream and allow IE to open in the  
browser then you will start to have trouble with binary files that  
are served that way ...

Regards,
Dave Fisher


On Mar 16, 2007, at 2:48 AM, Tahir Akhtar wrote:

> Hi Dragan,
>
>
>
> Although I don’t exactly remember what I said in the thread you  
> mentioned,
> here are few questions for you to answer
>
> *	As the file opens correctly when opened directly or through other
> tomcat server, the problem is not likely in the file.
> Do you save these files on server hard disk first or stream  
> directly from
> server?
> *	The problem could be in the headers being sent by server to browser
> When you open the attached excel file through the Linux SuSE +  
> tomcat, does
> the garbage shows up in MS Excel or directly in the browser window?
>
>
>
> I tried your file through following combinations
>
>
>
> Windows XP + Tomcat 4.1
>
> Internet Explorer: Garbage in IE6 Window (excel does not launch)
>
> Firefox 2 Opens correctly
>
>
>
> Windows XP + Tomcat 5.5
>
> Internet Explorer: Garbage in IE6 Window (excel does not launch)
>
> Firefox 2 Opens correctly
>
>
>
> I inspected HTTP headers returned by tomcat and found that tomcat  
> does not
> return any MIME type header by default. I am using Tomcat directly  
> (i-e not
> behind Apache Webserver or IIS). My assessment after this test is  
> that the
> bug lies in Internet Explorer (as usual :-). It appears to me that  
> IE fails
> to detect the file type correctly in some cases in absence of  
> proper MIME
> headers.
>
>
>
> You can try following approaches:
>
> 1. Add a mime-mapping in tomcat/conf/web.xml. I tried this and  
> excel file
> started opening correctly in IE6 (Restart tomcat and delete temporary
> internet files from IE).
>
>     <mime-mapping>
>
>         <extension>xls</extension>
>
>         <mime-type>application/octet-stream</mime-type>
>
>     </mime-mapping>
>
> 2. Instead of letting Tomcat serve the file create a custom servlet  
> and set
> HTTP headers manually like
>         response.setContentType("application/octet-stream");
>
>         response.setHeader("Content-Disposition", "attachment;
> filename=report.xls"  );
>
>
>
> Wassalam
>
>
>
> Tahir Akhtar
>
>
>
>   _____
>
> From: Dragan.Krnic@bahn.de [mailto:Dragan.Krnic@bahn.de]
> Sent: Friday, March 16, 2007 3:02 AM
> To: tahir@spectrum-tech.com
> Subject: Re: Excel Export
>
>
>
>
> Hello, Tahir,
>
> I've seen your name in an Apache/Tomcat thread regarding a problem
> which I also have from time to time. Some very simple Excel sheets
> show as garbage through a Tomcat 5.0.28 and 4.1.27  running under
> Linux SuSE 10.1 but the same file display just fine when opened
> directly or through a Tomcat 4.1 running under Windows XP.
>
> In one case I was able to restore proper Excel view by saving the
> same file from Excel 2002 but in other cases that didn't help either.
>
> I am enclosing one such file in the hope that you might find out
> what is wrong. Is it OK with you?
>
>
>
>
>
> I've even saved the file under a different name but it behaves just
> like this one - it displays as garbage in the IE6 browser. The new
> file is slightly bigger (exactly 512 bytes) than the original file  
> here.
>
> Do you see anything wrong with this file?
> Why does it not display properly?
>
> I have thousands of such Excel sheets which do display OK,
> but from time to time there is such a file which just won't
> display properly through a Linux Tomcat server but displays
> perfectly thgough a Windows XP Tomcat.
>
> It drives me nuts.
>
>
> Dragan Krnic
> DB Fernverkehr AG
> P.TVN5
> Stephensonstraße 1/I-01/27, 60326 Frankfurt
> Tel. +49 (0)69/265-59612, Fax (0)69/265-7550
> ________________________________________________________________
> Internetauftritt der Deutschen Bahn AG >> http://www.db.de
>


---------------------------------------------------------------------
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/