DataTplToDouble.vb
''
'' 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 example shows how to use the todouble() template formatter
'' to enable using numeric format specifiers (percent in this sample)
'' on numeric values stored as strings in the data source.
Public Class DataTplToDouble
    Function CreateDocx() As GcWordDocument
        '' The data source (ocean and sea data from Wikipedia),
        '' note that in order to demonstrate the todouble() formatter,
        '' the 'areaOfWorldOcean' in this data source is a string rather
        '' than a number:
        Dim oceans =
        {
            New With {.name = "Pacific", .areaOfWorldOcean = "0.466", .volumeOfWorldOcean = 0.501, .seas =
                {New With {.name = "Australasian Mediterranean Sea"}, New With {.name = "Philippine Sea"}, New With {.name = "Coral Sea"}, New With {.name = "South China Sea"}}},
            New With {.name = "Atlantic", .areaOfWorldOcean = "0.235", .volumeOfWorldOcean = 0.233, .seas =
                {New With {.name = "Sargasso Sea"}, New With {.name = "Caribbean Sea"}, New With {.name = "Mediterranean Sea"}, New With {.name = "Gulf of Guinea"}}},
            New With {.name = "Indian", .areaOfWorldOcean = "0.195", .volumeOfWorldOcean = 0.198, .seas =
                {New With {.name = "Arabian Sea"}, New With {.name = "Bay of Bengal"}, New With {.name = "Andaman Sea"}, New With {.name = "Laccadive Sea"}}},
            New With {.name = "Southern", .areaOfWorldOcean = "0.061", .volumeOfWorldOcean = 0.054, .seas =
                {New With {.name = "Weddell Sea"}, New With {.name = "Somov Sea"}, New With {.name = "Riiser-Larsen Sea"}, New With {.name = "Lazarev Sea"}}},
            New With {.name = "Arctic", .areaOfWorldOcean = "0.043", .volumeOfWorldOcean = 0.014, .seas =
                {New With {.name = "Barents Sea"}, New With {.name = "Greenland Sea"}, New With {.name = "East Siberian Sea"}, New With {.name = "Kara Sea"}}}
        }

        Dim doc = New GcWordDocument()

        '' Add the data source to the data template data sources:
        doc.DataTemplate.DataSources.Add("ds", oceans)

        '' Add list templates for the two-level list:
        Dim listTplTop = doc.ListTemplates.Add(BuiltInListTemplateId.NumberArabicParenthesis, "listTplTop")
        Dim listTplNested = doc.ListTemplates.Add(BuiltInListTemplateId.BulletDefault, "listTplNested")

        '' 'areaOfWorldOcean' in the data source is a string, so in order to be able
        '' to use percent formatting on it we convert it to a number using the
        '' todouble() formatter, then pass the result to format():
        Dim p1 = doc.Body.Paragraphs.Add("{{#ds}}{{name}} - {{areaOfWorldOcean}:todouble():format(0.#%)} of World Ocean area:")
        p1.ListFormat.Template = listTplTop
        '' Print the ocean's largest sea names as the nested list:
        Dim p2 = doc.Body.Paragraphs.Add("{{seas.name}}{{/ds}}")
        p2.ListFormat.Template = listTplNested
        p2.ListFormat.LevelNumber = 1

        '' Note that we explicitly specify the culture to make sure that
        '' the dot in 'areaOfWorldOcean' strings is recognized as decimal separator:
        doc.DataTemplate.Process(CultureInfo.GetCultureInfo("en-US"))

        '' Done:
        Return doc
    End Function
End Class