'''' This code is part of Document Solutions for Word demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DataImportsSystem.LinqImportsSystem.GlobalizationImportsGrapeCity.Documents.Word '' 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.PublicClassDataTplProductListPublicFunctionCreateDocx(ByRef sampleParams AsString()) AsGcWordDocumentDim doc = NewGcWordDocument() '' Load the template DOCX doc.Load(Path.Combine("Resources", "WordDocs", sampleParams(3))) 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("ProductName")SelectNewWith { .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'' (note that in this release, only one data source can be added): 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"))EndUsing '' DoneReturn docEndFunction PublicFunctionCreateDocx(Optional parsIdx AsInteger = 0) AsGcWordDocumentReturnCreateDocx(GetSampleParamsList()(parsIdx))EndFunction PublicSharedFunctionGetSampleParamsList() As List(OfString())'' Strings are name, description, info, template docxReturnNew List(OfString()) From {NewString() {"@data-templates/Product List","Load a template DOCX and bind it to a product list from an XML data set", Nothing,"ProductListTemplate.docx"},NewString() {"@data-templates/Formatter Chain","Load a template that uses chained formatters to highlight products that cost $50+", Nothing,"ProductListTemplate-cond.docx"} }EndFunctionEndClass