'''' This code is part of Document Solutions for Word demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.DataImportsSystem.GlobalizationImportsSystem.IOImportsSystem.LinqImportsGrapeCity.Documents.Word '' 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.PublicClassDataTplTopProductFunctionCreateDocx() AsGcWordDocument'' The number of iterations:ConstNAsInteger = 10 '' Load and modify the template DOCX:Dim doc = NewGcWordDocument() doc.Load(Path.Combine("Resources", "WordDocs", "ProductListTemplate.docx"))Dim caption0 = "Product List"Dim caption1 = $"{N} Most Expensive Products"Dim pStart0 = "{{#ds}}{{ds.ProductID}}"Dim pEnd0 = "{{/ds}}"Dim pStart1 = "{{#take}:seq(t10)}{{#ds}:follow(t10)}{{ds.ProductID}}"Dim 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", NewInteger(N - 1) {}) Using ds = NewDataSet()'' Load the data and build the product list data source: ds.ReadXml(Path.Combine("Resources", "data", "DsNWind.xml")) Dim dtProds AsDataTable = ds.Tables("Products")Dim dtSupps AsDataTable = ds.Tables("Suppliers") Dim products =From prod In dtProds.Select()Join supp In dtSupps.Select()On prod("SupplierID") Equals supp("SupplierID")OrderBy prod("UnitPrice") DescendingSelectNewWith { .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 docEndUsingEndFunctionEndClass