''
'' This code is part of Document Solutions for Word demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.Globalization
Imports GrapeCity.Documents.Word
'' This sample demonstrates how to access sibling data members
'' in two ranges with a common parent.
Public Class DataTplSiblingAccess
Function CreateDocx() As GcWordDocument
'' Simple JSON data source with two ranges:
Dim test = "{" +
"""letters"": [ { ""id"": ""a"" }, { ""id"": ""b"" }, { ""id"": ""c"" }, { ""id"": ""d"" } ]," +
"""numbers"": [ { ""id"": 1 }, { ""id"": 2 }, { ""id"": 3 }, { ""id"": 4 }, { ""id"": 5 }, { ""id"": 6 }, { ""id"": 7 } ]" +
"}"
Dim doc = New GcWordDocument()
'' Add the data source to the data template data sources:
doc.DataTemplate.DataSources.Add("ds", test)
'' Add a template that will iterate over both ranges and print all possible combinations of values
'' (this did not work in releases prior to v4.2):
Dim p = doc.Body.Paragraphs.Add("{{#ds}}{{ds.letters.id}:toupper()}{{#ds.numbers}}{{ds.numbers.id}}{{/ds.numbers}}{{/ds}}")
'' Format this as a bullet list:
p.ListFormat.Template = doc.ListTemplates.Add(BuiltInListTemplateId.BulletDefault, "myListTemplate")
'' This call expands all data templates in the document,
'' replacing template tags with data (iterating over all data items):
doc.DataTemplate.Process(CultureInfo.GetCultureInfo("en-US"))
'' Done:
Return doc
End Function
End Class