Click here to Skip to main content
14,766,279 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using ColdFusion as front-end. I want to save a HTML page to a Word Document. The below code are work fine, but when I try to save or save As, the default file type is .HTM/.HTML. How do I do to make default file type is .doc?

Here is the codes
<cfsavecontent variable="testMe">
<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns=''>

    <!--- Head tag instructs Word to start up a certain way, specifically in print view. --->
            <w:view w:val="print" />


        1234 <br>
</html><a href=""></a>

<cffile action="write" file="#application.reportsDir#eowReports\testMe.doc" output="#testMe#"/>
<a href="\&fileName=testMe.doc">Open It</a>

Thank you
Hung Pham

You cannot do it by just changing default. First of, those .doc formats are obsolete, you should use standard, based on Open XML standard, .docx. More importantly, this is not a part of W3 standard, you cannot just "convert" it. At the same time, MS Word can load HTML files. The cheating when you simply rename HTML to .doc would work, but would be nasty, making no practical sense.

If you really need to convert the HTML document to word, you can do it only on the server side. But the solution will be heavily depends on what is your server-side platform and what server-side technology you use, if any. It is of course possible, but I would strongly discourage you from doing that, unless you have string bonding with Microsoft Office (which rarely happens on the Web) and are ready to put good amount of development time.

Mario Z 1-May-15 2:45am
FYI renaming HTML to DOCX will not work. The trick is in renaming it to DOC.
Mario Z 1-May-15 5:03am
Really? I'm currently on mob. so I cannot check, but I will reply again when I verify your statement.

This is similar to somewhat commonly used trick with HTML renaming to XLS and that trick does not work with XLSX. However I must say I would be suprised if the same does not apply to DOC vs DOCX.
Mario Z 1-May-15 7:47am
Sergey I just tested this out and it turns out you are wrong.

I tried few simple HTML files and renamed them both to DOC and DOCX extensions and tried out on MS Word 2010 and 2013.
The DOC ones opened successfully and the DOCX ones failed with the following message:

The file cannot be opened because there are problems with the contents.

Error Details:
The file is corrupt and cannot be opened.
Your observations are correct; I confirm it. Sorry that I mentioned .docx in my answer; I changed it to .doc.

But this is not what I meant in my comment "Wrong". I mean it. The whole idea is wrong. You just name HTML content as *.DOC, for what? For opening it with Word, quite a bad HTML editor. No problem, but the user should not be tricked. This is not DOC; Word just imports HTML. The user knows better what to open with what.

Mario Z 2-May-15 2:53am
Oh, in that case yes I agree with you, this whole "workaround" is just a wrong thing to do.
Sorry to everyone: I should say "I want to convert the CONTENT of a HTML page to a Word document and then Save As the doc file". I did not mean to rename the file.

I am successfully convert the CONTENT of a HTML page to a Word document, but when I open the Word document file and "Save As" it for the first time, the Save as type is default to *.htm; *.html. I have to manually to select .doc or .docx to save for the first time, then after that the Save as type is default to .doc or .docx.

How do I do to make Save as type is default to .doc or .docx. for the first time?

ColdFusion is my front end.

Thank you so much and sorry for not making myself clear.

Hung Pham
Hi SA,
The reason I need to save a content of a HTML page into a Word document because my customers want to see it in Word as their report.
When they open their Word report, they can edit it as they want, and after that they will save or save as , then like I mentioned earlier, when they Save or Save for the first time the save as type default to .htm/.html instead of .doc. They want the save as type default to .doc.
I hope it makes sense to you and thank you so much for taking your time
Hung Pham

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900