如何从SQL数据库中检索数据在Word 2010? [英] how to retrieve data from SQL database in Word 2010?

查看:170
本文介绍了如何从SQL数据库中检索数据在Word 2010?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用我们的MS SQL数据库中的数据填充Word文档。

I would like to populate a Word document with data from our MS SQL database.

这是可能的吗?如果是的话,

Is this possible, and if yes how?

推荐答案

在过去做了各种方式。这取决于用户是从Microsoft Word的OUTSIDE还是从INSIDE Microsoft Word启动操作。

I have done it various ways in the past. It depends whether the user initiates the action from OUTSIDE of Microsoft Word or from INSIDE Microsoft Word.

INSIDE Microsoft Word中,

From INSIDE Microsoft Word, you can use one of the following techniques:


  1. 使用占位符打开模板,并使用VBA或VSTO使用数据源对它们进行迭代,糊。请注意,表在这里也是一种犯罪。这种方法类似于下面的方法1与外部。

  2. 打开一个带有占位符的模板,并使用VBA或VSTO来解析XML文件,这样做的缺点是它相对较慢(复制和粘贴)表示然后替换这些。它更快,但更难写。特别是由于XML表示可以在占位符内包含XML片段(诸如& amp; lt;& amp; lt; PUT_< xxx /> IT_HERE& amp; gt;& gt; '和更复杂的情况)。

  1. Open a template with placeholders and use VBA or VSTO to iterate over them using a data source using copy & paste. Please note that tables are also a crime here. This approach resembles approach 1 below with "OUTSIDE". Disadvantage that it is relatively slow (copy & paste) and that Microsoft Word autocorrect likes to kick in when least needed.
  2. Open a template with placeholders and use VBA or VSTO to parse the XML representation and then replace these. It is faster, but harder to write. Especially since the XML representation can contain XML fragments within the placeholders (such as '&amp;lt;&amp;lt;PUT_<xxx/>IT_HERE&amp;gt;&amp;gt;' and more complex cases). Also, you need to make sure you keep a valid XML document and well balanced.

OUTSIDE Microsoft Word(例如网络界面)您可以使用以下技术之一:

From OUTSIDE Microsoft Word (such as web interface) you can use one of the following techniques:


  1. 使用RTF将模板存储在某个地方过程比Word自己的结构)。请放入& lt;& lt; PLACEHOLDER-FOR-NAME& gt;& gt; '或类似的容易识别的文字,当用户请求Word文档,获取RTF,获取数据,替换占位符,服务器RTF给用户。 RTF有一些限制,但有一些优点。优点是:易于创建新模板,并且还与Microsoft写字板和其他Office包一起使用。缺点是表是一个真正的糟糕的过程,并不是所有的Microsoft Word结构都是可能的。重复表中的行甚至不太推荐。高容量可能是一个问题。

  2. 使用也会输出docx,doc或RTF文档的报告包。撰写报告。一般来说完美适合大容量。如果您希望最终用户键入大量附加文本,则不太适合,因为报告包通常基于页面而不是流动文本工作,有时会插入显式或隐式分页符。但是如果你只需要最终用户输入一个或两个句子,那就足够了。

  3. 胖客户端。将SQL数据放在某处。打开Word。阅读数据并查看来自INSIDE Microsoft Word的更多技术。

  1. Store a template somewhere using RTF (which is far easier to process than Word's own structure). Put '&lt;&lt;PLACEHOLDER-FOR-NAME&gt;&gt;' or similar easily recognized texts where you like to replace it. When user requests the Word document, fetch the RTF, fetch the data, replace the placeholders, server RTF to user. RTF has some restrictions, but some advantages. Advantages are: ease of creating new templates and also works with Microsoft Wordpad and other Office packages. Disadvantages are that tables are a real mess to process and that not all Microsoft Word constructs are possible. Repeating rows in a table are even less recommended. High volume can be an issue.
  2. Use a reporting package that happens to also output docx, doc or RTF documents. Write a report. In general perfectly suited for high volume. Less suited if you want the end user to type a major amount of additional text, since reporting packages typically work based on pages instead on a flowing text, where sometimes an explicit or implicit page break is inserted. But if you only need the end user to enter one or two sentences in addition, it is sufficient.
  3. Fat-client. Put the SQL data somewhere. Open Word. Read the data and see further techniques for from INSIDE Microsoft Word.

如果需要从SQL Server填充Word文档其他数据库或数据平台),我可以建议从数据库填充Word文档的免费版隐藏式组合(请注意,我已参与该产品)。它打开模板并从Word中合并它们,但更加针对非开发人员;只需指定模板和数据块(可能嵌套)和发布。开发人员只能在插件中添加一些C#。我认为这是一个很好的产品,当你有MANY模板(超过50),因为它缩放更容易。

If you need to fill a Word document from SQL Server (or any other database or data platform) , I can suggest the free edition of Invantive Composition for filling Word documents from the database (please note that I've been involved with that product). It opens templates and merges them from within Word, but is more targeted at non-developers; just specify the template and datablocks (possibly nested) and publish. Developers can only add some C# in plugins. I think it is a good product when you have MANY templates (over 50) because it scales easier.

这篇关于如何从SQL数据库中检索数据在Word 2010?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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