通过 OpenXML 删除 MailMerge 数据源
我有一些代码使用 Open XML 打开 .docx 文件,查找所有 MailMerge 字段,并将它们替换为数据(忽略可能已提供的数据源)。
我最初针对在 Office 2007 中创建的文档进行了测试,效果似乎很好。
然后,我们在 2003 年根据 Excel 电子表格数据源创建了一个,并将其保存为 2007 .docx 格式。当我们打开由我的代码生成的文件时,Word 会警告用户它将执行一些 SQL,特别是 SELECT * from 'Sheet1$'
。它有是/否选项。选择是需要我找到数据源。选择否会将我带到该文档,该文档似乎是正确的。
我不确定为什么现在会看到这个弹出窗口。也许是因为 2003 年文档的数据源不同?
我希望有一种方法可以删除对任何数据源的所有引用,并且弹出窗口不会显示。我发现这个,但似乎不起作用。有什么建议吗?
I have some code that uses Open XML to open up a .docx file, find all MailMerge fields, and replace them with data (ignoring the datasource that may have been provided).
I initially tested this against a document created in Office 2007 and it seemed to work great.
We then created one in 2003 based off an Excel spreadsheet data source and saved it to 2007 .docx format. When we open the file produced by my code, Word warns the user that it is going to execute some SQL, specifically SELECT * from 'Sheet1$'
. It has options of Yes/No. Selecting Yes requires I find the data source. Selecting No brings me to the document, which appears to be correct.
I'm not sure why I'm now seeing this pop-up. Perhaps it's due to a different data source for the 2003 document?
My hope was that there was a way to delete all references to any datasources and that the pop-up wouldn't show. I found this, but it doesn't seem to work. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我知道如何做到这一点。必须从 /word/settings.xml 获取设置部分,找到 w:mailMerge 条目并将其删除。
Ok, I found out how to do this. Had to get the settings part from /word/settings.xml, find the w:mailMerge entry and delete it.