'''' This code is part of Document Solutions for Word demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.LinqImportsSystem.GlobalizationImportsGrapeCity.Documents.Word '' This example demonstrates the use of collection state functions'' Index(), IsFirst() and IsLast() that can be used with the report templates'' 'calc' feature.PublicClassDataTplCollStateFunctionCreateDocx() AsGcWordDocument'' The original 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"}}} }'' Flatten the data source to get a flat collection of seas:Dim seas = oceans.SelectMany(Function(o) o.seas) '' Create the document and add the sea list as the data source:Dim doc = NewGcWordDocument() doc.DataTemplate.DataSources.Add("ds", seas) '' Template that for each record (sea) prints:'' - The 1-based number of the collection element (sea) and the total number of records;'' - The sea name;'' - The string '(first)' after the first element (sea);'' - The string '(last)' after the last element (sea):Dim p = doc.Body.Paragraphs.Add("Record {{calc Index(ds)+1}} of {{calc Count(ds)}}: {{ds.name}}{{if IsFirst(ds)}} (first){{else}}{{if IsLast(ds)}} (last){{endif}}{{endif}}") '' Expand the template: doc.DataTemplate.Process(CultureInfo.GetCultureInfo("en-US")) '' Done:Return docEndFunctionEndClass