Beispiel #1
0
        [Test] //ExSkip
        public void MailMergeCustomDataSourceRoot()
        {
            // Create a document with two mail merge regions named "Washington" and "Seattle"
            Document doc = CreateSourceDocumentWithMailMergeRegions(new string[] { "Washington", "Seattle" });

            // Create two data sources
            EmployeeList employeesWashingtonBranch = new EmployeeList();

            employeesWashingtonBranch.Add(new Employee("John Doe", "Sales"));
            employeesWashingtonBranch.Add(new Employee("Jane Doe", "Management"));

            EmployeeList employeesSeattleBranch = new EmployeeList();

            employeesSeattleBranch.Add(new Employee("John Cardholder", "Management"));
            employeesSeattleBranch.Add(new Employee("Joe Bloggs", "Sales"));

            // Register our data sources by name in a data source root
            DataSourceRoot sourceRoot = new DataSourceRoot();

            sourceRoot.RegisterSource("Washington", new EmployeeListMailMergeSource(employeesWashingtonBranch));
            sourceRoot.RegisterSource("Seattle", new EmployeeListMailMergeSource(employeesSeattleBranch));

            // Since we have consecutive mail merge regions, we would normally have to perform two mail merges
            // However, one mail merge source data root call every relevant data source and merge automatically
            doc.MailMerge.ExecuteWithRegions(sourceRoot);

            doc.Save(ArtifactsDir + "MailMerge.MailMergeCustomDataSourceRoot.docx");
        }
Beispiel #2
0
        [Test] //ExSkip
        public void CustomDataSourceRoot()
        {
            // Create a document with two mail merge regions named "Washington" and "Seattle".
            string[] mailMergeRegions = { "Vancouver", "Seattle" };
            Document doc = CreateSourceDocumentWithMailMergeRegions(mailMergeRegions);

            // Create two data sources for the mail merge.
            EmployeeList employeesWashingtonBranch = new EmployeeList();

            employeesWashingtonBranch.Add(new Employee("John Doe", "Sales"));
            employeesWashingtonBranch.Add(new Employee("Jane Doe", "Management"));

            EmployeeList employeesSeattleBranch = new EmployeeList();

            employeesSeattleBranch.Add(new Employee("John Cardholder", "Management"));
            employeesSeattleBranch.Add(new Employee("Joe Bloggs", "Sales"));

            // Register our data sources by name in a data source root.
            //  If we are about to use this data source root in a mail merge with regions,
            // each source's registered name must match the name of an existing mail merge region in the mail merge source document.
            DataSourceRoot sourceRoot = new DataSourceRoot();

            sourceRoot.RegisterSource(mailMergeRegions[0], new EmployeeListMailMergeSource(employeesWashingtonBranch));
            sourceRoot.RegisterSource(mailMergeRegions[1], new EmployeeListMailMergeSource(employeesSeattleBranch));

            // Since we have consecutive mail merge regions, we would normally have to perform two mail merges.
            // However, one mail merge source with a data root can fill in multiple regions
            // if the root contains tables with corresponding names/column names.
            doc.MailMerge.ExecuteWithRegions(sourceRoot);

            doc.Save(ArtifactsDir + "MailMergeCustom.CustomDataSourceRoot.docx");
            TestCustomDataSourceRoot(mailMergeRegions, sourceRoot, new Document(ArtifactsDir + "MailMergeCustom.CustomDataSourceRoot.docx")); //ExSkip
        }