poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dick Hildreth <DickHildr...@earthlink.net>
Subject Re: HSSF Failure in IE
Date Tue, 13 Dec 2005 18:30:37 GMT
Markus,

Your suggestion didn't quite work, but I thought I was reading your 
intent.  I coded:

    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-store");
    response.setDateHeader("Expires", 0);
    response.setHeader("Content-disposition", "attachment; filename=" +
                       reportEnvmt + ".xls");
    response.setContentType("application/vnd.ms-excel");

    ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
    OutputStream out = response.getOutputStream();
    wb.write(byteArrayOut);
    byte[] bytesOut = byteArrayOut.toByteArray();
    response.setContentLength(bytesOut.length);
    out.write(bytesOut);
    out.flush();
    out.close();

It still works fine in gecko browsers and it still fails in IE.  Same IE 
error: File: actionitems.xls, Unknown File Type, 87.0 KB, and the File 
does not exist.  The filename is correct.

Dick


Heck Markus wrote:

>Hello,
>
>have you tried writing the ByteArrayOutputStream to the
>ServletOutputStream???
>
>Some code snippet that is working for me (inside a servlet):
>
>        ServletOutputStream out            = null;
>        
>        response.setContentType( "application/vnd.ms-excel;
>charset=windows-1252" );
>        response.setHeader( "Content-Disposition"
>                          , "attachment; filename=test.xls" );
>
>        out = response.getOutputStream();
>
>        ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
>        wb.write( byteArrayOut );        
>
>        out.write( byteArrayOut.toByteArray() );
>
>Does this work?
>
>Markus
>
>  
>
>>Many thanks, Markus
>>
>>It seems to me that, doing as you say, I'm closing the barn 
>>door after 
>>the horses are gone.
>>
>>My code (after I've created the HSSFWorkbook wb):
>>
>>    ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
>>    wb.write(byteArrayOut);
>>    response.setContentLength((byteArrayOut.toByteArray()).length);
>>    byteArrayOut.flush();
>>    byteArrayOut.close();
>>
>>As I said, it seems to me that the Stream is already sent by the time 
>>I'm telling the browser how long the Stream is.  Additionally, using 
>>this construct has broken access via OpenOffice 2.0 Calc 
>>(says that it 
>>can't convert this Excel format) and it produces a blank spreadsheet 
>>when using IE and Excel.  Am I doing it wrong?  If I'm doing 
>>it right, 
>>then I must be fighting a different issue.
>>
>>Thanks again,
>>
>>Dick
>>
>>Heck Markus wrote:
>>
>>    
>>
>>>Hello,
>>>
>>>you can write the HHSFWorkbook to a ByteArrayOutputStream:
>>>
>>>   HSSFWorkbook workBook                 = null;
>>>   ByteArrayOutputStream byteArrayOut    = null;
>>>   ...
>>>   creating the Workbook
>>>   ...
>>>   byteArrayOut = new ByteArrayOutputStream();
>>>   workBook.write( byteArrayOut );
>>>
>>>And with byteArrayOut.toByteArray().length you get the desired 
>>>information.
>>>
>>>Regards
>>>
>>>Markus
>>>
>>> 
>>>
>>>      
>>>
>>>>-----Original Message-----
>>>>From: Dick Hildreth [mailto:DickHildreth@earthlink.net]
>>>>Sent: Monday, December 12, 2005 10:55 PM
>>>>To: POI Users List
>>>>Subject: Re: HSSF Failure in IE
>>>>
>>>>
>>>>Vielen dank, Christian!
>>>>
>>>>I already had the Header Properties set up as you suggest.  I
>>>>set them 
>>>>in a slightly different order, though I don't expect that 
>>>>would be an issue.
>>>>
>>>>One difference was that I had setDateHeader("Expires", 0)
>>>>where you have 
>>>>setHeader("Expires", 0).
>>>>
>>>>I don't understand, however, how to use a byte[] for intermediate
>>>>buffering as you suggest.  As I noted initially, I tried the 
>>>>HSSFWorkbook.getBytes() method, but that broke everything.  I 
>>>>can't find 
>>>>another way to implement the byte[] construct.
>>>>
>>>>Any further help would be most welcomed.
>>>>
>>>>Tschuess!
>>>>
>>>>Dick
>>>>
>>>>Christian Gosch wrote:
>>>>
>>>>   
>>>>
>>>>        
>>>>
>>>>>(1) Use a byte[] for intermediate buffering, that should tell the
>>>>>truth. If things get too big, you may underly a temp file.
>>>>>(2) There are RFCs about how to set up the HTTP response header 
>>>>>according to HTTP 1.0 or 1.1 (therefore you should know what 
>>>>>     
>>>>>
>>>>>          
>>>>>
>>>>your HTTP
>>>>   
>>>>
>>>>        
>>>>
>>>>>server component talks to its clients), but for IE that is
>>>>>     
>>>>>
>>>>>          
>>>>>
>>>>not really
>>>>   
>>>>
>>>>        
>>>>
>>>>>appropriate, because:
>>>>>(3) MSIE has really strange methods of claiming knowledge
>>>>>     
>>>>>
>>>>>          
>>>>>
>>>>about what is to
>>>>   
>>>>
>>>>        
>>>>
>>>>>come over the net; nevertheless it is all documented on MS's
>>>>>     
>>>>>
>>>>>          
>>>>>
>>>>website. Among
>>>>   
>>>>
>>>>        
>>>>
>>>>>the strange things is that in older versions (than 6) IE
>>>>>     
>>>>>
>>>>>          
>>>>>
>>>>used to send up to
>>>>   
>>>>
>>>>        
>>>>
>>>>>3 requests to fetch 1 file / resource. (I by myself have 
>>>>>          
>>>>>
>>seen up to 3 
>>    
>>
>>>>>dialogue boxes asking the user what to do.)
>>>>>
>>>>>
>>>>>We currently succeed on IE6 with some HTTP response header settings
>>>>>like the
>>>>>following:
>>>>>
>>>>>private void setHeaderProperties(HttpServletResponse
>>>>>     
>>>>>
>>>>>          
>>>>>
>>>>response, String
>>>>   
>>>>
>>>>        
>>>>
>>>>>filename) {
>>>>>response.setHeader("Cache-Control", "public");  
>>>>>response.setHeader("Pragma", "public");  
>>>>>response.setHeader("Expires", "0");  response.setHeader(
>>>>> "Content-Disposition",
>>>>> "attachment; filename=\""
>>>>>  + filename
>>>>>  + ".xls\";");
>>>>>response.setContentType("application/vnd.ms-excel");
>>>>>}
>>>>>
>>>>>
>>>>>Notice the content type since it is no 'real' type based 
>>>>>          
>>>>>
>>on any RFC.
>>    
>>
>>>>>This is just to confuse the IE file type recognition so that 
>>>>>     
>>>>>
>>>>>          
>>>>>
>>>>we get a
>>>>   
>>>>
>>>>        
>>>>
>>>>>Open/Save box for the end user.
>>>>>
>>>>>After that we calculate the real content byte count by using an
>>>>>intermediate byte[], set this value as content length and 
>>>>>     
>>>>>
>>>>>          
>>>>>
>>>>finally put
>>>>   
>>>>
>>>>        
>>>>
>>>>>the byte[] into the OutputStream (and flush it).
>>>>>
>>>>>
>>>>>The other thing is that this is NOT TESTED for any other
>>>>>     
>>>>>
>>>>>          
>>>>>
>>>>browser than
>>>>   
>>>>
>>>>        
>>>>
>>>>>IE (because we do not need to care about the better ones ;-) )
>>>>>
>>>>>
>>>>>Regards,
>>>>>Christian
>>>>>
>>>>>
>>>>>On Monday, December 12, 2005 2:56 AM [GMT+1=CET],
>>>>>Dick Hildreth <DickHildreth@earthlink.net> wrote:
>>>>>
>>>>>
>>>>>
>>>>>     
>>>>>
>>>>>          
>>>>>
>>>>>>I have built an application for creating and displaying an Excel
>>>>>>spreadsheet.  It works beautifully when accessed using Mozilla or

>>>>>>Firefox (haven't tested with Netscape) but fails when using MSIE.
>>>>>>
>>>>>>It appears that IE refuses to download the file (it also doesn't
>>>>>>recognize the content type) since, when Excel or OOo Calc 
>>>>>>       
>>>>>>
>>>>>>            
>>>>>>
>>>>open, they
>>>>   
>>>>
>>>>        
>>>>
>>>>>>complain that the file (in the Temporary Internet Files directory
>>>>>>structure) isn't found.  It isn't found for good reason - it isn't
>>>>>>there!
>>>>>>
>>>>>>            
>>>>>>
>>>>>>>From browsing other projects, such as iText on SourceForge, it
>>>>>          
>>>>>
>>>>>>appears that IE demands to know how big the stream is 
>>>>>>(setContentLength). Unfortunately, I can't figure out how 
>>>>>>       
>>>>>>
>>>>>>            
>>>>>>
>>>>to measure
>>>>   
>>>>
>>>>        
>>>>
>>>>>>the length to set it properly.  JavaDocs explicitly says that
>>>>>>WorkBook.getBytes() "get(s) the bytes of just the HSSF
>>>>>>       
>>>>>>
>>>>>>            
>>>>>>
>>>>portions of the
>>>>   
>>>>
>>>>        
>>>>
>>>>>>XLS file".  Apparently, there are bytes being sent other 
>>>>>>            
>>>>>>
>>than these
>>    
>>
>>>>>>bytes, since stting the ContentLength to the lenth of
>>>>>>getBytes() causes the geckop browsers to fail also.
>>>>>>
>>>>>>I would appreciate some insight as to how I might overcome this
>>>>>>problem.
>>>>>>
>>>>>>
>>>>>>------------------------------------------------------------
>>>>>>       
>>>>>>
>>>>>>            
>>>>>>
>>>>---------
>>>>   
>>>>
>>>>        
>>>>
>>>>>>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/
>>>>>>  
>>>>>>
>>>>>>       
>>>>>>
>>>>>>            
>>>>>>
>>>>>Gruesse,
>>>>>
>>>>>
>>>>>     
>>>>>
>>>>>          
>>>>>
>>>>   
>>>>
>>>>        
>>>>
>>>---------------------------------------------------------------------
>>>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/
>>>
>>>
>>> 
>>>
>>>      
>>>
>>    
>>
>
>---------------------------------------------------------------------
>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/
>
>
>  
>


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message