0

我有一个后端系统,我想将其用作 MS Word 2010 邮件合并的数据源。我的想法是我应该编写一个单词加载项,它提供数据源并通过 Web 服务与我的后端通信。

通常是否可以提供带有单词 add in 的自定义数据源?有没有更好的解决方案?是否可以在 C# 中执行此操作?我在哪里可以找到有关此的 moar 信息?

谢谢

4

2 回答 2

3

Word 的开箱即用 Mailmerge 功能可以使用的数据源类型是众所周知的 - 例如

  1. 文件类型的数据源,例如 Word 文档、纯文本文件、Excel 工作簿等,
  2. “DDE”源(Access、Excel 和 MS Query,它们又希望使用 ODBC 连接)
  3. ODBC 数据源和
  4. OLE DB 数据源(这些必须符合 AFAIK 未记录的某些标准,例如,我认为提供者必须实现 iCommand)

若要使用内置 Mailmerge,Word 必须打开源代码,并且您不能覆盖 OpenDataSource。

没有接口可以让您直接使用 ADO.NET 数据源或断开连接的记录集。如果你想这样做,你必须“滚动你自己的”邮件合并。您可以考虑的一个起点是 Eric White 的系列文章 - 请参见此处

否则,您必须确保您的数据源是上述内容之一。对于 ODBC 源,您还必须使用 DSN - 您无法使用无 DSN 的连接字符串进行连接。您可以通过系统或机器 DSN 避免使用“文件”,但实际上分发文件 DSN 可能比在目标机器上创建文件 DSN 更容易。

对于 OLE DB 数据源,您必须拥有某种“连接文件”,即 .udl 或 .odc

最后一点:就 Word 而言,“ODBC”是“旧的”,而“OLE DB”是较新的。但微软前段时间宣布,它正在弃用 OLE DB,转而支持 ODBC。目前尚不清楚这是否适用于 SQL Server,我也没有看到任何东西告诉我们 Word 将来会支持/支持什么。同时,当然,更多的文档和数据存储在云位置,使用某些 ODBC/OLE DB 驱动程序/提供程序可能无法访问这些位置。

于 2012-08-07T21:30:15.537 回答
1

Yes you can do it from C# but it is more work than the way you were hoping to do it. If you could use a custom data source this would probably give you best bang-for-your-buck. If you are comfortable with programing (you mentioned C#) then you would write a small program (hopefully small) to control the mail merge process. I've seen JODReports and Docmosis do mail-merge doc-to-doc in the Java space, but I don't know if they have a C# api. If those tools look useful then you could definitely call them from scripts/command-line which might be your next fastest return on effort.
You also have the option of processing DOCX files yourself since they are zip files of XML you can literally open them up and make modifications. That's a lot more programming work though.
Good luck.

于 2012-08-08T00:50:07.750 回答