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

Started by
3 comments, last by slicer4ever 9 years, 11 months ago

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?

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

[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

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.

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.

this looks like it's technically possible: http://stackoverflow.com/questions/4184944/javascript-download-data-to-file-from-content-within-the-page (see all reply's after first) using javascript, but is apparently not very reliable for older browsers.

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

This topic is closed to new replies.

Advertisement