示例#1
0
        public AssembleResult AssembleDocument(string templateFile, TextReader xmlData, string outputFile)
        {
            if (!File.Exists(templateFile))
            {
                throw new FileNotFoundException("Template not found in the expected location", templateFile);
            }
            WmlDocument templateDoc     = new WmlDocument(templateFile); // reads the template's bytes into memory
            XElement    data            = xmlData.Peek() == -1 ? new XElement("none") : XElement.Load(xmlData);
            WmlDocument wmlAssembledDoc = DocumentAssembler.AssembleDocument(templateDoc, data, out bool templateError);

            if (templateError)
            {
                Console.WriteLine("Errors in template.");
                Console.WriteLine("See the assembled document to inspect errors.");
            }
            if (!string.IsNullOrEmpty(outputFile))
            {
                //// save the output (even in the case of error, since error messages are in the file)
                wmlAssembledDoc.SaveAs(outputFile);
                return(new AssembleResult(outputFile, templateError));
            }
            else
            {
                return(new AssembleResult(wmlAssembledDoc.DocumentByteArray, templateError));
            }
        }
示例#2
0
        public void DA103_UseXmlDocument(string name, string data, bool err)
        {
            FileInfo templateDocx = new FileInfo(Path.Combine(TestUtil.SourceDir.FullName, name));
            FileInfo dataFile     = new FileInfo(Path.Combine(TestUtil.SourceDir.FullName, data));

            WmlDocument wmlTemplate = new WmlDocument(templateDocx.FullName);
            XmlDocument xmldata     = new XmlDocument();

            xmldata.Load(dataFile.FullName);

            bool        returnedTemplateError;
            WmlDocument afterAssembling = DocumentAssembler.AssembleDocument(wmlTemplate, xmldata, out returnedTemplateError);
            var         assembledDocx   = new FileInfo(Path.Combine(TestUtil.TempDir.FullName, templateDocx.Name.Replace(".docx", "-processed-by-DocumentAssembler.docx")));

            afterAssembling.SaveAs(assembledDocx.FullName);

            using (MemoryStream ms = new MemoryStream())
            {
                ms.Write(afterAssembling.DocumentByteArray, 0, afterAssembling.DocumentByteArray.Length);
                using (WordprocessingDocument wDoc = WordprocessingDocument.Open(ms, true))
                {
                    OpenXmlValidator v = new OpenXmlValidator();
                    var valErrors      = v.Validate(wDoc).Where(ve => !s_ExpectedErrors.Contains(ve.Description));
                    Assert.Equal(0, valErrors.Count());
                }
            }

            Assert.Equal(err, returnedTemplateError);
        }
        private static void Main()
        {
            var n      = DateTime.Now;
            var tempDi = new DirectoryInfo(string.Format("ExampleOutput-{0:00}-{1:00}-{2:00}-{3:00}{4:00}{5:00}", n.Year - 2000, n.Month, n.Day, n.Hour, n.Minute, n.Second));

            tempDi.Create();

            var templateDoc = new FileInfo("../../TemplateDocument.docx");
            var dataFile    = new FileInfo(Path.Combine(tempDi.FullName, "Data.xml"));

            // The following method generates a large data file with random data.
            // In a real world scenario, this is where you would query your data source and produce XML that will drive your document generation process.
            var data = GenerateDataFromDataSource(dataFile);

            var wmlDoc = new WmlDocument(templateDoc.FullName);
            var count  = 1;

            foreach (var customer in data.Elements("Customer"))
            {
                var assembledDoc = new FileInfo(Path.Combine(tempDi.FullName, string.Format("Letter-{0:0000}.docx", count++)));
                Console.WriteLine(assembledDoc.Name);
                var wmlAssembledDoc = DocumentAssembler.AssembleDocument(wmlDoc, customer, out var templateError);
                if (templateError)
                {
                    Console.WriteLine("Errors in template.");
                    Console.WriteLine("See {0} to determine the errors in the template.", assembledDoc.Name);
                }
                wmlAssembledDoc.SaveAs(assembledDoc.FullName);
            }
        }
示例#4
0
        public void Sample2()
        {
            var templateDoc = new FileInfo(GetFilePath("Sample2/TemplateDocument.docx"));
            var dataFile    = new FileInfo(Path.Combine(TempDir, "Data.xml"));

            // The following method generates a large data file with random data.
            // In a real world scenario, this is where you would query your data source and produce XML that will drive your document generation process.
            var      numberOfDocumentsToGenerate = 100;
            XElement data = GenerateDataFromDataSource(dataFile, numberOfDocumentsToGenerate);

            var wmlDoc = new WmlDocument(templateDoc.FullName);
            var count  = 1;

            foreach (var customer in data.Elements("Customer"))
            {
                var assembledDoc = new FileInfo(Path.Combine(TempDir, $"Letter-{count++:0000}.docx"));
                Log.WriteLine("Generating {0}", assembledDoc.Name);
                var wmlAssembledDoc = DocumentAssembler.AssembleDocument(wmlDoc, customer, out var templateError);
                if (templateError)
                {
                    Log.WriteLine("Errors in template.");
                    Log.WriteLine("See {0} to determine the errors in the template.", assembledDoc.Name);
                }
                wmlAssembledDoc.SaveAs(assembledDoc.FullName);

                Log.WriteLine("Converting to HTML {0}", assembledDoc.Name);
                var htmlFileName = ConvertToHtml(assembledDoc.FullName, TempDir);

                Log.WriteLine("Converting back to DOCX {0}", htmlFileName.Name);
                ConvertToDocx(htmlFileName.FullName, TempDir);
            }
        }
