创建Word 2010文档编程 [英] Create Word 2010 Document Programmatically

查看:157
本文介绍了创建Word 2010文档编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每周我产生一个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.

所以基本上我想要一个Word模板或控制台应用程序,当我打开/运行它,它熄灭,并收集所有这些东西,并将其链接到文档的各个部分。

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.

假设我必须插入:


  • 从另一个Word文档中复制一些

  • 一个PNG(饼图)

  • 从CSV文件中创建一个表

  • 有一个标准的页眉和页脚与页编号

我一般都对副本进行一些更改文件中强调,从本周的重头戏。

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

然后我检查到SharePoint去哪儿网的用户可以打开并查看它。

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

我想的事情要做的就是破解打开VS2010,使Word模板项目。我从来没有这样做之前,我想知道的陷阱有或者它甚至是一种适当的方式来解决我的问题。

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.

我会pretty舒适的控制台应用程序,所以我可能最终会做这种方式。

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

帮助/咨询AP preciated。

Help/Advice appreciated.

推荐答案

我会被打破的各个步骤,你会执行他们,如果你坐在一个空白的Word文档的正面解决这个问题。然后使用对象模型自动化。有一个学习曲线的一点点,但一旦你过去,你会沉迷于办公室自动化。办公室是一个相当强大的平台。大多数你可以通过用户界面实现可以通过编程来完成。我做了不少与Excel的自动化。在code是相当直观的...之类的东西worksheet.Range [A1] =ABCD(设置单元格A1 =ABCD)。

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").

这里有一些指针:

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

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

如果您通过在第一个链接的教程,你会得到它的要点。什么是伟大的是,你可以使用调试器来逐步执行code线。由于各行执行,你可以看到Word文档的结果。我从来没有使用Word模板项目,所以我不能为优点/缺点有说话。展望对象模型的路线,你只需要说出你想有发生什么,它分解为单独的步骤,你会c将其执行它们,然后$ C $起来。如果您遇到问题,否则可能有人在博客/张贴了关于如何使事情发生。谷歌会找到一个解决方案非常快。祝你好运!

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!

这篇关于创建Word 2010文档编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