''
'' This code is part of Document Solutions for Word demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.IO
Imports System.Globalization
Imports GrapeCity.Documents.Word
'' This example shows how to use the 'rbb' ('run-block-behavior') formatter
'' to print the data items of a list within a single paragraph rather than
'' as a list of paragraphs.
Public Class DataTplRunBlockBehavior
Function CreateDocx() As GcWordDocument
Using oceans = File.OpenRead(Path.Combine("Resources", "data", "oceans.json"))
Dim doc = New GcWordDocument()
doc.DataTemplate.DataSources.Add("ds", oceans)
'' Add a list for oceans, and a run for seas:
Dim p = doc.Body.Paragraphs.Add("{{#ds}}{{ds.name}} ocean: ", doc.Styles(BuiltInStyleId.ListParagraph))
Dim myListTemplate = doc.ListTemplates.Add(BuiltInListTemplateId.BulletDefault, "myListTemplate")
p.ListFormat.Template = myListTemplate
'' The 'rbb' ('run-block-behavior') formatter forces the range to be expanded
'' within the current paragraph, each data item generating a run rather than a paragraph:
doc.Body.Paragraphs.First.GetRange().Runs.Add("{{#ds.seas}:rbb()}{{ds.seas.name}}; {{/ds.seas}}")
'' Close the parent range '#ds':
doc.Body.Paragraphs.First.GetRange().Runs.Add("{{/ds}}")
'' Process the template:
doc.DataTemplate.Process(CultureInfo.GetCultureInfo("en-US"))
Return doc
End Using
End Function
End Class