示例#5
0
        public void DA101(string name, string data, bool err)
        {
            var sourceDir    = new DirectoryInfo("../../../../TestFiles/");
            var templateDocx = new FileInfo(Path.Combine(sourceDir.FullName, name));
            var dataFile     = new FileInfo(Path.Combine(sourceDir.FullName, data));

            var wmlTemplate = new WmlDocument(templateDocx.FullName);
            var xmldata     = XElement.Load(dataFile.FullName);

            var afterAssembling = DocumentAssembler.AssembleDocument(wmlTemplate, xmldata, out var returnedTemplateError);
            var assembledDocx   = new FileInfo(Path.Combine(TestUtil.TempDir.FullName, templateDocx.Name.Replace(".docx", "-processed-by-DocumentAssembler.docx")));

            afterAssembling.SaveAs(assembledDocx.FullName);

            using (var ms = new MemoryStream())
            {
                ms.Write(afterAssembling.DocumentByteArray, 0, afterAssembling.DocumentByteArray.Length);
                using var wDoc = WordprocessingDocument.Open(ms, true);
                var v         = new OpenXmlValidator();
                var valErrors = v.Validate(wDoc).Where(ve => !s_ExpectedErrors.Contains(ve.Description));

                var sb = new StringBuilder();
                foreach (var item in valErrors.Select(r => r.Description).OrderBy(t => t).Distinct())
                {
                    sb.Append(item).Append(Environment.NewLine);
                }
                var z = sb.ToString();
                Console.WriteLine(z);

                Assert.Empty(valErrors);
            }

            Assert.Equal(err, returnedTemplateError);
        }
        static void Main(string[] args)
        {
            //CommonUtilities.ProductLicense();

            string folderName = "ExcelTemplates";
            string fileName = "Common List.xlsx";
            string dataSourceName = "customers";
            string updatedFileName = CommonUtilities.ChangeFileName(fileName);

            try
            {
                DocumentAssembler assembler = new DocumentAssembler();
                assembler.AssembleDocument(CommonUtilities.DocumentSourceFolderPath(fileName, folderName), CommonUtilities.DocumentOutputFolderPath(updatedFileName, folderName), DataLayer.PopulateData(), dataSourceName);
            }
            catch (Exception ex)
            {
                
                Console.WriteLine(ex.Message);
            }
           
            //If dataSourceName is products call ProductsData data source 
            //If dataSourceName is orders call OrdersData data source 
            //If dataSourceName is customers call PopulateData data source
            //If dataSourceName is customer call CustomerData data source
        }
        private void button5_Click(object sender, EventArgs e)
        {
            //Setting up source word template
            FileStream template = File.OpenRead("../../../../Data/Samples/Source/Expense Sheet.docx");
            //Setting up destination word report
            FileStream output = File.Create("../../../../Data/Samples/Destination/Expense Sheet Report.docx");

            //Generate the report
            DocumentAssembler doc = new DocumentAssembler();

            //Beside data source and output path it takes dataSourceObject and dataSourceString
            doc.AssembleDocument(template, output, GenerateReport(), "ExpenseDetails");
        }
