Message-ID: <1568677660.8715.1711657595476.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_8714_1030839487.1711657595476" ------=_Part_8714_1030839487.1711657595476 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.
=20public void SetMailMerge(System.Data.DataSet ds)=20
Public Sub SetMailMerge(ByVal ds As System.Data.DataSet)=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
//--- Create connection string for Excel file data string connString =3D "Provider=3DMicrosoft.Jet.OLEDB.4.0;" + "Data Source=3D" + Server.MapPath("data/MailM= ergeData.xls") + ";" + "Extended Properties=3DExcel 8.0;"; //--- Use OleDb to get all data from Sheet1 of the MailMergeData.= xls spreadsheet OleDbConnection conn =3D new OleDbConnection(connString); conn.Open(); OleDbCommand cmd =3D new OleDbCommand("SELECT * FROM [Sheet1= $]", conn); OleDbDataAdapter adapter =3D new OleDbDataAdapter(); adapter.SelectCommand =3D cmd; //--- Dump the data into a DataSet DataSet ds =3D new DataSet(); adapter.Fill(ds); WordTemplate wt =3D new WordTemplate(); wt.Open(Server.MapPath("template/MergeFieldTest.doc")); //--- Set the mail merge //--- The data source is the DataSet wt.SetMailMerge(ds); wt.Process(); wt.Save(Page.Response, "output.doc", false);=20
'--- Create connection string for Excel file data Dim connString As String =3D _ "Provider=3DMicrosoft.Jet.OLEDB.4.0;" & _ "Data Source=3D" & Server.MapPath("data/M= ailMergeData.xls") + ";" & _ "Extended Properties=3DExcel 8.0;" '--- Use OleDb to get all data from Sheet1 of the MailMergeData.x= ls spreadsheet Dim conn As New OleDbConnection(connString) conn.Open() Dim cmd As New OleDbCommand("SELECT * FROM [Sheet1$]", = conn) Dim adapter As New OleDbDataAdapter() adapter.SelectCommand =3D cmd '--- Dump the data into a DataSet Dim ds As New DataSet() adapter.Fill(ds) Dim wt As New WordTemplate() wt.Open(Server.MapPath("template\MergeFieldTest.doc")) '--- Set the mail merge '--- The data source is the DataSet wt.SetMailMerge(ds) wt.Process() wt.Save(Page.Response, "output.doc", False)=20