We're having an application where we generate a .doc file on our ColdFusion server. The file opens properly in MSWord and is displayed correctly.
In Internet Explorer, it asks me wether to download or save the file. When saving, the file saves as file.doc in my download folder, which is correct.
When opening directly from Internet Explorer, the file is displayed correctly. But when I do "save as" in MSWord, the default file type is "website" and not "word document".
Here's the word's content. I know there are better solutions, but that's how we had it done then.
<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'>
<head>
<title>file name goes here</title>
<!--[if gte mso 9]>
<xml>
<w:WordDocument>
<w:View>Print</w:View>
<w:Zoom>90</w:Zoom>
<w:DoNotOptimizeForBrowser/>
</w:WordDocument>
</xml>
<![endif]-->
<style>/*style goes here*/</style>
</head>
<body>body goes here</body>
</html>
I had tried to add a doctype, but nothing happened.
On ColdFusion, following happens:
<cfcontent reset="true" type="application/vnd.ms-word" />
#wordContent#
<cfheader name="Content-Disposition" value="attachment; filename=file.doc" />
I had also tried "application/msword" as MIME-Type, but nothing happened.
I had tried to make it a .docx, but then it's malformed which seems logical, since it's not xml but html.
I hoped, there might be some meta information, which grants me access to the default file name as in e.g.
<o:Author>Author name goes here</o:Author>
<o:LastAuthor>Last authors name goes here</o:LastAuthor>
<o:Revision>1</o:Revision>
<o:Created>#dateFormat(now(),"yyyy-mm-dd")#T#timeFormat(now(),"HH:mm")#Z</o:Created>
<o:LastSaved>#dateFormat(now(),"yyyy-mm-dd")#T#timeFormat(now(),"HH:mm")#Z</o:LastSaved>
<o:Version>12.00</o:Version>
</o:DocumentProperties>
I also played with the informations given here http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats
But none of them seemed to work. So here I am, asking for help.
Edit: Added screenshot of MSWord behaving wrong (german)
Honestly I do not think it is possible to change the default "Save as type" value. While you can trick the browser into opening the content with MS Word, Word is still smart enough to recognize the current content is HTML. So it sets the default file type accordingly.
In any case, you can still select the .doc
file type manually. But as long as you are generating a faux-MS Word file (ie HTML) that is probably as good as it gets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With