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
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.E= nableNEXTFields 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.
=20public void SetMailMerge(System.Object[,] table, System.String[] columnNam= es, int maxRows, boolean transpose)=20
Public Sub SetMailMerge(ByVal table As Object(,), ByVal columnNames As Stri= ng(), ByVal maxRows As Integer, ByVal transpose As Boolean)=20
true
, the array is treated as Object[column, row]. If transpos=
e is set to=20
false
, the array is treated as Object[row, column].=20
null
(C#) or=20
Nothing
(VB.NET) is passed to the method.=20
You can call SetMailMerge once for each instance of WordTemplate. If you are using the Word= 2003 binary template file type (.doc/.dot), you can call SetMailMerge or S= etRepeatBlock, but not both.
=20Additionally, 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:
=20Merge 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»).
=20SetM= ailMerge 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
... //--- 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);=20
... '--- 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)=20