//// This code is part of Document Solutions for Word demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem;usingSystem.Collections.Generic;usingSystem.Globalization;usingGrapeCity.Documents.Word; namespaceDsWordWeb.Demos{// This sample shows how arrays of primitive value types (such as int[] or List<string>)// can be used as data sources for templates, injecting the array elements into// the document with the "value" template tag.// Types that allow using the "value" tag are those for which Type.IsPrimitive gets true// (except pointer types), and strings.publicclassDataTplElemColl {publicGcWordDocumentCreateDocx() {var doc = newGcWordDocument(); // Add a few simple arrays as data sources: doc.DataTemplate.DataSources.Add("dsInts", newint[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }); doc.DataTemplate.DataSources.Add("dsConsts", newdouble[] {Math.PI,Math.E, }); doc.DataTemplate.DataSources.Add("dsStrs", newList<string>() {"Pacific","Atlantic","Indian","Southern","Arctic", }); // Add a list template so that the data is formatted as a list:var myListTemplate = doc.ListTemplates.Add(BuiltInListTemplateId.BulletDefault, "myListTemplate"); // Integers: doc.Body.Paragraphs.Add("Integers from 1 to 9:", doc.Styles[BuiltInStyleId.Heading1]);var p = doc.Body.Paragraphs.Add("{{#dsInts}}{{dsInts.value}}{{/dsInts}}", doc.Styles[BuiltInStyleId.ListParagraph]); p.ListFormat.Template = myListTemplate; // Math constants: doc.Body.Paragraphs.Add("Constants from the Math class:", doc.Styles[BuiltInStyleId.Heading1]); p = doc.Body.Paragraphs.Add("{{#dsConsts}}{{dsConsts.value}}{{/dsConsts}}", doc.Styles[BuiltInStyleId.ListParagraph]); p.ListFormat.Template = myListTemplate; // Strings (oceans): doc.Body.Paragraphs.Add("Strings (oceans):", doc.Styles[BuiltInStyleId.Heading1]); p = doc.Body.Paragraphs.Add("{{#dsStrs}}{{dsStrs.value}:toupper()}{{/dsStrs}}", doc.Styles[BuiltInStyleId.ListParagraph]); p.ListFormat.Template = myListTemplate; // Expand all data templates in the document: doc.DataTemplate.Process(CultureInfo.GetCultureInfo("en-US")); // Done:return doc; } }}