'''' This code is part of Document Solutions for Word demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.GlobalizationImportsGrapeCity.Documents.Word '' This example demonstrates the use of 'if/else' construct in report templates'' to filter data source on a condition (that a certain field starts with the letter 'S').PublicClassDataTplIfStartsWithFunctionCreateDocx() AsGcWordDocument'' The data source (ocean and sea data from Wikipedia):Dim oceans = {NewWith {.name = "Pacific", .areaOfWorldOcean = 0.466, .volumeOfWorldOcean = 0.501, .seas = {NewWith {.name = "Australasian Mediterranean Sea"}, NewWith {.name = "Philippine Sea"}, NewWith {.name = "Coral Sea"}, NewWith {.name = "South China Sea"}}},NewWith {.name = "Atlantic", .areaOfWorldOcean = 0.235, .volumeOfWorldOcean = 0.233, .seas = {NewWith {.name = "Sargasso Sea"}, NewWith {.name = "Caribbean Sea"}, NewWith {.name = "Mediterranean Sea"}, NewWith {.name = "Gulf of Guinea"}}},NewWith {.name = "Indian", .areaOfWorldOcean = 0.195, .volumeOfWorldOcean = 0.198, .seas = {NewWith {.name = "Arabian Sea"}, NewWith {.name = "Bay of Bengal"}, NewWith {.name = "Andaman Sea"}, NewWith {.name = "Laccadive Sea"}}},NewWith {.name = "Southern", .areaOfWorldOcean = 0.061, .volumeOfWorldOcean = 0.054, .seas = {NewWith {.name = "Weddell Sea"}, NewWith {.name = "Somov Sea"}, NewWith {.name = "Riiser-Larsen Sea"}, NewWith {.name = "Lazarev Sea"}}},NewWith {.name = "Arctic", .areaOfWorldOcean = 0.043, .volumeOfWorldOcean = 0.014, .seas = {NewWith {.name = "Barents Sea"}, NewWith {.name = "Greenland Sea"}, NewWith {.name = "East Siberian Sea"}, NewWith {.name = "Kara Sea"}}} } Dim doc = NewGcWordDocument() '' Add the data source: doc.DataTemplate.DataSources.Add("ds", oceans) '' Add a list template so that the data is formatted as a list:Dim myListTemplate = doc.ListTemplates.Add(BuiltInListTemplateId.BulletDefault, "myListTemplate") '' Filter output using if/then/else - print only names starting with an 's':Dim p = doc.Body.Paragraphs.Add("{{if StartsWith(UCase(ds.seas.name),""S"")}}{{ds.seas.name}}{{endif}}", doc.Styles(BuiltInStyleId.ListParagraph)) p.ListFormat.Template = myListTemplate '' Expand the templates: doc.DataTemplate.Process(CultureInfo.GetCultureInfo("en-US")) '' Add a short note describing the demo at the top of the document: doc.Body.Paragraphs.Insert("This example demonstrates the use of 'if/else' construct in report templates " +"to filter data source on a condition (that a certain field starts with the letter 'S')." +"Please see this sample source code for full details.",InsertLocation.Start) doc.Body.Paragraphs.Insert("Report templates: if data starts with 'S'", doc.Styles(BuiltInStyleId.Heading1), InsertLocation.Start) '' Done:Return docEndFunctionEndClass