在 C# 中导出到 Word 文档

发布于 2024-07-08 10:01:08 字数 257 浏览 5 评论 0原文

我正在寻找一个允许创建 Word 文档的 .NET 库。 我需要将基于 HTML 的内容导出到 Word 文档(97-2003 格式,而不是 docx)。

我知道有 Microsoft Office Automation 库和 Office interop,但据我所知,它们要求您实际安装了 Office,并且它们通过打开 Word 本身来进行转换。 但我不希望需要安装 Office 才能进行转换。

编辑:如果可能的话,转换为 RTF 甚至可能有效。

I'm looking for a .NET library that will allow creation of a Word document. I need to export HTML based content to a Word doc (97-2003 format, not docx).

I know that there are the Microsoft Office Automation libraries and Office interop, but as far as I can tell, they require that you have office actually installed and they do the conversion by opening word itself. But I don't want to have the requirement of having office installed for the conversion to work.

Edit: Converting to RTF may even work, if possible.

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

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

发布评论

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

评论(7

傾旎 2024-07-15 10:01:08

如果我以某种方式将 CSS 转换为嵌入到 HTML 中,它会起作用吗?

是的。 正如我提到的,我使用内部样式表。

文档示例:

<html>
<head>
<STYLE type="text/css">
    h1 {text-align:center; font-size:12.0pt; font-family:Arial; font-weight:bold;}

    p {margin:0in; margin-bottom:0pt; font-size: 10.0pt;font-family: Arial;}
    p.Address {text-align:center;font-family:Times; margin-bottom: 10px;}
</style></head>
<body>
<p class="Address">The Street</p>
<h1>Head</h1>

Would it work if I somehow converted the CSS to be embedded in the HTML??

Yes. I use an internal style sheet, as I mentioned.

Document Example:

<html>
<head>
<STYLE type="text/css">
    h1 {text-align:center; font-size:12.0pt; font-family:Arial; font-weight:bold;}

    p {margin:0in; margin-bottom:0pt; font-size: 10.0pt;font-family: Arial;}
    p.Address {text-align:center;font-family:Times; margin-bottom: 10px;}
</style></head>
<body>
<p class="Address">The Street</p>
<h1>Head</h1>
夜访吸血鬼 2024-07-15 10:01:08

我使用 Aspose 来处理 Word,让一切变得轻而易举:http://www.aspose.com/

I use Aspose for working with Word, makes everything a breeze: http://www.aspose.com/

花期渐远 2024-07-15 10:01:08

我发现输出为 HTML 但名为 .doc 的文档将在 Word 中以正确格式打开。 我使用 Word 2000 和带有内部样式表的文件进行了测试。

I have found that a document output to HTML but called .doc will open properly formated in Word. I tested with Word 2000 and a file with an internal style sheet.

無處可尋 2024-07-15 10:01:08

从 ASP.NET 使用 Word Automation 并不是一个好主意(请参阅 MSKB - http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2)

如果您不使用 WinForms,恕我直言,您最好的选择是生成 RTF,哪个女士的词会很高兴地打开。 (请参阅已引用文章中的链接)。

祝你好运!

Using Word Automation from ASP.NET is not a good idea (see the MSKB - http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2)

If you are not using WinForms your best option IMHO is to generate RTF, which ms word will happily open. (see the link in the already referenced article).

Good Luck!

夜司空 2024-07-15 10:01:08

由于文档格式规范尚未开放,并且互操作程序集是 Microsoft 解决方案,因此我担心它们是您的主要(甚至唯一)选择。

他们确实需要安装 Office,并且打开 Word(尽管显示窗口是可选的)。

我认为Word可以打开HTML文档; 这是你的选择吗?

Since the doc format specification is not open, and the interop assemblies are the Microsoft solution, I fear that they are your primary (or even only) option.

They do indeed require office to be installed, and they open Word (although showing a window is optional).

I think Word can open HTML documents; is that an option for you?

山田美奈子 2024-07-15 10:01:08

我尝试直接在 word 中打开 html,这在技术上是有效的,除了一件事...我的 html 文档 包含 CSS,当在 Word 中打开时,它完全忽略 CSS,所以我不再有任何格式。 我意识到我不会从 CSS 中获取所有内容,但我至少希望仍然拥有指定的字体、字体大小等......有什么方法让它读取 CSS? 如果我以某种方式将 CSS 转换为嵌入到 HTML 中,它会起作用吗?

I tried just opening the html directly in word, which technically works except for one thing... My html doc also contains CSS, and when opening in Word, it completely ignores the CSS so I no longer have any of the formatting. I realize that I wouldn't get everything out of the CSS but I would at least like to still have the specified fonts, font sizes, etc... Any way to get it to read the CSS? Would it work if I somehow converted the CSS to be embedded in the HTML??

无声静候 2024-07-15 10:01:08

有一个名为 JODConverter 的工具,它可以连接到开放式办公室以公开其文件格式转换器,有一个可发布到的 Web 应用程序(位于 tomcat 中)的版本和一个命令行工具。 我一直在它上发射 html 并成功转换为 .doc 和 pdf,它是一个相当大的项目,还没有上线,但我想我会使用它。
http://sourceforge.net/projects/jodconverter/

There's a tool called JODConverter which hooks into open office to expose it's file format converters, there's versions available as a webapp (sits in tomcat) which you post to and a command line tool. I've been firing html at it and converting to .doc and pdf succesfully it's in a fairly big project, haven't gone live yet but I think I'm going to be using it.
http://sourceforge.net/projects/jodconverter/

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