DataTplNestedList.vb
  1. ''
  2. '' This code is part of Document Solutions for Word demos.
  3. '' Copyright (c) MESCIUS inc. All rights reserved.
  4. ''
  5. Imports System.IO
  6. Imports System.Drawing
  7. Imports System.Text
  8. Imports System.Data
  9. Imports System.Linq
  10. Imports System.Globalization
  11. Imports GrapeCity.Documents.Word
  12.  
  13. '' This sample uses data templates to print the list of sea names
  14. '' from a simple hierarchical data source.
  15. Public Class DataTplNestedList
  16. Function CreateDocx() As GcWordDocument
  17. '' The data source (ocean And sea data from Wikipedia):
  18. Dim oceans =
  19. {
  20. New With {.name = "Pacific", .areaOfWorldOcean = 0.466, .volumeOfWorldOcean = 0.501, .seas =
  21. {New With {.name = "Australasian Mediterranean Sea"}, New With {.name = "Philippine Sea"}, New With {.name = "Coral Sea"}, New With {.name = "South China Sea"}}},
  22. New With {.name = "Atlantic", .areaOfWorldOcean = 0.235, .volumeOfWorldOcean = 0.233, .seas =
  23. {New With {.name = "Sargasso Sea"}, New With {.name = "Caribbean Sea"}, New With {.name = "Mediterranean Sea"}, New With {.name = "Gulf of Guinea"}}},
  24. New With {.name = "Indian", .areaOfWorldOcean = 0.195, .volumeOfWorldOcean = 0.198, .seas =
  25. {New With {.name = "Arabian Sea"}, New With {.name = "Bay of Bengal"}, New With {.name = "Andaman Sea"}, New With {.name = "Laccadive Sea"}}},
  26. New With {.name = "Southern", .areaOfWorldOcean = 0.061, .volumeOfWorldOcean = 0.054, .seas =
  27. {New With {.name = "Weddell Sea"}, New With {.name = "Somov Sea"}, New With {.name = "Riiser-Larsen Sea"}, New With {.name = "Lazarev Sea"}}},
  28. New With {.name = "Arctic", .areaOfWorldOcean = 0.043, .volumeOfWorldOcean = 0.014, .seas =
  29. {New With {.name = "Barents Sea"}, New With {.name = "Greenland Sea"}, New With {.name = "East Siberian Sea"}, New With {.name = "Kara Sea"}}}
  30. }
  31.  
  32. Dim doc = New GcWordDocument()
  33.  
  34. '' Add the data source to the data template data sources
  35. '' (note that in this release, only one data source can be added):
  36. doc.DataTemplate.DataSources.Add("ds", oceans)
  37.  
  38. '' Add list templates for the two-level list:
  39. Dim listTplTop = doc.ListTemplates.Add(BuiltInListTemplateId.NumberArabicParenthesis, "listTplTop")
  40. Dim listTplNested = doc.ListTemplates.Add(BuiltInListTemplateId.BulletDefault, "listTplNested")
  41.  
  42. '' Print 'ocean - area % of world ocean' at the top list level:
  43. Dim p1 = doc.Body.Paragraphs.Add("{{#ds}}{{name}} - {{areaOfWorldOcean}:format(0.#%)}")
  44. p1.ListFormat.Template = listTplTop
  45. '' Print the ocean's largest sea names as the nested list:
  46. Dim p2 = doc.Body.Paragraphs.Add("{{seas.name}}{{/ds}}")
  47. p2.ListFormat.Template = listTplNested
  48. p2.ListFormat.LevelNumber = 1
  49.  
  50. '' This call expands all data templates in the document,
  51. '' replacing template tags with data (iterating over all data items):
  52. doc.DataTemplate.Process(CultureInfo.GetCultureInfo("en-US"))
  53.  
  54. '' Done
  55. Return doc
  56. End Function
  57. End Class
  58.