Is there any chance this is an .xlsx (office 2007) and not an xls document?  
.xlsx documents are really zip files.  If this is the case then your content 
type would be different as well.

I believe the .xlsx is: 
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

Hope this helps.

-Nate

Nathan Sarr
Senior Software Engineer
River Campus Libraries
University of Rochester
Rochester, NY  14627
(585) 275-0692

-----Original Message-----
From: raygrrr [mailto:rayg...@gmail.com] 
Sent: Wednesday, October 19, 2011 5:18 AM
To: user@struts.apache.org
Subject: can't download excel file correctly

Dear Experts,

I have this action class to perform file downloading function, however, it
doesn't export excel file correctly, it give me a 'actionClassName.zip' file
instead of the excel file, but other format files like pdf file, jpg file
and text file are fine though, can't figure it out why 



My action class code:
public class DownloadDocumentAction extends Action {
        private static Log log = 
LogFactory.getLog(DownloadDocumentAction.class);
        
        public ActionForward execute(ActionMapping mapping, 
                                                                        
ActionForm form, 
                                                                        
HttpServletRequest request, 
                                                                        
HttpServletResponse response) {
                

        try 
        {
                String token = OpenkmUtils.getToken();
                byte[] localFile = OpenkmUtils.getFile(token, okmPath);
                
                ServletOutputStream out = response.getOutputStream();
                InputStream in = new ByteArrayInputStream(localFile);
     
                byte[] buffer = new byte[1024];

                int length = -1;
                while((length = in.read(buffer)) != -1) {                 
                        out.write(buffer, 0, length);       
                }
                
                in.close();
                out.flush();
                out.close();
          }
          catch (java.io.IOException ex)
          {
                 log.error(ex.getMessage());
          }
          

          response.setContentType("application/vnd.ms-excel");
              
response.setHeader("Content-Disposition","attachment;filename=\"" +
fileName+"\"");
          
          return null;
        }

}

--
View this message in context: 
http://struts.1045723.n5.nabble.com/can-t-download-excel-file-correctly-tp4917014p4917014.html
Sent from the Struts - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to