Message-ID: <134090961.9963.1711707704079.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_9962_1472593748.1711707704079" ------=_Part_9962_1472593748.1711707704079 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html WordTemplate.SetMailMerge(Object()(), String())

WordTemplate.SetMailMerge(Object()(), String())

Description

=20

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 WordTemplate.= EnableNEXTFields property is set to true, the NEXT field can also be us= ed to indicate that the next row of data should be inserted instead of the = current row at the next occurence of the merge fields. This should largely = imitate the behavior of a Microsoft Word Mail merge.

=20
C#
=20
 public void SetMailMerge(System.Object[][] jaggedArray, System.String[] co=
lumnNames)
=20
=20
vb.net
=20
Public Sub SetMailMerge(ByVal jaggedArray As Object()(), ByVal columnNames =
As String())
=20
=20

Parame= ters

=20
jagge= dArray
The jagged array (array-of-arrays) to use as the data source.= =20
colum= nNames
The one-dimensional array of strings that represent the field n= ames to be replaced by the data. These names must match the column names fr= om your data source.=20

Except= ions

=20
ArgumentNullException
=20 Save will = throw this exception if=20 null (C#) or=20 Nothing (VB.NET) is passed to the method.=20
ArgumentException
=20

Remarks=20

You can call SetMailMerge once for each instance of WordTemplate. If you are using the Wo= rd 2003 binary template file type (.doc/.dot), you can call SetMailMerge or= SetRepeatBlock, but not both.

=20

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.&= nbsp; Alternatively, you can create a hidden page break at the top of the p= age as follows:

=20 =20

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 («fieldname») and field ordinals («#1»).

=20

Introduced in build 8.2

=20

Set= MailMerge will now work with headers and footers. A section break is re= quired instead of a page break if each header or footer will be different.<= /p>=20

Examples=

=20
C#
=20

          ...
          //--- A 2-D jagged array of values
          object[][] data =3D new object[][]{
               new string[]{"Knoxville","Tennessee"},
               new string[]{"Boston","Massachusetts"},
               new string[]{"Washington","DC"},
               new string[]{"Seattle","Washington"},
               new string[]{"Chicago", "Illinois"},
               new string[]{"New York","New York"},
               new string[]{"Atlanta", "Georgia"},
               new string[]{"Los Angeles", "California"=
},
               new string[]{"Houston", "Texas"}
               };

          //--- Names array, elements correspond to merge field names
          string[] names =3D new string[]{"City", "State&quo=
t;};
          WordTemplate wt =3D new WordTemplate();
          wt.Open(Server.MapPath("template/MergeFieldTest.doc"));

          //--- Set the mail merge
          //--- The data source is the 2-D jagged data array
          wt.SetMailMerge(data, names);
          wt.Process();
          wt.Save(Page.Response, "output.doc", false);
        
=20
=20
vb.net
=20

          ...
          '--- A 2-D jagged array of values
          Dim data()() As Object =3D { _
               New Object() {"Knoxville", "Tennessee"},=
 _
               New Object() {"Boston", "Massachusetts"}=
, _
               New Object() {"Washington", "DC"}, _
               New Object() {"Seattle", "Washington"}, =
_
               New Object() {"Chicago", "Illinois"}, _
               New Object() {"New York", "New York"}, _
               New Object() {"Atlanta", "Georgia"}, _
               New Object() {"Los Angeles", "California"=
;}, _
               New Object() {"Houston", "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 jagged data array
          wt.SetMailMerge(data, names)
          wt.Process()
          wt.Save(Page.Response, "output.doc", False)
          ...
        
=20

------=_Part_9962_1472593748.1711707704079--