如何在Word中创建报告生成器 [英] How to create a report generator in word

查看:455
本文介绍了如何在Word中创建报告生成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在设法做到这一点,因此我可以为word加载一个模板,并提示您填写数据,然后将这些数据填充到word文档中.该报告有2个主要部分.俯视图中的第一个:

I am currently trying to figure out to to make it so I can load a template for word and be prompted to fill in data that will then be populated on the word document. The report has a 2 main sections. The first in the over view:

摘要将自动计算.

第二部分是将在其中添加数据的摘要:

The second section is the summary where data will be appended:

推荐答案

有多种方法可以在Word中生成报告,每种方法各有利弊:

There are several approaches to report generation in Word, each with its pros and cons:

1.使用VBA模块在MS Word本身(或其他启用VBA的MS Office应用程序)中自动生成报告: 在这种情况下,您将需要在将要生成报告的计算机上安装MS Word.您还必须允许在Word VBA模块中执行脚本.打开文档后,VBA可以开始执行,并且您可以执行几乎所有操作-例如连接到某些外部数据源,然后将这些数据填充到Word模板中.我一直在Word中使用书签作为数据的占位符.这样,您还可以填写表格-只需将书签放在第一个单元格中,跳到该书签,然后以编程方式一次填充一个单元格的数据,然后以编程方式移动到相邻的单元格,并且当您位于某个单元格的最后一个单元格中时行,新行将打开,并且您位于新行的第一个单元格中. 但是,在完成文档生成后,必须小心如何释放WINWORD进程. Office 2013不再支持VBA,因此这可能不是最佳解决方案.

1. Automate report generation in MS Word itself (or other VBA enabled MS Office applications), using VBA modules: In this case you will need to have MS Word installed on the machine, where the report generation will take place. You will also have to allow execution of scripts in Word VBA modules. After the document is open, VBA can start executing and there you can do pretty much anything - like connecting to some source of external data, filling this data into the Word template. I have been using bookmarks in Word as placeholders for the data. In this way you can also fill tables - just put the bookmark in the first cell, jump to this bookmark and then programmatically fill data one cell at the time and then programmatically move to the adjacent cell and when you are in the last cell in a row the new row opens and you are in the first cell of the new row. However, you have to be careful how to release WINWORD processes after you are done with document generation. VBA is no longer supported in Office 2013, so this is probably not the best solution.

2.使用.NET中的Interop程序集以编程方式执行此操作:首先,MSDN上有一篇文章介绍了如何使用Word模板并以编程方式对其进行操作.您可以在此处找到这篇文章.同样,您将需要在运行代码的计算机上安装Word.您可以很快获得结果,但是请注意,它并非设计为在服务器上运行,因为您可能很快就会遇到性能问题和内存泄漏.

2. Use Interop assemblies in .NET to do this programmatically: To start with, there is an article on MSDN about using a Word template and manipulate it programmatically. You can find this article here. Again you will need Word installed on the machine where you run the code. You can achieve results very quickly, but note that it is not designed run on a server, because you may soon have performance issues and memory leaks.

3.使用OperXML SDK可以通过编程方式从托管的.NET应用程序中处理Word文档::这使您可以完全自由地生成文档,但是学习过程又长又陡.根据您的业务领域的规模,您可以考虑将时间花在学习这项技术上.

3. Use OperXML SDK to programmatically manipulate Word documents from managed .NET application: This gives you total freedom in document generation, but the learning curve is long and steep. Depending on the scale of your business domain you may consider investing your time in learning this technology.

4.使用某些第三方工具:
就我而言,我不想使用OpenXML.我已经用SDK工具包替换了上述基于VBA的报表自动化功能,该工具包用于Word模板生成和报表自动化.您可以检查此链接举个例子.到目前为止,该工具包已经满足了我们的所有需求,因此我不再赘述.我大约在3年前使用此工具包准备了我的第一个模板,它们在从Office 2007到2010到2013的迁移过程中都顺利幸存了下来.现在,我拥有大约90个不同的Word模板库,这些模板被不同的应用程序使用,并且在后台使用.类似于设置并忘记它",与我们之前使用的VBA文档自动化相比,它节省了很多时间.

4. Use some of the third party Tools:
In my case I didn't want to use OpenXML. I have replaced VBA-based report automation as explained above with SDK toolkit for Word template generation and report automation. You can check this link for an example. So far this toolkit has covered all our needs, so I am not looking any further. I prepared my first templates about 3 years ago using this toolkit and they smoothly survived migrations from Office 2007 to 2010 to 2013. Now I have a library of about 90 different Word templates which are being used by different applications, using this toolkit in the background. Its kind like 'set it and forget it', and it saves me quite a bit of time compared to VBA document automation which we used before.

这篇关于如何在Word中创建报告生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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