简体   繁体   English

在ASP.NET C#中将网页上的内容另存为.doc

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

I want to save the contents in a file as .doc. 我想将内容保存为.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. 我有3个文本框控件,2个组合框和HTMLeditor ..我要将在此控件中输入的数据存储到MSword上。

How can i do this do. 我该怎么做。

This can be done using Word automation. 这可以使用Word自动化来完成。 The only catch is that you need Ms Word on the server. 唯一的问题是您在服务器上需要Word女士。

There is more information (no web application, but it should get you started) over here on: 有关更多信息(没有Web应用程序,但应该可以使您入门),有关以下信息:

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. 看一下html格式的doc的一个问题是,要用word打开doc时要显示的图像,需要互联网连接才能显示图像,因为它仅保存指向图像的链接。

But you can tweak this approach to suit your needs and if you refer to Microsoft Office HTML and XML Reference 但是如果您参考Microsoft Office HTML和XML参考 ,则可以调整此方法以适合您的需求。

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. 这样做的简单方法是创建一个Word文档,并为要插入值的位置制作占位符文本,例如## MyValue1 ####MyValue2 ##等。

Then save it in format that outputs human readable text like xml or html. 然后将其保存为输出易于阅读的文本(例如xml或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. 从那里开始,您在代码中要做的所有事情就是以文本形式读取文件,在占位符上进行字符串替换,然后将文件作为what.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. 这很容易,您可以使用word精确地按需要创建布局,并且不需要在服务器或任何其他组件上安装word。

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. 需要注意的是,您需要检查单词生成的xml或html,以确保它不会在占位符的中间插入奇怪的标记,从而阻止替换对象找到它们。

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. Microsoft也不推荐这样做。 See this article: http://support.microsoft.com/kb/257757 请参阅这篇文章: http : //support.microsoft.com/kb/257757

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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