以编程方式编辑 Microsoft Word 文档

发布于 2024-10-16 22:03:06 字数 286 浏览 4 评论 0原文

我想知道这是否可以做到。

我正在为我们的软件系统(学校项目)构建一个数据字典,并且我正在考虑一种自动化的方法来做到这一点。基本上我不怎么使用 Microsoft Word (2007),我只用它来记录学校的资料等。我想知道是否可以通过模板以编程方式创建/编辑 Word 文档。

我的想法是,我将在 Word 上创建一个页面,其中包含一个空表单,该表单将在每个页面上重复。对于我将输入到程序中的每个数据,它将更新表单中的相应字段并跳到下一个表单。

这样做的目的是消除复制粘贴方法(我的习惯)并加快编写文档的速度。

I want to know if this could be done.

I am building a data dictionary for our software system (school project), and I'm thinking of an automated way to do this. Basically I don't use much of Microsoft Word (2007), I only use it in documenting schools stuff, etc. I want to know if its possible to create/edit a Word document programmatically from a template.

The idea is, I will create a page on Word that contains an empty form that will be repeated on every page. For every data that I will input to my program, it will update the corresponding field in the form and skips to the next form.

The purpose of this, is to eliminate copy-paste methods (my habit) and to speed things up when doing the documentation.

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

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

发布评论

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

评论(6

梦途 2024-10-23 22:03:06

正如其他人所建议的,Word 自动化将导致您陷入痛苦的世界,原因有两个:

  1. Office 不适合在无人值守的情况下运行,因此它可以随时弹出消息框,并且
  2. (可能)未获得许可为没有办公功能的计算机启用办公功能。如果您使用自动化在网站上生成 Word 文档,则必须确保未安装 Office 的计算机无法使用此功能(除非他们在过去几年更改了此规则)。

我使用过 Aspose.Words,它的成本有点高,但效果很好,就是为此而设计的。

Word automation, as suggested by others, will lead you to a world of hurt for two major reasons:

  1. Office is not intended to be run unattended, so it can pop up message boxes at any time, and
  2. It is (probably) not licensed to enable office functionality for computers which don't have it. If you generate a Word document on a web site using automation, you have to make sure that this functionality cannot be reached by computers which don't have office installed (unless they changed this rule in the last years).

I have used Aspose.Words, it costs a little, but it works well and is intended for this.

请止步禁区 2024-10-23 22:03:06

不太确定您真正想要什么,但使用 c# 创建 Word 文档应该不会有任何问题:

http:// support.microsoft.com/kb/316384

Not exactly sure what you really want, but creating word documents with c# shouldn't be any problem:

http://support.microsoft.com/kb/316384

幻梦 2024-10-23 22:03:06

如果我正确地找到了您的目的,您需要访问此 microsoft msdn 链接

操纵 Word 2007 年 OpenXML 文件

If i find out your purpose correctly you need to visit this microsoft msdn link

Manipulating Word 2007 Files with OpenXML

绾颜 2024-10-23 22:03:06

绝对有可能。使用办公自动化来实现这一点相当简单。请参阅此知识库文章了解基本示例:如何使用 Visual C# 自动执行 Microsoft Word 创建新文档

我认为该示例的主要区别在于您将打开模板并执行“另存为”而不是创建新文档,但我记不清了。

但是,根据您的具体要求,可能有更好的选择。例如,不建议在服务器(包括网络服务器)上执行办公自动化,因此如果需要,您可能想看看其他东西。

Definitely possible. A fairly easy way of doing it using Office Automation. See this KB article for a basic sample: How to automate Microsoft Word to create a new document by using Visual C#

I think the main difference to that sample will be that you'll open your template and do SaveAs instead of creating a new document, but I can't remember exactly.

However, depending on your exact requirements, there might be better alternatives. For example, it's not recommended to do Office Automation on servers (including on webservers), so if that's needed you might want to look at something else.

泪是无色的血 2024-10-23 22:03:06

使用 COM 编程并不是 erikkallen 提到的最好方法,我建议使用 OPEN XML。它真的很容易使用,并且您的文档生成操作将会非常快。

http://blog.goyello.com/2009/08/21/how-to-generate-open-xml-file-in-c-in-4-minutes/
http://msdn.microsoft.com/en-us/library/aa338205(v=office.12).aspx

Using COM programming is not the best way as mentioned by erikkallen, I suggest using OPEN XML. It is really easy to use and your document generation operation will be very fast.

http://blog.goyello.com/2009/08/21/how-to-generate-open-xml-file-in-c-in-4-minutes/
http://msdn.microsoft.com/en-us/library/aa338205(v=office.12).aspx

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