//// This code is part of Document Solutions for Word demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Collections.Generic;usingSystem.Data;usingSystem.Globalization;usingGrapeCity.Documents.Word; namespaceDsWordWeb.Demos{// The code in this example loads a DOCX document (created in MS Word)// containing a report template, and depending on the selected demo,// either adds a data source and generates the data bound report,// or simply returns the unmodified template for reference.publicclassDataTplUseCases {publicGcWordDocumentCreateDocx(string[] sampleParams) {var doc = newGcWordDocument(); // Load the template DOCX: doc.Load(Path.Combine("Resources", "WordDocs", sampleParams[3])); usingvar ds = newDataSet();// Load the data set: ds.ReadXml(Path.Combine("Resources", "data", "DsWordTplDataSet.xml")); // Return the unmodified template document for reference:if (sampleParams.Length >= 6 && sampleParams[5] == "template")return doc; // Add the data source to the data template data sources:if (sampleParams.Length >= 5 && !string.IsNullOrEmpty(sampleParams[4])) doc.DataTemplate.DataSources.Add("ds", ds.Tables[sampleParams[4]]);else doc.DataTemplate.DataSources.Add("ds", ds); // The document already has all the necessary bindings,// so we only need to process the data template: doc.DataTemplate.Process(CultureInfo.GetCultureInfo("en-US")); // Done:return doc; } publicGcWordDocumentCreateDocx(int parsIdx = 0) {returnCreateDocx(GetSampleParamsList()[parsIdx]); } publicstaticList<string[]> GetSampleParamsList() {// Mandatory: name, description, info// Custom: template DOCX [[, table] , "template"]returnnewList<string[]>() {newstring[] { "@use-data-tpl/Lease Agreement", "Generate a lease agreement", null,"Lease_Agreement_Template.docx", "LeaseAgreement" },newstring[] { "@use-data-tpl/Consulting Agreement", "Generate a consultancy agreement", null,"Consulting_Agreement_Template.docx", "ConsAgreement" },newstring[] { "@use-data-tpl/Rental Agreement", "Generate a house rental agreement", null,"House_Rental_Template.docx", "HouseRentalAgreement" },newstring[] { "@use-data-tpl/Employment Contract", "Generate an employment contract", null,"Employment_Contract_Template.docx", "EmploymentContract" }, // Parameter sets below simply return the template used to produce the bound document in corresponding// data template samples:newstring[] { "@use-data-tpl-src/Lease Agreement", "Template Lease_Agreement_Template.docx", null,"Lease_Agreement_Template.docx", null, "template" },newstring[] { "@use-data-tpl-src/Consulting Agreement", "Template Consulting_Agreement_Template.docx", null,"Consulting_Agreement_Template.docx", null, "template" },newstring[] { "@use-data-tpl-src/Rental Agreement", "Template House_Rental_Template.docx", null,"House_Rental_Template.docx", null, "template" },newstring[] { "@use-data-tpl-src/Employment Contract", "Template Employment_Contract_Template.docx", null,"Employment_Contract_Template.docx", null, "template" },newstring[] { "@use-data-tpl-src/Order Invoice", "Template InvoiceTemplate.docx", null,"InvoiceTemplate.docx", null, "template" },newstring[] { "@use-data-tpl-src/Closing Disclosure", "Template Closing_Disclosure_Template.docx", null,"Closing_Disclosure_Template.docx", null, "template" },newstring[] { "@use-data-tpl-src/Vacation Itinerary", "Template Vacation_Itinerary_Template.docx", null,"Vacation_Itinerary_Template.docx", null, "template" }, }; } }}