简体   繁体   中英

Saving the contents on a web page as .doc in asp.net c#

I want to save the contents in a file as .doc.

I have 3 text box controls,2 combo box and HTMLeditor..i want to store the data entered in this controls onto a MSword.

How can i do this do.

This can be done using Word automation. The only catch is that you need Ms Word on the server.

There is more information (no web application, but it should get you started) over here on:

c-sharpcorner

Take a look at this Html to DOC One problem with this, is that for images to be shown when you'll open the doc with word, will need internet connection to show the images, because it only saves the link to the image.

But you can tweak this approach to suit your needs and if you refer to Microsoft Office HTML and XML Reference

HTH

The easy way to do this is to create a word document, and make placeholder text for the places where you want to insert your values like ##MyValue1## ##MyValue2## and so forth.

Then save it in format that outputs human readable text like xml or html.

From there all you have to do in the code is read the file in as text, do a string replace on your placeholders, and serve up the document as whatever.doc.

It is easy, and you use word to create your layout exactly how you want it, and it does not require word to be installed on the server or any other component.

One caveat, you need to inspect the xml or html that word generates to make sure it does not insert weird tags in the middle of your placeholders that would prevent your replace from finding them.

It is not recommended to use word automation unattended on a server. It is very flaky you will end up with word process that don't close properly and so on. Microsoft does not recommend it either. See this article: http://support.microsoft.com/kb/257757

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM