Kieran Senior
Kieran Senior

Reputation: 18220

Word Open XML Mail Merge

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?

Upvotes: 2

Views: 5247

Answers (3)

Richard B
Richard B

Reputation: 1581

Can this be of some help?

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

Upvotes: 1

Alexander Taylor
Alexander Taylor

Reputation: 17632

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.

Upvotes: 0

Todd Main
Todd Main

Reputation: 29153

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:

Upvotes: 1

Related Questions