XLSM files converted to XLSX

194 views
Skip to first unread message

Andrew Buchan

unread,
Aug 26, 2013, 7:06:33 AM8/26/13
to web...@googlegroups.com


I'm having a strange issue with a static file download. In the static folder I have a file with an xlsm extension, which I want users to be able to download via a hyperlink, which is created in the controller like so:

report_file_name = "DESIGN_SPEND_VS_ESTIMATE.xlsm"
...
DIV(P(A('Download report: %s' % report_file_name,
_href=URL(r=request,c='static/downloads',f=report_file_name)))),
...

This creates a download link which works fine in Google chrome, Fine in IE9, but not in IE8, where it tries to download the file with a .xlsx extension, which Excel cannot open, so it looks like I'm serving a corrupt file, which I'm not.

I've read up on this and aside from the really useful advice of telling me not to use IE8 (the default browser in my client's, the only pointer I get is that it may be to do with MIME type sniffing in IE, and that I need to change .htaccess settings on the server, which is equally useless to me as I might not always be in control of the server. As it turns out, this app runs on rocket on Windows, and there's nothing in the rocket docs about mime types, and I don't know if setting a .htaccess would even work on Windows.

Any thoughts?

Tim Richardson

unread,
Aug 26, 2013, 8:13:58 AM8/26/13
to web...@googlegroups.com
As a workaround, try saving the file as .xlsb and see what happens.

Niphlod

unread,
Aug 26, 2013, 8:21:46 AM8/26/13
to web...@googlegroups.com
content-type if not provided is guessed by gluon/contenttype.py. 
for xslx is 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'

If you need a different content-type, alter the default.py/download() function accordingly....

Andrew Buchan

unread,
Aug 26, 2013, 9:26:13 AM8/26/13
to web...@googlegroups.com
Hi Niphlod,

If I save file as xlsb I get an "invalid request" upon clicking on the link... Seems the browser is trying to open the files whereas I want it to download.

As for content-type and modifying default.py/download() function accordingly - can you provide an example of what alterations I should make. 
I can vaguely guess at what content type is all about, but have no idea why it's required and why we should have to set it?? I just want to provide a link so the user can download a file is all...

Thanks.




--
 
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/uENzWdeuy2c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Niphlod

unread,
Aug 26, 2013, 11:48:29 AM8/26/13
to web...@googlegroups.com
uhm. ok. if you don't know what a content-type is, please don't fiddle with it.
It may be that ie8 wants to autoopen the file instead of saving it like all the other browsers. The solution to force a "save as" dialog is quite simple: just add ?attachment to the generated URL.

Andrew Buchan

unread,
Aug 26, 2013, 1:13:06 PM8/26/13
to web...@googlegroups.com
I tried adding "?attachment", and I get a Save As dialog box......trying to save it as a xlsx file!! I'm just baffled by how something so basic can go so wrong...
I can download xlsm files fine from other sites, using IE8, so it has to be something in the Rocket or web2py.

Thanks for your help so far, just not sure where to go from now...


Derek

unread,
Aug 26, 2013, 2:09:20 PM8/26/13
to web...@googlegroups.com
xlsm mime type is: 

application/vnd.ms-excel.sheet.macroEnabled.12


from here:

Niphlod

unread,
Aug 26, 2013, 2:12:39 PM8/26/13
to web...@googlegroups.com
rotfl.... we miss a contenttype for xslm, but I can't find nowhere what is supposed to be the correct one. Can you point me to a link to an xslm file that it's working in IE8 ?

Andrew Buchan

unread,
Aug 27, 2013, 4:40:38 PM8/27/13
to web...@googlegroups.com
Sorry, was that request for me? My developments are all internal, not www so I've got no link to send...

In terms of getting an immediate/temporary fix, how would I go about adding that mime/content type to the rocket server my web2py app runs on?


Niphlod

unread,
Aug 27, 2013, 6:01:08 PM8/27/13
to web...@googlegroups.com
open gluon/contenttype.py . It's pretty much self-explanatory, but if you don't know the correct mime-type, its not going to be useful. BTW, if you find a mime-type that works out, tell us, we'll definitely include that.

Andrew Buchan

unread,
Aug 27, 2013, 6:38:40 PM8/27/13
to web...@googlegroups.com
OK, I added the following MIME type as suggested by Derek

application/vnd.ms-excel.sheet.macroEnabled.12

to gluon.py, which results in the file being opened/saved as xlsm, so it seems that is the correct one to use (gluon.py did have an entry for xlsm, but not the right one)

However...the workbook will not open with Excel telling me it contains invalid content, and this is true regardless of whether I open or save the file....BUT it works fine if I append "?attachment" to the URL...

So we have the correct MIME type to update gluon.py with, and I'm tempted to put down the need for the "?attachment" work-around as an IE8 problem as it works fine in IE9...

Thanks for all your help guys!

Derek

unread,
Sep 3, 2013, 12:54:00 PM9/3/13
to web...@googlegroups.com
Andrew, clear your IE cache and try downloading the file again, or rename the file and then try downloading it. IE < 9.0 will use the cache control headers, so the file will be cached if you don't use the attachment keyword. Look at line ~300 in the globals.py
Reply all
Reply to author
Forward
0 new messages