Word Open XML Mail Merge

…衆ロ難τιáo~ 提交于 2019-12-11 03:28:00

问题


I'm attempting to manually create a mail merge using Word's XML (from Word 2007). I have the following XML which isn't working:

<w:mailMerge>
    <w:mainDocumentType w:val="catalog" />
    <w:linkToQuery />
    <w:dataType w:val="native" />
    <w:connectString w:val="Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=TheServer;Data Source=." />
    <w:query w:val="SELECT * FROM  `Table` WHERE `id_field` = 7" />
    <w:dataSource r:id="rId1" />
    <w:activeRecord w:val="0" />
</w:mailMerge>

I can't really figure out from the documentation what I'm supposed to do. This is just a mail merge from a database table. It says there's an error on the line <w:mainDocumentType w:val="catalog" />. I've looked up possible values of w:val without any luck. I can't find any decent documentation on it.

Anyone have any ideas?


回答1:


DII has all of the documentation and you can also look up on this site, like the mainDocumentType is listed as a CT_MailMergeDocType. Upon searching for that, I get which then tells me to look up ST_MailMergeDocType, where it lists the types.

Also, OpenXML Developer has some basic intro articles to MailMerge with WordprocessingML:

  • Mail merge in WordProcessingML using System.IO.Packaging API
  • Mail Merge in WordProcessingML



回答2:


Can this be of some help?

Mail Merging With Word and Linq-to-Xml in VB




回答3:


in your sql command you aren't using regular single quotes (') but the kind i see when people have international keyboards ( "`" vs "'" ). i don't know how the SQLOLEDB provider works but i am used to seeing brackets around table and cloumn names rather than quotes.

using microsoft word, set up mail merging in a test document just how you want it. then view the xml that word generated using the Open XML SDK Tool which you can get here: http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=5124

compare the xml that word generates to your code to see where you may have gone wrong.

note that a w:mailMerge may depend on an external resource, in which case you include a data source reference.



来源:https://stackoverflow.com/questions/3555796/word-open-xml-mail-merge

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!