以编程方式创建 Word 2010 文档

发布于 2024-09-29 05:53:31 字数 550 浏览 2 评论 0原文

每周我都会制作一份 Word 文档,其中包含来自我们网络上各种来源的一些副本、表格和图表。

这可能需要一些时间,有时我会犯错误或忘记应该输入的内容。我想尽可能地自动化这个过程。

所以基本上我想制作一个Word模板或控制台应用程序,当我打开/运行它时,它会关闭并收集所有这些内容并将其链接到文档的各个部分。

假设我必须插入:

  • 来自另一个 Word 文档的一些副本
  • PNG(饼图)
  • 从 CSV 文件创建表格
  • 有一个带页码的标准页眉和页脚

我通常会对文档中的副本进行一些更改以突出显示突出显示内容从一周开始。

然后我将其签入 SharePoint,网络用户可以在其中打开并查看它。

我认为要做的就是破解VS2010并制作一个Word模板项目。我以前从未这样做过,我想知道其中存在哪些陷阱,或者这是否是解决我的问题的合适方法。

我的另一个选择是一些电源外壳,但我也不是这方面的专家。

我很乐意编写控制台应用程序,所以我最终可能会这样做。

感谢帮助/建议。

Every week I produce a word document with some copy, tables and charts from various sources on our network.

It can take a bit of time and sometimes I make mistakes or forget stuff that should go in. I want to automate this process as much as possible.

So basically I want to make a Word Template or Console App that when I open/run it it goes off and collects all this stuff and links it into the various parts of the document.

Assume I have to insert:

  • Some copy from another Word document
  • A PNG (pie chart)
  • Create a table from a CSV file
  • Have a standard Header and Footer with page numbering

I usually make a few changes to the copy in the document to highlight the highlight from the week.

Then I check it into a SharePoint where network users can open and view it.

I figure the thing to do is crack open VS2010 and make a Word Template project. I have never done this before and I wondered what traps there are or if its even an appropriate way to solve my problem.

My other option would be some power-shell but i'm no expert there either.

I'd be pretty comfortable writing console apps so I might end up doing it that way.

Help/Advice appreciated.

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

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

发布评论

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

评论(2

夜清冷一曲。 2024-10-06 05:53:31

我会通过分解各个步骤来解决这个问题,就像您坐在空白 Word 文档前面一样执行这些步骤。然后使用对象模型将其自动化。虽然有一点学习曲线,但一旦你克服了这个曲线,你就会对自动化 Office 上瘾。 Office 是一个非常强大的平台。通过用户界面实现的大部分功能都可以通过编程方式完成。我用 Excel 做了很多自动化工作。代码相当直观......它的东西像worksheet.Range [“A1”] =“abcd”(设置单元格A1 =“abcd”)。

以下是一些提示:

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

http://msdn.microsoft.com/en-us/library/ee861527.aspx

如果您阅读第一个链接中的教程,您就会了解其要点。最棒的是您可以使用调试器来单步执行代码行。每行执行时,您都可以在 Word 文档中看到结果。我从未使用过 Word 模板项目,所以我无法谈论那里的优点/缺点。走对象模型路线,您只需阐明您想要发生的事情,将其分解为执行这些步骤的各个步骤,然后对其进行编码。如果您遇到困难,很可能其他人已经在博客/帖子中介绍了如何实现某件事。谷歌会很快找到解决方案。祝你好运!

I would approach this problem by breaking down the individual steps as you would perform them if you were sitting in front of a blank Word document. Then automate it using the object model. There's a little bit of a learning curve, but once you get past that you'll be addicted to automating Office. Office is quite a powerful platform. Most of what you can achieve via the User Interface can be done programatically. I do quite a bit of automation with Excel. The code is fairly intuitive...its things like worksheet.Range["A1"] = "abcd" (setting cell A1 = "abcd").

here are some pointers:

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

http://msdn.microsoft.com/en-us/library/ee861527.aspx

If you go through the tutorial in the first link, you'll get the gist of it. What's great is that you can use the debugger to step through your lines of code. As each line executes, you can see the results on the Word document. I've never used a Word Template project, so I can't speak for the pros/cons there. Going the object model route, you just have to articulate what you want to have happen, break it down into the individual steps as you would perform them, and then code it up. If you get stuck, likely someone else has blogged/posted about how to make something happen. Google will find a solution very quick. Good luck!

旧情别恋 2024-10-06 05:53:31

您有很多选择:

  • 自动化 Word
  • 将其作为宏 (dotm)
  • 创建文档
  • 使用 Open XML SDK VSTO

您可能最好先使用宏来执行此操作,尽管这是旧的 VB6。您在那里快速学到的技术可以很好地转化为其他方法。 Open XML SDK 的优点是不需要 Word 创建文档。

You have lots of options:

  • automate Word
  • do it as a macro (dotm)
  • create your document using Open XML SDK
  • VSTO

You are probably best off doing it using a macro first, though this is old VB6. The techniques you quickly learn there translate pretty well into the other approaches. Open XML SDK has the virtue of not needing Word to create the document.

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