Message-ID: <1034375260.9571.1711695175440.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_9570_1480952570.1711695175440" ------=_Part_9570_1480952570.1711695175440 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html WordTemplate.SetMailMerge(Object(,), String(), Int32, Boolean)</= title> <!--[if gte mso 9]> <xml> <o:OfficeDocumentSettings> <o:TargetScreenSize>1024x640</o:TargetScreenSize> <o:PixelsPerInch>72</o:PixelsPerInch> <o:AllowPNG/> </o:OfficeDocumentSettings> <w:WordDocument> <w:View>Print</w:View> <w:Zoom>90</w:Zoom> <w:DoNotOptimizeForBrowser/> </w:WordDocument> </xml> <![endif]--> <style> <!-- @page Section1 { size: 8.5in 11.0in; margin: 1.0in; mso-header-margin: .5in; mso-footer-margin: .5in; mso-paper-source: 0; } td { page-break-inside: avoid; } tr { page-break-after: avoid; } div.Section1 { page: Section1; } /* Confluence print stylesheet. Common to all themes for print medi= a */ /* Full of !important until we improve batching for print CSS */ #main { padding-bottom: 1em !important; /* The default padding of 6em is too mu= ch for printouts */ } body { font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 10pt; line-height: 1.2; } body, #full-height-container, #main, #page, #content, .has-personal-sidebar= #content { background: #fff !important; color: #000 !important; border: 0 !important; width: 100% !important; height: auto !important; min-height: auto !important; margin: 0 !important; padding: 0 !important; display: block !important; } a, a:link, a:visited, a:focus, a:hover, a:active { color: #000; } #content h1, #content h2, #content h3, #content h4, #content h5, #content h6 { font-family: Arial, Helvetica, FreeSans, sans-serif; page-break-after: avoid; } pre { font-family: Monaco, "Courier New", monospace; } #header, .aui-header-inner, #navigation, #sidebar, .sidebar, #personal-info-sidebar, .ia-fixed-sidebar, .page-actions, .navmenu, .ajs-menu-bar, .noprint, .inline-control-link, .inline-control-link a, a.show-labels-editor, .global-comment-actions, .comment-actions, .quick-comment-container, #addcomment { display: none !important; } .comment .date::before { content: none !important; /* remove middot for print view */ } h1.pagetitle img { height: auto; width: auto; } .print-only { display: block; } #footer { position: relative !important; /* CONF-17506 Place the footer at end of= the content */ margin: 0; padding: 0; background: none; clear: both; } #poweredby { border-top: none; background: none; } #poweredby li.print-only { display: list-item; font-style: italic; } #poweredby li.noprint { display:none; } /* no width controls in print */ .wiki-content .table-wrap, .wiki-content p, .panel .codeContent, .panel .codeContent pre, .image-wrap { overflow: visible !important; } /* TODO - should this work? */ #children-section, #comments-section .comment, #comments-section .comment .comment-body, #comments-section .comment .comment-content, #comments-section .comment p { page-break-inside: avoid; } #page-children a { text-decoration: none; } /** hide twixies the specificity here is a hack because print styles are getting loaded before the base styles. */ #comments-section.pageSection .section-header, #comments-section.pageSection .section-title, #children-section.pageSection .section-header, #children-section.pageSection .section-title, .children-show-hide { padding-left: 0; margin-left: 0; } .children-show-hide.icon { display: none; } /* personal sidebar */ .has-personal-sidebar #content { margin-right: 0px; } .has-personal-sidebar #content .pageSection { margin-right: 0px; } --> </style> </head> <body> <h1>WordTemplate.SetMailMerge(Object(,), String(), Int32, Boolean)</h1> <div class=3D"Section1"> <h2 id=3D"WordTemplate.SetMailMerge(Object(,),String(),Int32,Boolea= n)-Description">Description</h2>=20 <p>Sets the MailMerge's data source to a two-dimensional (rectangular) arra= y of objects. A MailMerge by default treats the page content as a repeat bl= ock, repeating the page content for each row unless NEXT fields are used. I= f the <a href=3D"/display/WW8/WordTemplate.EnableNEXTFields">WordTemplate.E= nableNEXTFields</a> property is set to true, the NEXT field can also be use= d to indicate that the next row of data should be inserted instead of the c= urrent row at the next occurence of the merge fields. This should largely i= mitate the behavior of a Microsoft Word Mail merge.</p>=20 <div class=3D"code panel pdl" style=3D"border-width: 1px;"> <div class=3D"codeHeader panelHeader pdl" style=3D"border-bottom-width: 1px= ;"> <b>C#</b> </div> <div class=3D"codeContent panelContent pdl">=20 <pre class=3D"theme: Default; brush: csharp; collapse: false; gutter: false= " style=3D"font-size:12px;"> public void SetMailMerge(System.Object[,] table, System.String[] columnNam= es, int maxRows, boolean transpose) </pre>=20 </div> </div>=20 <div class=3D"code panel pdl" style=3D"border-width: 1px;"> <div class=3D"codeHeader panelHeader pdl" style=3D"border-bottom-width: 1px= ;"> <b>vb.net</b> </div> <div class=3D"codeContent panelContent pdl">=20 <pre class=3D"theme: Default; brush: vbnet; collapse: false; gutter: false"= style=3D"font-size:12px;"> Public Sub SetMailMerge(ByVal table As Object(,), ByVal columnNames As Stri= ng(), ByVal maxRows As Integer, ByVal transpose As Boolean) </pre>=20 </div> </div>=20 <h2 id=3D"WordTemplate.SetMailMerge(Object(,),String(),Int32,Boolean)-Param= eters">Parameters</h2>=20 <h6 id=3D"WordTemplate.SetMailMerge(Object(,),String(),Int32,Boolean)-table= ">table</h6> The two-dimensional (rectangular) array of objects to use as t= he data source.=20 <h6 id=3D"WordTemplate.SetMailMerge(Object(,),String(),Int32,Boolean)-colum= nNames">columnNames</h6> The one-dimensional array of strings that represen= t the field names to be replaced by the data. These names must match the co= lumn names from your data source.=20 <br class=3D"atl-forced-newline" />=20 <h6 id=3D"WordTemplate.SetMailMerge(Object(,),String(),Int32,Boolean)-maxRo= ws">maxRows</h6> Specifies the maximum number of rows to import from the da= ta source. To import the maximum rows available, use the constant=20 <a href=3D"/display/WW8/WordTemplate.ALL_ROWS" rel=3D"nofollow">WordTemplat= e.ALL_ROWS</a> .=20 <br class=3D"atl-forced-newline" />=20 <h6 id=3D"WordTemplate.SetMailMerge(Object(,),String(),Int32,Boolean)-trans= pose">transpose</h6> If transpose is set to=20 <code>true</code>, the array is treated as Object[column, row]. If transpos= e is set to=20 <code>false</code>, the array is treated as Object[row, column].=20 <h2 id=3D"WordTemplate.SetMailMerge(Object(,),String(),Int32,Boolean)-Excep= tions">Exceptions</h2>=20 <h6 id=3D"WordTemplate.SetMailMerge(Object(,),String(),Int32,Boolean)-Argum= entNullException">ArgumentNullException</h6>=20 <a href=3D"/display/WW8/WordTemplate.Save" rel=3D"nofollow">Save</a> will t= hrow this exception if=20 <code>null</code> (C#) or=20 <code>Nothing</code> (VB.NET) is passed to the method.=20 <h6 id=3D"WordTemplate.SetMailMerge(Object(,),String(),Int32,Boolean)-Argum= entException">ArgumentException</h6>=20 <h2 id=3D"WordTemplate.SetMailMerge(Object(,),String(),Int32,Boolean)-Remar= ks">Remarks</h2>=20 <p>You can call <a href=3D"/display/WW8/WordTemplate.SetMailMerge" rel=3D"n= ofollow">SetMailMerge</a> once for each instance of <a href=3D"/display/WW8= /WordTemplate" rel=3D"nofollow">WordTemplate</a>. If you are using the Word= 2003 binary template file type (.doc/.dot), you can call SetMailMerge or S= etRepeatBlock, but not both.</p>=20 <p>Additionally, only the page content is repeated for each row, not the en= tire page itself. If you wish to have the page itself repeat for each row, = you will need to remember to place a page break at the bottom of the page. = Alternatively, you can create a hidden page break at the top of the page as= follows:</p>=20 <ul>=20 <li>Put the cursor at the top of the document</li>=20 <li>Go to Page Layout and open the paragraph formatting dialog</li>=20 <li>On the Line and Page Breaks tab,  select "Page Break Before&q= uot;</li>=20 </ul>=20 <p>Merge Fields for using the SetMailMerge method must not specify a data s= ource =E2=80=93 the data source is implied, and using a data source name wi= ll cause WordTemplate to throw an error. Valid merge field formats for use = with SetMailMerge include field names (<strong>«fieldname»</str= ong>) and field ordinals (<strong>«#1»</strong>).</p>=20 <span style=3D"color:black"><h4 id=3D"WordTemplate.SetMailMerge(Object(,),S= tring(),Int32,Boolean)-Introducedinbuild8.2">Introduced in build 8.2</h4></= span>=20 <p><a href=3D"/display/WW8/WordTemplate.SetMailMerge" rel=3D"nofollow">SetM= ailMerge</a> will now work with headers and footers. A section break is req= uired instead of a page break if each header or footer will be different.</= p>=20 <h2 id=3D"WordTemplate.SetMailMerge(Object(,),String(),Int32,Boolean)-Examp= les">Examples</h2>=20 <div class=3D"code panel pdl" style=3D"border-width: 1px;"> <div class=3D"codeHeader panelHeader pdl" style=3D"border-bottom-width: 1px= ;"> <b>C#</b> </div> <div class=3D"codeContent panelContent pdl">=20 <pre class=3D"theme: Default; brush: csharp; gutter: false" style=3D"font-s= ize:12px;"> ... //--- A 2-D rectangular array of values //--- This is a "transposed" array with columns in the = first //--- dimension and rows in the second object[,] data =3D new object[,]{ {"Knoxville", "Boston", "Washington", "Seattle", "Chicago", "New York", "Atlanta", "Los Angeles", "Houston"}, {"Tennessee", "Massachusetts", "DC", "Washington", "Illinois", "New York", "Georgia", "California", "Texas"} }; //--- Names array, elements correspond to merge field names string[] names =3D new string[]{"City","State"= ;}; WordTemplate wt =3D new WordTemplate(); wt.Open(Server.MapPath("template/MergeFieldTest.doc")); //--- Set the mail merge //--- The data source is the 2-D rectangular data array //--- MaxRows is set to ALL_ROWS, which allows all rows to be imp= orted //--- Transpose is set to true to handle the transposed array wt.SetMailMerge(data, names, WordTemplate.ALL_ROWS, true); wt.Process(); wt.Save(Page.Response, "output.doc", false); </pre>=20 </div> </div>=20 <div class=3D"code panel pdl" style=3D"border-width: 1px;"> <div class=3D"codeHeader panelHeader pdl" style=3D"border-bottom-width: 1px= ;"> <b>vb.net</b> </div> <div class=3D"codeContent panelContent pdl">=20 <pre class=3D"theme: Default; brush: csharp; gutter: false" style=3D"font-s= ize:12px;"> ... '--- A 2-D rectangular array of values '--- This is a "transposed" array with columns in the f= irst '--- dimension and rows in the second Dim data(,) As Object =3D { _ {"Knoxville", "Boston", _ "Washington", "Seattle", _ "Chicago", "New York", _ "Atlanta", "Los Angeles", _ "Houston"}, _ {"Tennessee", "Massachusetts", _ "DC", "Washington", _ "Illinois", "New York", _ "Georgia", "California", _ "Texas"} _ } '--- names array, elements correspond to merge field names Dim names() As String =3D {"City", "State"} Dim wt As New WordTemplate() wt.Open(Server.MapPath("template/MergeFieldTest.doc")) '--- Set the mail merge '--- The data source is the 2-D rectangular data array '--- MaxRows is set to ALL_ROWS, which allows all rows to be impo= rted '--- Transpose is set to true to handle the transposed array wt.SetMailMerge(data, names, WordTemplate.ALL_ROWS, True) wt.Process() wt.Save(Page.Response, "output.doc", False) </pre>=20 </div> </div> </div> </body> </html> ------=_Part_9570_1480952570.1711695175440--