MailMergeExecuteADO Method |
Namespace: Aspose.Words.MailMerging
This method is useful when you intend to use Aspose.Words classes as COM objects from unmanaged code such as an application built using ASP or Visual Basic 6.0.
This method ignores the RemoveUnusedRegions option.
For more information see description of MailMerge.Execute(DataTable).
[VBScript] Dim RS Set RS = CreateObject("ADODB.Recordset") RS.Open _ "SELECT TOP 50 * FROM Customers ORDER BY Country, CompanyName", _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Northwind.mdb" Dim License Set License = CreateObject("Aspose.Words.License") License.SetLicense "C:\MyPath\MyLicense.lic" Dim Helper Set Helper = CreateObject("Aspose.Words.ComHelper") Dim Doc Set Doc = Helper.Open("CustomerLabels.doc") Doc.MailMerge.ExecuteADO RS Doc.Save "C:\MyPath\CustomerLabels Out VBScript.doc"
public void ExecuteADO() { // Create a document that will be merged Document doc = CreateSourceDocADOMailMerge(); // To work with ADO DataSets, we need to add a reference to the Microsoft ActiveX Data Objects library, // which is included in the .NET distribution and stored in "adodb.dll", then create a connection ADODB.Connection connection = new ADODB.Connection(); // Create a connection string which points to the "Northwind" database file in our local file system and open a connection string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DatabaseDir + "Northwind.mdb"; connection.Open(connectionString); // Create a record set ADODB.Recordset recordset = new ADODB.Recordset(); // Run an SQL command on the database we are connected to to populate our dataset // The names of the columns returned here correspond to the values of the MERGEFIELDS that will accomodate our data string command = @"SELECT ProductName, QuantityPerUnit, UnitPrice FROM Products"; recordset.Open(command, connection); // Execute the mail merge and save the document doc.MailMerge.ExecuteADO(recordset); doc.Save(ArtifactsDir + "MailMerge.ExecuteADO.docx"); } /// <summary> /// Create a blank document and populate it with MERGEFIELDS that will accept data when a mail merge is executed. /// </summary> private static Document CreateSourceDocADOMailMerge() { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Write("Product:\t"); builder.InsertField(" MERGEFIELD ProductName"); builder.Writeln(); builder.InsertField(" MERGEFIELD QuantityPerUnit"); builder.Write(" for $"); builder.InsertField(" MERGEFIELD UnitPrice"); return doc; }