示例#8
0
        public void DA102_Throws(string name, string data, bool err)
        {
            FileInfo templateDocx = new FileInfo(Path.Combine(TestUtil.SourceDir.FullName, name));
            FileInfo dataFile     = new FileInfo(Path.Combine(TestUtil.SourceDir.FullName, data));

            WmlDocument wmlTemplate = new WmlDocument(templateDocx.FullName);
            XElement    xmldata     = XElement.Load(dataFile.FullName);

            bool        returnedTemplateError;
            WmlDocument afterAssembling;

            Assert.Throws <OpenXmlPowerToolsException>(() =>
            {
                afterAssembling = DocumentAssembler.AssembleDocument(wmlTemplate, xmldata, out returnedTemplateError);
            });
        }
 //ExStart:GenerateReportShowcase
 /// <summary>
 /// Generates the report by using dataset.
 /// </summary>
 /// <param name="ds"></param>
 public void GenerateReportDB(DataSet ds)
 {
     try
     {
         License lic = new License();
         //lic.SetLicense(_LicensePath);
         //Instantiate DocumentAssembler class
         DocumentAssembler assembler = new DocumentAssembler();
         //Call AssembleDocument to generate Common List Report in open document format
         assembler.AssembleDocument(_TemplateSourcePath, _ReportDestinationPath, ds);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public void DA101(string name, string data, bool err)
        {
            var templateDocx = new FileInfo(Path.Combine(_sourceDir.FullName, name));
            var dataFile     = new FileInfo(Path.Combine(_sourceDir.FullName, data));

            var wmlTemplate = new WmlDocument(templateDocx.FullName);
            var xmldata     = XElement.Load(dataFile.FullName);

            var afterAssembling = DocumentAssembler.AssembleDocument(wmlTemplate, xmldata, out var returnedTemplateError);
            var assembledDocx   = new FileInfo(Path.Combine(TempDir, templateDocx.Name.Replace(".docx", "-processed-by-DocumentAssembler.docx")));

            afterAssembling.SaveAs(assembledDocx.FullName);

            Validate(assembledDocx);
            Assert.Equal(err, returnedTemplateError);
        }
示例#11
0
        public void DA102_Throws(string name, string data)
        {
            var sourceDir    = new DirectoryInfo("../../../../TestFiles/");
            var templateDocx = new FileInfo(Path.Combine(sourceDir.FullName, name));
            var dataFile     = new FileInfo(Path.Combine(sourceDir.FullName, data));

            var wmlTemplate = new WmlDocument(templateDocx.FullName);
            var xmldata     = XElement.Load(dataFile.FullName);

            WmlDocument afterAssembling;

            Assert.Throws <OpenXmlPowerToolsException>(() =>
            {
                afterAssembling = DocumentAssembler.AssembleDocument(wmlTemplate, xmldata, out var returnedTemplateError);
            });
        }
 //ExStart:GenerateReportShowcase
 /// <summary>
 /// Generates the report by using dataset.
 /// </summary>
 /// <param name="ds"></param>
 public void GenerateReportDB(DataSet ds)
 {
     try
     {
         License lic = new License();
         //lic.SetLicense(_LicensePath);
         //Instantiate DocumentAssembler class
         DocumentAssembler assembler = new DocumentAssembler();
         //Call AssembleDocument to generate Common List Report in open document format
         assembler.AssembleDocument(_TemplateSourcePath, _ReportDestinationPath, ds);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#13
0
            static void Main2(string[] args)
            {
                if (args.Length != 3)
                {
                    PrintUsage();
                    Environment.Exit(0);
                }

                FileInfo templateDoc = new FileInfo(args[0]);

                if (!templateDoc.Exists)
                {
                    Console.WriteLine("Error, {0} does not exist.", args[0]);
                    PrintUsage();
                    Environment.Exit(0);
                }
                FileInfo dataFile = new FileInfo(args[1]);

                if (!dataFile.Exists)
                {
                    Console.WriteLine("Error, {0} does not exist.", args[1]);
                    PrintUsage();
                    Environment.Exit(0);
                }
                FileInfo assembledDoc = new FileInfo(args[2]);

                if (assembledDoc.Exists)
                {
                    Console.WriteLine("Error, {0} exists.", args[2]);
                    PrintUsage();
                    Environment.Exit(0);
                }

                WmlDocument wmlDoc = new WmlDocument(templateDoc.FullName);
                XElement    data   = XElement.Load(dataFile.FullName);
                bool        templateError;
                WmlDocument wmlAssembledDoc = DocumentAssembler.AssembleDocument(wmlDoc, data, out templateError);

                if (templateError)
                {
                    Console.WriteLine("Errors in template.");
                    Console.WriteLine("See {0} to determine the errors in the template.", assembledDoc.Name);
                }

                wmlAssembledDoc.SaveAs(assembledDoc.FullName);
            }
示例#14
0
        private WmlDocument GenerateDoc(XElement dataXML)
        {
            FileInfo    docTemplate = new FileInfo(this.TemplatePath);
            WmlDocument wmlDoc      = new WmlDocument(docTemplate.FullName);

            bool        templateError;
            WmlDocument wmlAssembledDoc = DocumentAssembler.AssembleDocument(wmlDoc, dataXML, out templateError);

            //wmlAssembledDoc.SaveAs(documentoGerado.FullName);

            //if (templateError)
            //{
            //    throw new Exception("Errors in template.",
            //        new Exception(String.Format("Check {0} to determinate the error in template.", wmlAssembledDoc.FileName)));
            //}

            return(wmlAssembledDoc);
        }
        static void Main(string[] args)
        {
            //Setting up source open presentation template
            FileStream template = File.OpenRead("../../../../../Data/Samples/Source/Common List.docx");
            //Setting up destination open presentation report
            FileStream output = File.Create("../../../../../Data/Samples/Destination/Xml Common List.docx");

            try
            {
                //Instantiate DocumentAssembler class
                DocumentAssembler assembler = new DocumentAssembler();
                //Call AssembleDocument to generate Bulleted List Report in open presentation format
                assembler.AssembleDocument(template, output, GetCustomListData(), "ds");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
示例#16
0
        /// <summary>
        /// Generate final word document starting from a Template and xml data informations.
        /// </summary>
        /// <param name="currentDate">current Date used in genetayed file name.</param>
        /// <param name="temporaryFolder">use a folder to keep files</param>
        /// <param name="templateDocument">the template document</param>
        /// <param name="openXmlPowerToolsWmlDocument">an object from powerTools</param>
        /// <param name="data">xml data file</param>
        /// <returns>true or false</returns>
        private static bool Generate(DateTime currentDate, DirectoryInfo temporaryFolder, FileInfo templateDocument, WmlDocument openXmlPowerToolsWmlDocument, XElement data)
        {
            bool        errors;
            WmlDocument wmlAssembledDoc = DocumentAssembler.AssembleDocument(openXmlPowerToolsWmlDocument, data, out errors);

            if (errors)
            {
                return(true);
            }

            try
            {
                FileInfo generatedDocument = new FileInfo(Path.Combine(temporaryFolder.FullName, string.Format("GeneratedFromTemplate{0:00}-{1:00}-{2:00}-{3:00}{4:00}{5:00}.docx", currentDate.Year, currentDate.Month, currentDate.Day, currentDate.Hour, currentDate.Minute, currentDate.Second)));
                wmlAssembledDoc.SaveAs(generatedDocument.FullName);
            }
            catch (Exception)
            {
                return(true);
            }


            return(errors);
        }
        public void DA101_DocumentAssembler(string templateDocumentName, string dataFileName, bool templateError)
        {
            FileInfo templateDocx = new FileInfo(Path.Combine(TestUtil.SourceDir.FullName, templateDocumentName));
            FileInfo dataFile     = new FileInfo(Path.Combine(TestUtil.SourceDir.FullName, dataFileName));

            WmlDocument wmlTemplate = new WmlDocument(templateDocx.FullName);
            XElement    data        = XElement.Load(dataFile.FullName);

            bool        returnedTemplateError;
            WmlDocument afterAssembling = DocumentAssembler.AssembleDocument(wmlTemplate, data, out returnedTemplateError);
            var         assembledDocx   = new FileInfo(Path.Combine(TestUtil.TempDir.FullName, templateDocx.Name.Replace(".docx", "-processed-by-DocumentAssembler.docx")));

            afterAssembling.SaveAs(assembledDocx.FullName);

            using (MemoryStream ms = new MemoryStream())
            {
                ms.Write(afterAssembling.DocumentByteArray, 0, afterAssembling.DocumentByteArray.Length);
                using (WordprocessingDocument wDoc = WordprocessingDocument.Open(ms, true))
                {
                    OpenXmlValidator v = new OpenXmlValidator();
                    var valErrors      = v.Validate(wDoc).Where(ve => !s_ExpectedErrors.Contains(ve.Description));

#if false
                    StringBuilder sb = new StringBuilder();
                    foreach (var item in valErrors.Select(r => r.Description).OrderBy(t => t).Distinct())
                    {
                        sb.Append(item).Append(Environment.NewLine);
                    }
                    string z = sb.ToString();
#endif

                    Assert.Equal(0, valErrors.Count());
                }
            }

            Assert.Equal(templateError, returnedTemplateError);
        }
示例#18
0
        public void AddSalesOrder(Action <DocumentAssembler> document)
        {
            var documentAssembler = new DocumentAssembler();

            document(documentAssembler);

            _currentDocId++;

            var items = documentAssembler.DocumentItemAssemblers;

            var salesOrderItems = new List <SalesOrderItemEntity>();

            foreach (var item in items)
            {
                var prodId = _productsTable.Get(item.Name);

                salesOrderItems.Add(
                    new SalesOrderItemEntity()
                {
                    ProductInfo = prodId.Info,
                    ProductName = item.Name,
                    Price       = item.Price,
                    Quantity    = item.Quantity,
                    Value       = item.Price * item.Quantity
                });
            }

            var salesOrderEntity = new SalesOrderEntity()
            {
                Id    = _currentDocId,
                Items = salesOrderItems,
                Value = salesOrderItems.Sum(x => x.Value)
            };

            SalesOrderEntities.Add(salesOrderEntity.Id);
            _mocks.SalesOrderRepository.Get(salesOrderEntity.Id).Returns(salesOrderEntity);
        }
        public async Task <Hashtable> Assemble(string jid, string templateFilename, string datasourceFilename, string assembledFilename, string datasourceName = null, int datasourceTableIndex = 0)
        {
            DocumentAssembler assembler = new DocumentAssembler();

            assembler.Options = DocumentAssemblyOptions.AllowMissingMembers;

            DataSourceInfo source = new DataSourceInfo();

            source.DataSource = new GroupDocs.Assembly.Data.DocumentTable(
                Path.Combine(AppSettings.WorkingDirectory, jid, datasourceFilename),
                datasourceTableIndex,
                new DocumentTableOptions()
            {
                FirstRowContainsColumnNames = true
            }
                );
            source.Name = datasourceName;

            string sourcePath = Path.Combine(AppSettings.WorkingDirectory, jid, templateFilename);
            string targetPath = Path.Combine(AppSettings.WorkingDirectory, jid, assembledFilename);

            await Task.Run(() => {
                using (Stream sourceStream = new FileStream(sourcePath, FileMode.Open))
                {
                    using (Stream targetStream = new FileStream(targetPath, FileMode.Create))
                    {
                        assembler.AssembleDocument(sourceStream, targetStream, source);
                    }
                }
            });

            Hashtable result = new Hashtable();

            result.Add("filename", assembledFilename);
            return(result);
        }
        private static void Main()
        {
            var n      = DateTime.Now;
            var tempDi = new DirectoryInfo(string.Format("ExampleOutput-{0:00}-{1:00}-{2:00}-{3:00}{4:00}{5:00}", n.Year - 2000, n.Month, n.Day, n.Hour, n.Minute, n.Second));

            tempDi.Create();

            var templateDoc = new FileInfo("../../TemplateDocument.docx");
            var dataFile    = new FileInfo("../../Data.xml");

            var wmlDoc          = new WmlDocument(templateDoc.FullName);
            var data            = XElement.Load(dataFile.FullName);
            var wmlAssembledDoc = DocumentAssembler.AssembleDocument(wmlDoc, data, out var templateError);

            if (templateError)
            {
                Console.WriteLine("Errors in template.");
                Console.WriteLine("See AssembledDoc.docx to determine the errors in the template.");
            }

            var assembledDoc = new FileInfo(Path.Combine(tempDi.FullName, "AssembledDoc.docx"));

            wmlAssembledDoc.SaveAs(assembledDoc.FullName);
        }
 public static void GenerateReportLazilyAndRecursively()
 {
     //ExStart:GeneratingReportbyRecursivelyandLazilyAccessingtheData
     //Setting up source open document template
     const String strDocumentTemplate = "Word Templates/Lazy And Recursive.docx";
     //Setting up destination open document report
     const String strDocumentReport = "Word Reports/Lazy And Recursive Report.docx";
     try
     {
         //Instantiate DynamicEntity class
         DynamicEntity dentity = new DynamicEntity(Guid.NewGuid());
         //Instantiate DocumentAssembler class
         DocumentAssembler assembler = new DocumentAssembler();
         //Call AssembleDocument to generate Single Row Report in open document format
         assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate), CommonUtilities.SetDestinationDocument(strDocumentReport), dentity, "root");
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     //ExEnd:GeneratingReportbyRecursivelyandLazilyAccessingtheData
 }
 public static void OuterDocumentInsertion()
 {
     //ExStart:OuterDocumentInsertion
     //Setting up source open document template
     const String strDocumentTemplate = "Word Templates/OuterDocInsertion.odt";
     //Setting up destination open document report
     const String strDocumentReport = "Word Reports/OuterDocInsertion Report.odt";
     try
     {
         //Instantiate DocumentAssembler class
         DocumentAssembler assembler = new DocumentAssembler();
         //Call AssembleDocument to generate  Report in open document format
         assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate), CommonUtilities.SetDestinationDocument(strDocumentReport), DataLayer.GetCustomerData(), "customer");
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     //ExEnd:OuterDocumentInsertion
 }
 public static void TemplateSyntaxFormatting()
 {
     //ExStart:TemplateSyntaxFormatting
     //Setting up source open document template
     const String strDocumentTemplate = "Word Templates/String_Numeric_Formatting.odt";
     //Setting up destination open document report
     const String strDocumentReport = "Word Reports/String_Numeric_Formatting Report.odt";
     try
     {
         //Instantiate DocumentAssembler class
         DocumentAssembler assembler = new DocumentAssembler();
         //Call AssembleDocument to generate   Report in open document format
         assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate), CommonUtilities.SetDestinationDocument(strDocumentReport), DataLayer.GetOrdersData(), "orders");
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     //ExEnd:TemplateSyntaxFormatting
 }
 /// <summary>
 /// Update word processing documents fields while assembling 
 /// </summary>
 /// <param name="documentType"></param>
 public static void UpdateWordDocFields(string documentType)
 {
     if (documentType == "document")
     {
         //ExStart:UpdateWordDocFields
         //Setting up source document template
         const String strDocumentTemplate = "Word Templates/Update_Field_XML.docx";
         //Setting up destination document report
         const String strDocumentReport = "Word Reports/Update_Field_XML Report.docx";
         DocumentAssembler assembler = new DocumentAssembler();
         assembler.Options |= DocumentAssemblyOptions.UpdateFieldsAndFormulas;
         assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate), CommonUtilities.SetDestinationDocument(strDocumentReport), DataLayer.GetAllDataFromXML(), "ds");
         //ExEnd:UpdateWordDocFields
     }
     else if (documentType == "spreadsheet")
     {
         //ExStart:updateformula
         //Setting up source document template
         const String strDocumentTemplate = "Spreadsheet Templates/Update-Fomula.xlsx";
         //Setting up destination document report
         const String strDocumentReport = "Spreadsheet Reports/Update-Fomula Report.xlsx";
         DocumentAssembler assembler = new DocumentAssembler();
         assembler.Options |= DocumentAssemblyOptions.UpdateFieldsAndFormulas;
         assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate), CommonUtilities.SetDestinationDocument(strDocumentReport), DataLayer.GetAllDataFromXML(), "ds");
         //ExEnd:updateformula
     }
 }
        public static void GenerateCommonList(string strDocumentFormat, bool isDatabase, bool isDataSet, bool isDataSourceXML, bool isJson)
        {
            switch (strDocumentFormat)
            {
                case "document":
                    if (isDatabase)
                    {
                        //ExStart:GenerateCommonListFromDatabaseinOpenDocumentProcessingFormat
                        //Setting up source open document template
                        const String strDocumentTemplate = "Word Templates/Common List_OpenDocument.odt";
                        //Setting up destination open document report
                        const String strDocumentReport = "Word Reports/Common List_DB Report.odt";
                        try
                        {
                            //Instantiate DocumentAssembler class
                            DocumentAssembler assembler = new DocumentAssembler();
                            //Call AssembleDocument to generate Common List Report in open document format
                            assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate), CommonUtilities.SetDestinationDocument(strDocumentReport), DataLayer.GetCustomersDataDB(), "customers");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        //ExEnd:GenerateCommonListFromDatabaseinOpenDocumentProcessingFormat
                    }
                    else if (isDataSet)
                    {
                        //ExStart:GenerateCommonListFromDataSetinOpenDocumentProcessingFormat
                        //Setting up source open document template
                        const String strDocumentTemplate = "Word Templates/Common List_OpenDocument.odt";
                        //Setting up destination open document report
                        const String strDocumentReport = "Word Reports/Common List_DT Report.odt";
                        try
                        {
                            //Instantiate DocumentAssembler class
                            DocumentAssembler assembler = new DocumentAssembler();
                            //Call AssembleDocument to generate Common List Report in open document format
                            assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate), CommonUtilities.SetDestinationDocument(strDocumentReport), DataLayer.GetCustomersAndOrdersDataDT());
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        //ExEnd:GenerateCommonListFromDataSetinOpenDocumentProcessingFormat
                    }
                    else if (isDataSourceXML)
                    {
                        //ExStart:GenerateCommonListFromXMLinOpenDocumentProcessingFormat
                        //Setting up source open document template
                        const String strDocumentTemplate = "Word Templates/Common List_OpenDocument.odt";
                        //Setting up destination open document report
                        const String strDocumentReport = "Word Reports/Common List_XML Report.odt";
                        try
                        {
                            //Instantiate DocumentAssembler class
                            DocumentAssembler assembler = new DocumentAssembler();
                            //Call AssembleDocument to generate Common List Report in open document format
                            assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate), CommonUtilities.SetDestinationDocument(strDocumentReport), DataLayer.GetAllDataFromXML(), "ds");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        //ExEnd:GenerateCommonListFromXMLinOpenDocumentProcessingFormat
                    }
                    else if (isJson)
                    {
                        //ExStart:GenerateCommonListReportFromJsoninOpenWord
                        //setting up source
                        const String strDocumentTemplate = "Word Templates/Common List_OpenDocument.odt";
                        //Setting up destination
                        const String strDocumentReport = "Word Reports/Common List_OpenDocument_Json Report.odt";
                        try
                        {
                            //Instantiate DocumentAssembler class
                            DocumentAssembler assembler = new DocumentAssembler();//initialize object of DocumentAssembler class
                            //Call AssembleDocument to generate Common List report in open document format
                            assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate), CommonUtilities.SetDestinationDocument(strDocumentReport), DataLayer.GetCustomerDataFromJson(), "customers");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        //ExEnd:GenerateCommonListReportFromJsoninOpenWord
                    }
                    else
                    {
                        //ExStart:GenerateCommonListinOpenDocumentProcessingFormat
                        //Setting up source open document template
                        const String strDocumentTemplate = "Word Templates/Common List_OpenDocument.odt";
                        //Setting up destination open document report
                        const String strDocumentReport = "Word Reports/Common List Report.odt";
                        try
                        {
                            //Instantiate DocumentAssembler class
                            DocumentAssembler assembler = new DocumentAssembler();
                            //Call AssembleDocument to generate Common List Report in open document format
                            assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate), CommonUtilities.SetDestinationDocument(strDocumentReport), DataLayer.PopulateData(), "customers");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        //ExEnd:GenerateCommonListinOpenDocumentProcessingFormat
                    }
                    break;

                case "spreadsheet":
                    if (isDatabase)
                    {
                        //ExStart:GenerateCommonListFromDatabaseinOpenSpreadsheetFormat
                        //Setting up source open spreadsheet template
                        const String strSpreadsheetTemplate = "Spreadsheet Templates/Common List_OpenDocument.ods";
                        //Setting up destination open spreadsheet report
                        const String strSpreadsheetReport = "Spreadsheet Reports/Common List_DB Report.ods";
                        try
                        {
                            //Instantiate DocumentAssembler class
                            DocumentAssembler assembler = new DocumentAssembler();
                            //Call AssembleDocument to generate Common List Report in open spreadsheet format
                            assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strSpreadsheetTemplate), CommonUtilities.SetDestinationDocument(strSpreadsheetReport), DataLayer.GetCustomersDataDB(), "customers");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        //ExEnd:GenerateCommonListFromDatabaseinOpenSpreadsheetFormat
                    }
                    else if (isDataSet)
                    {
                        //ExStart:GenerateCommonListFromDataSetinOpenSpreadsheetFormat
                        //Setting up source open spreadsheet template
                        const String strSpreadsheetTemplate = "Spreadsheet Templates/Common List_OpenDocument.ods";
                        //Setting up destination open spreadsheet report
                        const String strSpreadsheetReport = "Spreadsheet Reports/Common List_DT Report.ods";
                        try
                        {
                            //Instantiate DocumentAssembler class
                            DocumentAssembler assembler = new DocumentAssembler();
                            //Call AssembleDocument to generate Common List Report in open spreadsheet format
                            assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strSpreadsheetTemplate), CommonUtilities.SetDestinationDocument(strSpreadsheetReport), DataLayer.GetCustomersAndOrdersDataDT());
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        //ExEnd:GenerateCommonListFromDataSetinOpenSpreadsheetFormat
                    }
                    else if (isDataSourceXML)
                    {
                        //ExStart:GenerateCommonListFromXMLinOpenSpreadsheetFormat
                        //Setting up source open spreadsheet template
                        const String strSpreadsheetTemplate = "Spreadsheet Templates/Common List_OpenDocument.ods";
                        //Setting up destination open spreadsheet report
                        const String strSpreadsheetReport = "Spreadsheet Reports/Common List_XML Report.ods";
                        try
                        {
                            //Instantiate DocumentAssembler class
                            DocumentAssembler assembler = new DocumentAssembler();
                            //Call AssembleDocument to generate Common List Report in open spreadsheet format
                            assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strSpreadsheetTemplate), CommonUtilities.SetDestinationDocument(strSpreadsheetReport), DataLayer.GetAllDataFromXML(), "ds");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        //ExEnd:GenerateCommonListFromXMLinOpenSpreadsheetFormat
                    }
                    else if (isJson)
                    {
                        //ExStart:GenerateCommonListReportFromJsoninOpenSpreadsheet
                        //setting up source
                        const String strDocumentTemplate = "Spreadsheet Templates/Common List_OpenDocument.ods";
                        //Setting up destination
                        const String strDocumentReport = "Spreadsheet Reports/Common List_OpenDocument_Json Report.ods";
                        try
                        {
                            //Instantiate DocumentAssembler class
                            DocumentAssembler assembler = new DocumentAssembler();//initialize object of DocumentAssembler class
                            //Call AssembleDocument to generate Common List report in open spreadsheet format
                            assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate), CommonUtilities.SetDestinationDocument(strDocumentReport), DataLayer.GetCustomerDataFromJson(), "customers");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        //ExEnd:GenerateCommonListReportFromJsoninOpenSpreadsheet
                    }
                    else
                    {
                        //ExStart:GenerateCommonListinOpenSpreadsheetFormat
                        //Setting up source open spreadsheet template
                        const String strSpreadsheetTemplate = "Spreadsheet Templates/Common List_OpenDocument.ods";
                        //Setting up destination open spreadsheet report
                        const String strSpreadsheetReport = "Spreadsheet Reports/Common List Report.ods";
                        try
                        {
                            //Instantiate DocumentAssembler class
                            DocumentAssembler assembler = new DocumentAssembler();
                            //Call AssembleDocument to generate Common List Report in open spreadsheet format
                            assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strSpreadsheetTemplate), CommonUtilities.SetDestinationDocument(strSpreadsheetReport), DataLayer.PopulateData(), "customers");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        //ExEnd:GenerateCommonListinOpenSpreadsheetFormat
                    }
                    break;

                case "presentation":
                    if (isDatabase)
                    {
                        //ExStart:GenerateCommonListFromDatabaseinOpenPresentationFormat
                        //Setting up source open presentation template
                        const String strPresentationTemplate = "Presentation Templates/Common List_OpenDocument.odp";
                        //Setting up destination open presentation report
                        const String strPresentationReport = "Presentation Reports/Common List_DB Report.odp";
                        try
                        {
                            //Instantiate DocumentAssembler class
                            DocumentAssembler assembler = new DocumentAssembler();
                            //Call AssembleDocument to generate Common List Report in open presentation format
                            assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strPresentationTemplate), CommonUtilities.SetDestinationDocument(strPresentationReport), DataLayer.GetCustomersDataDB(), "customers");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        //ExEnd:GenerateCommonListFromDatabaseinOpenPresentationFormat
                    }
                    else if (isDataSet)
                    {
                        //ExStart:GenerateCommonListFromDataSetinOpenPresentationFormat
                        //Setting up source open presentation template
                        const String strPresentationTemplate = "Presentation Templates/Common List_OpenDocument.odp";
                        //Setting up destination open presentation report
                        const String strPresentationReport = "Presentation Reports/Common List_DT Report.odp";
                        try
                        {
                            //Instantiate DocumentAssembler class
                            DocumentAssembler assembler = new DocumentAssembler();
                            //Call AssembleDocument to generate Common List Report in open presentation format
                            assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strPresentationTemplate), CommonUtilities.SetDestinationDocument(strPresentationReport), DataLayer.GetCustomersAndOrdersDataDT());
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        //ExEnd:GenerateCommonListFromDataSetinOpenPresentationFormat
                    }
                    else if (isDataSourceXML)
                    {
                        //ExStart:GenerateCommonListFromXMLinOpenPresentationFormat
                        //Setting up source open presentation template
                        const String strPresentationTemplate = "Presentation Templates/Common List_OpenDocument.odp";
                        //Setting up destination open presentation report
                        const String strPresentationReport = "Presentation Reports/Common List_XML Report.odp";
                        try
                        {
                            //Instantiate DocumentAssembler class
                            DocumentAssembler assembler = new DocumentAssembler();
                            //Call AssembleDocument to generate Common List Report in open presentation format
                            assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strPresentationTemplate), CommonUtilities.SetDestinationDocument(strPresentationReport), DataLayer.GetAllDataFromXML(), "ds");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        //ExEnd:GenerateCommonListFromXMLinOpenPresentationFormat
                    }
                    else if (isJson)
                    {
                        //ExStart:GenerateCommonListReportFromJsoninOpenPresentation
                        //setting up source
                        const String strDocumentTemplate = "Presentation Templates/Common List_OpenDocument.odp";
                        //Setting up destination
                        const String strDocumentReport = "Presentation Reports/Common List_OpenDocument_Json Report.odp";
                        try
                        {
                            //Instantiate DocumentAssembler class
                            DocumentAssembler assembler = new DocumentAssembler();//initialize object of DocumentAssembler class
                            //Call AssembleDocument to generate Common List report in open presentation format
                            assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate), CommonUtilities.SetDestinationDocument(strDocumentReport), DataLayer.GetCustomerDataFromJson(), "customers");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        //ExEnd:GenerateCommonListReportFromJsoninOpenPresentation
                    }
                    else
                    {
                        //ExStart:GenerateCommonListinOpenPresentationFormat
                        //Setting up source open presentation template
                        const String strPresentationTemplate = "Presentation Templates/Common List_OpenDocument.odp";
                        //Setting up destination open presentation report
                        const String strPresentationReport = "Presentation Reports/Common List Report.odp";
                        try
                        {
                            //Instantiate DocumentAssembler class
                            DocumentAssembler assembler = new DocumentAssembler();
                            //Call AssembleDocument to generate Common List Report in open presentation format
                            assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strPresentationTemplate), CommonUtilities.SetDestinationDocument(strPresentationReport), DataLayer.PopulateData(), "customers");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        //ExEnd:GenerateCommonListinOpenPresentationFormat
                    }
                    break;
            }
        }
 /// <summary>
 /// Support for Analogue of Microsoft Word NEXT Field
 /// </summary>
 public static void NextIteration()
 {
     //ExStart:nextiteration
     //Setting up source document template
     const String strDocumentTemplate = "Word Templates/Using Next.docx";
     //Setting up destination document report
     const String strDocumentReport = "Word Reports/Using Next Report.docx";
     try
     {
         //Instantiate DocumentAssembler class
         DocumentAssembler assembler = new DocumentAssembler();
         //Call AssembleDocument to generate Report
         assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate), CommonUtilities.SetDestinationDocument(strDocumentReport), DataLayer.GetAllDataFromXML(), "ds");
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     //ExEnd:nextiteration
 }
        /// <summary>
        /// Generate barcodes
        /// </summary>
        /// <param name="strDocumentFormat"></param>
        public static void AddBarCodes(string strDocumentFormat)
        {
            switch (strDocumentFormat)
            {
                case "document":
                    //ExStart:AddBarCodesDocumentProcessingFormat
                    //Setting up source open document template
                    const String strDocumentTemplate = "Word Templates/Barcode.docx";
                    //Setting up destination open document report
                    const String strDocumentReport = "Word Reports/Barcode.docx";
                    try
                    {
                        //Instantiate DocumentAssembler class
                        DocumentAssembler assembler = new DocumentAssembler();
                        //Call AssembleDocument to generate   Report in open document format
                        assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate), CommonUtilities.SetDestinationDocument(strDocumentReport), DataLayer.GetCustomerData(), "customer");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    //ExEnd:AddBarCodesDocumentProcessingFormat
                    break;

                case "spreadsheet":
                    //ExStart:AddBarCodesSpreadsheet
                    //Setting up source open spreadsheet template
                    const String strSpreadsheetTemplate = "Spreadsheet Templates/Barcode.xlsx";
                    //Setting up destination open spreadsheet report
                    const String strSpreadsheetReport = "Spreadsheet Reports/Barcode.xlsx";
                    try
                    {
                        //Instantiate DocumentAssembler class
                        DocumentAssembler assembler = new DocumentAssembler();
                        //Call AssembleDocument to generate  Report in open spreadsheet format
                        assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strSpreadsheetTemplate), CommonUtilities.SetDestinationDocument(strSpreadsheetReport), DataLayer.GetCustomerData(), "customer");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    //ExEnd:AddBarCodesSpreadsheet
                    break;

                case "presentation":
                    //ExStart:AddBarCodesPowerPoint
                    //Setting up source open presentation template
                    const String strPresentationTemplate = "Presentation Templates/Barcode.pptx";
                    //Setting up destination open presentation report
                    const String strPresentationReport = "Presentation Reports/Barcode.pptx";
                    try
                    {
                        //Instantiate DocumentAssembler class
                        DocumentAssembler assembler = new DocumentAssembler();
                        //Call AssembleDocument to generate  Report in open presentation format
                        assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strPresentationTemplate), CommonUtilities.SetDestinationDocument(strPresentationReport), DataLayer.GetCustomerData(), "customer");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    //ExEnd:AddBarCodesPowerPoint
                    break;
            }
        }
        public static void GenerateReportUsingMultipleDS(string strDocumentFormat)
        {
            if (strDocumentFormat == "document")
            {
                //ExStart:GeneratingReportUsingMultipleDataSourcesdocumentprocessing
                //Setting up source open document template
                const String strDocumentTemplate = "Word Templates/Multiple DS.odt";
                //Setting up destination open document report
                const String strDocumentReport = "Word Reports/Multiple DS.odt";
                try
                {
                    //Instantiate DocumentAssembler class
                    DocumentAssembler assembler = new DocumentAssembler();
                    //Create an array of data source objects
                    object[] dataSourceObj = new object[] { DataLayer.GetAllDataFromXML(), DataLayer.GetProductsDataJson() };
                    //Create an array of data source string
                    string[] dataSourceString = new string[] { "ds", "products" };

                    //Call AssembleDocument to generate report
                    assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate), CommonUtilities.SetDestinationDocument(strDocumentReport), dataSourceObj, dataSourceString);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                //ExEnd:GeneratingReportUsingMultipleDataSourcesdocumentprocessing
            }
            else if (strDocumentFormat == "spreadsheet")
            {
                //ExStart:GeneratingReportUsingMultipleDataSourcesspreadsheet
                //Setting up source open document template
                const String strDocumentTemplate = "Spreadsheet Templates/Multiple DS.ods";
                //Setting up destination open document report
                const String strDocumentReport = "Spreadsheet Reports/Multiple DS.ods";
                try
                {
                    //Instantiate DocumentAssembler class
                    DocumentAssembler assembler = new DocumentAssembler();
                    //Create an array of data source objects
                    object[] dataSourceObj = new object[] { DataLayer.GetAllDataFromXML(), DataLayer.GetProductsDataJson() };
                    //Create an array of data source string
                    string[] dataSourceString = new string[] { "ds", "products" };

                    //Call AssembleDocument to generate report
                    assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate), CommonUtilities.SetDestinationDocument(strDocumentReport), dataSourceObj, dataSourceString);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                //ExEnd:GeneratingReportUsingMultipleDataSourcesspreadsheet
            }
            else if (strDocumentFormat == "presentation")
            {
                //ExStart:GeneratingReportUsingMultipleDataSourcespresentation
                //Setting up source open document template
                const String strDocumentTemplate = "Presentation Templates/Multiple DS.odp";
                //Setting up destination open document report
                const String strDocumentReport = "Presentation Reports/Multiple DS.odp";
                try
                {
                    //Instantiate DocumentAssembler class
                    DocumentAssembler assembler = new DocumentAssembler();
                    //Create an array of data source objects
                    object[] dataSourceObj = new object[] { DataLayer.GetAllDataFromXML(), DataLayer.GetProductsDataJson() };
                    //Create an array of data source string
                    string[] dataSourceString = new string[] { "ds", "products" };

                    //Call AssembleDocument to generate report
                    assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate), CommonUtilities.SetDestinationDocument(strDocumentReport), dataSourceObj, dataSourceString);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                //ExEnd:GeneratingReportUsingMultipleDataSourcespresentation
            }
        }