• Advertisement
Sign in to follow this  

Is there any way to generate a word doc from a html file

This topic is 1323 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Attached is my file. I would like that when the user clicks submit a word file is generated with the information. How could I do this?

Share this post


Link to post
Share on other sites
Advertisement

with html you can't.

 

You can however do it using PHP, Python, C# or some other programming language on the server backend (There are plenty of libraries around that lets you generate word and excel documents (primary in the newer .docx and .xlsx formats)

 

C#: http://www.codeproject.com/Articles/660478/Csharp-Create-and-Manipulate-Word-Documents-Progra

PHP: http://phpword.codeplex.com/

PHP (alternative library): http://www.phpdocx.com/documentation/tutorial

Python: https://pypi.python.org/pypi/docx/0.2.4

Edited by SimonForsman

Share this post


Link to post
Share on other sites

What we do at work is save our (HTML) reports into an MHTML file, which we give a .doc extension. Word will then open it via the shell, but recognise the format.

 

Its okay. Plenty of formatting issues of course.

Share this post


Link to post
Share on other sites

You can create the file server side as SimonForsman said, but with the new File API in HTML5 and Javascript you can create files in client's side too ( http://www.html5rocks.com/en/tutorials/file/filesystem/ ). There are security limitations for this, you can't just write the file anywhere in the disk (it works in a sandboxed file system) so you'll need to send that file to the server and provide a "download" popup if you want the user to get it.

 

Also, "a word file" could have a lot of formats (a single txt file can be opened in Word), but if you're trying to create a .doc file it might be a hard task. The .doc file format is not fully documented, so maybe you can create a .odt file (it's a standard well defined file format for documents) that Word recognizes and opens without problems. You'll probably found more info about doing this than doing HTML -> .doc.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement