Ejemplo n.º 1
0
        public void MailMergeCustomDataSource()
        {
            // Create some data that we will use in the mail merge.
            CustomerList customers = new CustomerList();

            customers.Add(new Customer("Thomas Hardy", "120 Hanover Sq., London"));
            customers.Add(new Customer("Paolo Accorti", "Via Monte Bianco 34, Torino"));

            // Create some data for nesting in the mail merge.
            customers[0].Orders.Add(new Order("Rugby World Cup Cap", 2));
            customers[0].Orders.Add(new Order("Rugby World Cup Ball", 1));
            customers[1].Orders.Add(new Order("Rugby World Cup Guide", 1));

            // Open the template document.
            Document doc = new Document(MyDir + "NestedMailMerge.CustomDataSource.doc");

            // To be able to mail merge from your own data source, it must be wrapped
            // into an object that implements the IMailMergeDataSource interface.
            CustomerMailMergeDataSource customersDataSource = new CustomerMailMergeDataSource(customers);

            // Now you can pass your data source into Aspose.Words.
            doc.MailMerge.ExecuteWithRegions(customersDataSource);

            doc.Save(MyDir + @"\Artifacts\NestedMailMerge.CustomDataSource.doc");
        }
        public void MailMergeCustomDataSource()
        {
            //ExStart
            //ExFor:IMailMergeDataSource
            //ExFor:IMailMergeDataSource.TableName
            //ExFor:IMailMergeDataSource.MoveNext
            //ExFor:IMailMergeDataSource.GetValue
            //ExFor:IMailMergeDataSource.GetChildDataSource
            //ExFor:MailMerge.Execute(IMailMergeDataSource)
            //ExSummary:Performs mail merge from a custom data source.
            // Create some data that we will use in the mail merge.
            CustomerList customers = new CustomerList();

            customers.Add(new Customer("Thomas Hardy", "120 Hanover Sq., London"));
            customers.Add(new Customer("Paolo Accorti", "Via Monte Bianco 34, Torino"));

            // Open the template document.
            Document doc = new Document(MyDir + "MailMerge.CustomDataSource.doc");

            // To be able to mail merge from your own data source, it must be wrapped
            // into an object that implements the IMailMergeDataSource interface.
            CustomerMailMergeDataSource customersDataSource = new CustomerMailMergeDataSource(customers);

            // Now you can pass your data source into Aspose.Words.
            doc.MailMerge.Execute(customersDataSource);

            doc.Save(MyDir + @"\Artifacts\MailMerge.CustomDataSource.doc");
        }
        public static void Run()
        {
            //ExStart:NestedMailMergeCustom
            // The path to the documents directory.
            string dataDir  = RunExamples.GetDataDir_MailMergeAndReporting();
            string fileName = "NestedMailMerge.CustomDataSource.doc";
            // Create some data that we will use in the mail merge.
            CustomerList customers = new CustomerList();

            customers.Add(new Customer("Thomas Hardy", "120 Hanover Sq., London"));
            customers.Add(new Customer("Paolo Accorti", "Via Monte Bianco 34, Torino"));

            // Create some data for nesting in the mail merge.
            customers[0].Orders.Add(new Order("Rugby World Cup Cap", 2));
            customers[0].Orders.Add(new Order("Rugby World Cup Ball", 1));
            customers[1].Orders.Add(new Order("Rugby World Cup Guide", 1));

            // Open the template document.
            Document doc = new Document(dataDir + fileName);

            // To be able to mail merge from your own data source, it must be wrapped
            // into an object that implements the IMailMergeDataSource interface.
            CustomerMailMergeDataSource customersDataSource = new CustomerMailMergeDataSource(customers);

            // Now you can pass your data source into Aspose.Words.
            doc.MailMerge.ExecuteWithRegions(customersDataSource);

            dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
            doc.Save(dataDir);
            //ExEnd:NestedMailMergeCustom

            Console.WriteLine("\nMail merge performed with nested custom data successfully.\nFile saved at " + dataDir);
        }
        public static void Run()
        {
            // ExStart:NestedMailMergeCustom
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_MailMergeAndReporting();
            string fileName = "NestedMailMerge.CustomDataSource.doc";
            // Create some data that we will use in the mail merge.
            CustomerList customers = new CustomerList();
            customers.Add(new Customer("Thomas Hardy", "120 Hanover Sq., London"));
            customers.Add(new Customer("Paolo Accorti", "Via Monte Bianco 34, Torino"));

            // Create some data for nesting in the mail merge.
            customers[0].Orders.Add(new Order("Rugby World Cup Cap", 2));
            customers[0].Orders.Add(new Order("Rugby World Cup Ball", 1));
            customers[1].Orders.Add(new Order("Rugby World Cup Guide", 1));

            // Open the template document.
            Document doc = new Document(dataDir + fileName);

            // To be able to mail merge from your own data source, it must be wrapped
            // Into an object that implements the IMailMergeDataSource interface.
            CustomerMailMergeDataSource customersDataSource = new CustomerMailMergeDataSource(customers);

            // Now you can pass your data source into Aspose.Words.
            doc.MailMerge.ExecuteWithRegions(customersDataSource);          

            dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
            doc.Save(dataDir);
            // ExEnd:NestedMailMergeCustom

            Console.WriteLine("\nMail merge performed with nested custom data successfully.\nFile saved at " + dataDir);
        }
        [Test] //ExSkip
        public void CustomDataSource()
        {
            // Create a destination document for the mail merge
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.InsertField(" MERGEFIELD FullName ");
            builder.InsertParagraph();
            builder.InsertField(" MERGEFIELD Address ");

            // Create some data that we will use in the mail merge
            CustomerList customers = new CustomerList();

            customers.Add(new Customer("Thomas Hardy", "120 Hanover Sq., London"));
            customers.Add(new Customer("Paolo Accorti", "Via Monte Bianco 34, Torino"));

            // To be able to mail merge from your own data source, it must be wrapped
            // into an object that implements the IMailMergeDataSource interface
            CustomerMailMergeDataSource dataSource = new CustomerMailMergeDataSource(customers);

            // Now you can pass your data source into Aspose.Words
            doc.MailMerge.Execute(dataSource);

            doc.Save(ArtifactsDir + "MailMergeCustom.CustomDataSource.docx");
            TestCustomDataSource(customers, new Document(ArtifactsDir + "MailMergeCustom.CustomDataSource.docx")); //ExSkip
        }
Ejemplo n.º 6
0
        [Test] //ExSkip
        public void CustomDataSource()
        {
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Normally, MERGEFIELDs contain the name of a column of a mail merge data source.
            // Instead, we can use "TableStart:" and "TableEnd:" prefixes to begin/end a mail merge region.
            // Each region will belong to a table with a name that matches the string immediately after the prefix's colon.
            builder.InsertField(" MERGEFIELD TableStart:Customers");

            // These MERGEFIELDs are inside the mail merge region of the "Customers" table.
            // When we execute the mail merge, this field will receive data from rows in a data source named "Customers".
            builder.Write("Full name:\t");
            builder.InsertField(" MERGEFIELD FullName ");
            builder.Write("\nAddress:\t");
            builder.InsertField(" MERGEFIELD Address ");
            builder.Write("\nOrders:\n");

            // Create a second mail merge region inside the outer region for a data source named "Orders".
            // The "Orders" data entries have a many-to-one relationship with the "Customers" data source.
            builder.InsertField(" MERGEFIELD TableStart:Orders");

            builder.Write("\tItem name:\t");
            builder.InsertField(" MERGEFIELD Name ");
            builder.Write("\n\tQuantity:\t");
            builder.InsertField(" MERGEFIELD Quantity ");
            builder.InsertParagraph();

            builder.InsertField(" MERGEFIELD TableEnd:Orders");
            builder.InsertField(" MERGEFIELD TableEnd:Customers");

            // Create related data with names that match those of our mail merge regions.
            CustomerList customers = new CustomerList();

            customers.Add(new Customer("Thomas Hardy", "120 Hanover Sq., London"));
            customers.Add(new Customer("Paolo Accorti", "Via Monte Bianco 34, Torino"));

            customers[0].Orders.Add(new Order("Rugby World Cup Cap", 2));
            customers[0].Orders.Add(new Order("Rugby World Cup Ball", 1));
            customers[1].Orders.Add(new Order("Rugby World Cup Guide", 1));

            // To mail merge from your data source, we must wrap it into an object that implements the IMailMergeDataSource interface.
            CustomerMailMergeDataSource customersDataSource = new CustomerMailMergeDataSource(customers);

            doc.MailMerge.ExecuteWithRegions(customersDataSource);

            doc.Save(ArtifactsDir + "NestedMailMergeCustom.CustomDataSource.docx");
            TestCustomDataSource(customers, new Document(ArtifactsDir + "NestedMailMergeCustom.CustomDataSource.docx")); //ExSkip
        }
        [Test] //ExSkip
        public void CustomDataSource()
        {
            // Create a destination document for the mail merge
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.InsertField(" MERGEFIELD TableStart:Customer");

            builder.Write("Full name:\t");
            builder.InsertField(" MERGEFIELD FullName ");
            builder.Write("\nAddress:\t");
            builder.InsertField(" MERGEFIELD Address ");
            builder.Write("\nOrders:\n");

            builder.InsertField(" MERGEFIELD TableStart:Order");

            builder.Write("\tItem name:\t");
            builder.InsertField(" MERGEFIELD Name ");
            builder.Write("\n\tQuantity:\t");
            builder.InsertField(" MERGEFIELD Quantity ");
            builder.InsertParagraph();

            builder.InsertField(" MERGEFIELD TableEnd:Order");

            builder.InsertField(" MERGEFIELD TableEnd:Customer");

            // Create some data that we will use in the mail merge
            CustomerList customers = new CustomerList();

            customers.Add(new Customer("Thomas Hardy", "120 Hanover Sq., London"));
            customers.Add(new Customer("Paolo Accorti", "Via Monte Bianco 34, Torino"));

            // Create some data for nesting in the mail merge
            customers[0].Orders.Add(new Order("Rugby World Cup Cap", 2));
            customers[0].Orders.Add(new Order("Rugby World Cup Ball", 1));
            customers[1].Orders.Add(new Order("Rugby World Cup Guide", 1));

            // To be able to mail merge from your own data source, it must be wrapped
            // into an object that implements the IMailMergeDataSource interface
            CustomerMailMergeDataSource customersDataSource = new CustomerMailMergeDataSource(customers);

            // Now you can pass your data source into Aspose.Words
            doc.MailMerge.ExecuteWithRegions(customersDataSource);

            doc.Save(ArtifactsDir + "NestedMailMergeCustom.CustomDataSource.docx");
            TestCustomDataSource(customers, new Document(ArtifactsDir + "NestedMailMergeCustom.CustomDataSource.docx")); //ExSkip
        }
        public void CustomMailMerge()
        {
            //ExStart:NestedMailMergeCustom
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.InsertField(" MERGEFIELD TableStart:Customer");

            builder.Write("Full name:\t");
            builder.InsertField(" MERGEFIELD FullName ");
            builder.Write("\nAddress:\t");
            builder.InsertField(" MERGEFIELD Address ");
            builder.Write("\nOrders:\n");

            builder.InsertField(" MERGEFIELD TableStart:Order");

            builder.Write("\tItem name:\t");
            builder.InsertField(" MERGEFIELD Name ");
            builder.Write("\n\tQuantity:\t");
            builder.InsertField(" MERGEFIELD Quantity ");
            builder.InsertParagraph();

            builder.InsertField(" MERGEFIELD TableEnd:Order");

            builder.InsertField(" MERGEFIELD TableEnd:Customer");

            List <Customer> customers = new List <Customer>
            {
                new Customer("Thomas Hardy", "120 Hanover Sq., London"),
                new Customer("Paolo Accorti", "Via Monte Bianco 34, Torino")
            };

            customers[0].Orders.Add(new Order("Rugby World Cup Cap", 2));
            customers[0].Orders.Add(new Order("Rugby World Cup Ball", 1));
            customers[1].Orders.Add(new Order("Rugby World Cup Guide", 1));

            // To be able to mail merge from your data source,
            // it must be wrapped into an object that implements the IMailMergeDataSource interface.
            CustomerMailMergeDataSource customersDataSource = new CustomerMailMergeDataSource(customers);

            doc.MailMerge.ExecuteWithRegions(customersDataSource);

            doc.Save(ArtifactsDir + "NestedMailMergeCustom.CustomMailMerge.docx");
            //ExEnd:NestedMailMergeCustom
        }
        //ExStart
        //ExFor:IMailMergeDataSource
        //ExFor:IMailMergeDataSource.TableName
        //ExFor:IMailMergeDataSource.MoveNext
        //ExFor:IMailMergeDataSource.GetValue
        //ExFor:IMailMergeDataSource.GetChildDataSource
        //ExFor:MailMerge.Execute(IMailMergeDataSource)
        //ExSummary:Performs mail merge from a custom data source.
        public void MailMergeCustomDataSource()
        {
            // Create some data that we will use in the mail merge.
            CustomerList customers = new CustomerList();
            customers.Add(new Customer("Thomas Hardy", "120 Hanover Sq., London"));
            customers.Add(new Customer("Paolo Accorti", "Via Monte Bianco 34, Torino"));

            // Open the template document.
            Document doc = new Document(MyDir + "MailMerge.CustomDataSource.doc");

            // To be able to mail merge from your own data source, it must be wrapped
            // into an object that implements the IMailMergeDataSource interface.
            CustomerMailMergeDataSource customersDataSource = new CustomerMailMergeDataSource(customers);

            // Now you can pass your data source into Aspose.Words.
            doc.MailMerge.Execute(customersDataSource);

            doc.Save(MyDir + @"\Artifacts\MailMerge.CustomDataSource.doc");
        }
Ejemplo n.º 10
0
        //ExStart
        //ExFor:IMailMergeDataSource
        //ExFor:IMailMergeDataSource.TableName
        //ExFor:IMailMergeDataSource.MoveNext
        //ExFor:IMailMergeDataSource.GetValue
        //ExFor:IMailMergeDataSource.GetChildDataSource
        //ExFor:MailMerge.Execute(IMailMergeDataSource)
        //ExSummary:Performs mail merge from a custom data source.
        public void MailMergeCustomDataSource()
        {
            // Create some data that we will use in the mail merge.
            CustomerList customers = new CustomerList();

            customers.Add(new Customer("Thomas Hardy", "120 Hanover Sq., London"));
            customers.Add(new Customer("Paolo Accorti", "Via Monte Bianco 34, Torino"));

            // Open the template document.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "MailMerge.CustomDataSource.doc");

            // To be able to mail merge from your own data source, it must be wrapped
            // into an object that implements the IMailMergeDataSource interface.
            CustomerMailMergeDataSource customersDataSource = new CustomerMailMergeDataSource(customers);

            // Now you can pass your data source into Aspose.Words.
            doc.MailMerge.Execute(customersDataSource);

            doc.Save(MyDir + "MailMerge.CustomDataSource Out.doc");
        }
Ejemplo n.º 11
0
        [Test] //ExSkip
        public void CustomDataSource()
        {
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.InsertField(" MERGEFIELD FullName ");
            builder.InsertParagraph();
            builder.InsertField(" MERGEFIELD Address ");

            CustomerList customers = new CustomerList();

            customers.Add(new Customer("Thomas Hardy", "120 Hanover Sq., London"));
            customers.Add(new Customer("Paolo Accorti", "Via Monte Bianco 34, Torino"));

            // To use a custom object as a data source, it must implement the IMailMergeDataSource interface.
            CustomerMailMergeDataSource dataSource = new CustomerMailMergeDataSource(customers);

            doc.MailMerge.Execute(dataSource);

            doc.Save(ArtifactsDir + "MailMergeCustom.CustomDataSource.docx");
            TestCustomDataSource(customers, new Document(ArtifactsDir + "MailMergeCustom.CustomDataSource.docx")); //ExSkip
        }
        public void MailMergeCustomDataSource()
        {
            // Create some data that we will use in the mail merge.
            CustomerList customers = new CustomerList();
            customers.Add(new Customer("Thomas Hardy", "120 Hanover Sq., London"));
            customers.Add(new Customer("Paolo Accorti", "Via Monte Bianco 34, Torino"));

            // Create some data for nesting in the mail merge.
            customers[0].Orders.Add(new Order("Rugby World Cup Cap", 2));
            customers[0].Orders.Add(new Order("Rugby World Cup Ball", 1));
            customers[1].Orders.Add(new Order("Rugby World Cup Guide", 1));

            // Open the template document.
            Document doc = new Document(MyDir + "NestedMailMerge.CustomDataSource.doc");

            // To be able to mail merge from your own data source, it must be wrapped
            // into an object that implements the IMailMergeDataSource interface.
            CustomerMailMergeDataSource customersDataSource = new CustomerMailMergeDataSource(customers);

            // Now you can pass your data source into Aspose.Words.
            doc.MailMerge.ExecuteWithRegions(customersDataSource);

            doc.Save(MyDir + "NestedMailMerge.CustomDataSource Out.doc");
        }