//// This code is part of Document Solutions for Word demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem;usingSystem.IO;usingSystem.Data;usingSystem.Linq;usingSystem.Globalization;usingGrapeCity.Documents.Word; namespaceDsWordWeb.Demos{// This sample is similar to DataTplProductList but it sorts the product// list by price in the descending order to print 10 most expensive products.// To limit the list this sample uses the seq/follow formatter as a 'take(N)'// operator, utilizing also the ability to use multiple data sources.// The template document is modified to include the sequence/follow formatters.publicclassDataTplTopProduct {publicGcWordDocumentCreateDocx() {// The number of iterations:constintN = 10; // Load and modify the template DOCX:var doc = newGcWordDocument(); doc.Load(Path.Combine("Resources", "WordDocs", "ProductListTemplate.docx"));var caption0 = "Product List";var caption1 = $"{N} Most Expensive Products";var pStart0 = @"{{#ds}}{{ds.ProductID}}";var pEnd0 = @"{{/ds}}";var pStart1 = @"{{#take}:seq(t10)}{{#ds}:follow(t10)}{{ds.ProductID}}";var pEnd1 = @"{{/ds}}{{/take}}"; doc.Body.Replace(caption0, caption1); doc.Body.Replace(pEnd0, pEnd1); doc.Body.Replace(pStart0, pStart1); // Add a simple array to be used as the sequence data source// limiting the number of iterations over the "real" data range: doc.DataTemplate.DataSources.Add("take", newint[N]); 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["UnitPrice"] descendingselectnew {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; } }}