''
'' 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 'pbb' ('paragraph-block-behavior') formatter
'' to print all data items of a list as separate paragraphs inside a single table cell
'' rather than generating a new row for each item.
Public Class DataTplParaBlockBehavior
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 table with one column and two rows, note that each cell has one default paragraph
'' when the table is created, so we add template tags to those already existing paragraphs:
Dim table = doc.Body.Tables.Add(1, 2, doc.Styles(BuiltInStyleId.ColorfulShadingAccent1))
'' The first row is used to print the ocean's name:
table(0, 0).GetRange().Paragraphs.First.GetRange().Runs.Add("{{#ds}}{{ds.name}}")
'' The second row prints the ocean's seas range. Using the 'pbb' (paragraph-block-b) formatter
'' allows us to print all items in the range (seas) inside the same single cell rather than
'' generating a row per each item:
table(1, 0).GetRange().Paragraphs.First.GetRange().Runs.Add("{{#ds.seas}:pbb()}{{ds.seas.name}}{{/ds.seas}}")
'' Close the parent range '#ds':
doc.Body.Paragraphs.Add("{{/ds}}")
'' Process the template:
doc.DataTemplate.Process(CultureInfo.GetCultureInfo("en-US"))
Return doc
End Using
End Function
End Class