在asp.net c#中将网页上的内容保存为.doc

发布于 2024-10-01 11:32:21 字数 112 浏览 0 评论 0原文

我想将文件中的内容保存为 .doc。

我有 3 个文本框控件、2 个组合框和 HTML 编辑器..我想将在此控件中输入的数据存储到 MSword 中。

我该怎么做才能做到这一点。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

初与友歌 2024-10-08 11:32:21

这可以使用 Word 自动化来完成。唯一的问题是您需要在服务器上安装 Ms Word。

这里有更多信息(没有网络应用程序,但应该可以帮助您入门):

c-尖角

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

随心而道 2024-10-08 11:32:21

看看这个Html to DOC
这样做的一个问题是,当您使用 Word 打开文档时要显示图像,需要互联网连接才能显示图像,因为它只保存图像的链接。

但是,如果您参考 Microsoft Office HTML 和 XML 参考,您可以调整此方法以满足您的需求

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

零崎曲识 2024-10-08 11:32:21

执行此操作的简单方法是创建一个 Word 文档,并为要插入值的位置创建占位符文本,例如 ##MyValue1## ##MyValue2## 等。

然后将其保存为输出人类可读文本的格式,例如 xml 或 html。

从那里开始,您在代码中要做的就是以文本形式读取文件,对占位符进行字符串替换,然后将文档作为whatever.doc 提供。

这很简单,您可以使用 Word 完全按照您想要的方式创建布局,并且不需要在服务器或任何其他组件上安装 Word。

需要注意的是,您需要检查 word 生成的 xml 或 html,以确保它不会在占位符中间插入奇怪的标签,从而阻止您的替换找到它们。

不建议在服务器上使用无人值守的文字自动化。这是非常不稳定的,你最终会得到无法正确关闭的文字处理等等。微软也不推荐它。请参阅这篇文章:http://support.microsoft.com/kb/257757

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文