DownloadLink with static Excel files

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

DownloadLink with static Excel files

jgormley
I'm trying to use DownloadLink with a static Excel file in my resources directory and everything appears to be working just fine except that the file doesn't open in Excel (Excel complains that it is corrupt).

Everything works fine if I download a .txt or .jpg file, but not with .xlsx, .xls, or .zip files.  This tells me that some binary files do in fact work, but not Excel or Zip files.

Do I need to set the response headers specific for Excel?

Here's my code:
String templatePath = MyPage.class.getResource("").getPath() + "template.xlsx";
File templateFile = new File(templatePath);
form.add(new DownloadLink("templateLink", templateFile));
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: DownloadLink with static Excel files

jgormley
I have added a content type specific to xlsx files, and the file is still being corrupted.  The download dialog window in the browser (FF4) now recognizes that it's an Excel Workbook (as opposed to a binary file as it was doing before), but the file is still being corrupted somewhere along the line.  One other odd thing is that the file size of the downloaded file is different than the original file in the resources folder.

response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

Could there be some other wicket setting that I'm missing?  Maybe Tomcat is munging things?  Any help would be appreciated.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Resolved: DownloadLink with static Excel files

jgormley
Resolved!

The error was actually caused by Maven during the copy resources execution phase.  We have filtering turned on for the resources directory and it was clobbering the excel files.  I added a rule for xlsx files to not be filtered and all is well now.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Resolved: DownloadLink with static Excel files

ravi
I am trying to open the excel file on click of download button.
 can you plz help me in dat??
Loading...