In the documentation[1] for the Stream result type we have a:

<param name="contentDisposition">filename="contacts.xls"</param>

This was causing the problem. A simple change to:

<param name="contentDisposition">attachment;filename="contacts.xls"</param>

solved the issue.

Hope this may help someone out there

Gustavo
[1] http://struts.apache.org/2.0.11.1/docs/stream-result.html
Gustavo Felisberto escreveu:
Hello ALL,

I'm generating an Excel file in runtime and sending it to the client.I'm using struts 2.0.11.
In struts.xml I have:

<action name="ExportExcelFile" class="my.Class">
     <result name="success" type="stream">
       <param name="contentType">application/vnd.ms-excel</param>
       <param name="inputName">excelInputStream</param>
       <param name="contentDisposition">filename="contacts.xls"</param>
       <param name="bufferSize">4096</param>
     </result>
</action>

In the class I have:
public InputStream getExcelInputStream() {
       return new ByteArrayInputStream(exportExcelFile().toByteArray());
   }
private ByteArrayOutputStream exportExcelFile() {
       ByteArrayOutputStream bos = new ByteArrayOutputStream();
       try {
           WritableWorkbook workbook = Workbook.createWorkbook(bos);
           WritableSheet sheet = workbook.createSheet("Contactos", 0);
WritableCellFormat textFormat = new WritableCellFormat(NumberFormats.TEXT);

            //ADD STUFF TO SHEET

           workbook.write();
           workbook.close();
       } catch (RowsExceededException e) {
       } catch (WriteException e) {
       } catch (IOException e) {
       }
       return bos;
   }

If I use IE7 and I choose to save the file to disk and then open it with Excel 2007 all works ok. If I choose to open the file instead of saving it I get: 1 - an error in Tomcat: ERROR [http-8080-Processor21] (CommonsLogger.java:24) - Can not find a java.io.InputStream with the name [excelInputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.

2- A message from excel saying that the file I'm trying to open ExportExcelFile (and not the real name of the file) is in a diferent format than the extension. If i choose to open it the file is ok

3- IE7 hard locks until I say yes/no in excel to open the file

I'm accessing tomcat via HTTP

Any help will be much appreciated.



--
Gustavo Felisberto.
WIT-Software, Lda
Coimbra (Portugal), San Jose (California)
Phone: +351239801030
Web: http://www.wit-software.com

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to