//// 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.Linq;usingSystem.Globalization;usingGrapeCity.Documents.Word; namespaceDsWordWeb.Demos{// This data template sample loads a DOCX that was created in MS Word,// and contains a table with data template tags. It then creates a DataSet,// loads the DsNWind.xml data base into it, and builds a product list// from tables in that data set. The product list is set as the template// data source on the document, and the template is processed to build// the final document with actual data.publicclassDataTplProductList {publicGcWordDocumentCreateDocx(string[] sampleParams) {var doc = newGcWordDocument(); // Load the template DOCX: doc.Load(Path.Combine("Resources", "WordDocs", sampleParams[3])); usingvar ds = newDataSet();// Load the data and build the product list data source: ds.ReadXml(Path.Combine("Resources", "data", "DsNWind.xml")); DataTable dtProds = ds.Tables["Products"];DataTable dtSupps = ds.Tables["Suppliers"]; var products =from prod in dtProds.Select()join supp in dtSupps.Select()on prod["SupplierID"] equals supp["SupplierID"]orderby prod["ProductName"]selectnew {ProductID = prod["ProductID"],ProductName = prod["ProductName"],Supplier = supp["CompanyName"],QuantityPerUnit = prod["QuantityPerUnit"],UnitPrice = prod["UnitPrice"] }; // Add the data source to the data template data sources: doc.DataTemplate.DataSources.Add("ds", products); // 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 paramIdx = 0) {returnCreateDocx(GetSampleParamsList()[paramIdx]); } publicstaticList<string[]> GetSampleParamsList() {// Strings are name, description, info, template docx:returnnewList<string[]>() {newstring[] { "@data-templates/Product List","Load a template DOCX and bind it to a product list from an XML data set", null,"ProductListTemplate.docx" },newstring[] { "@data-templates/Formatter Chain","Load a template that uses chained formatters to highlight products that cost $50+", null,"ProductListTemplate-cond.docx" }, }; } }}