DataTplNestedTable.vb
- ''
- '' This code is part of Document Solutions for Word demos.
- '' Copyright (c) MESCIUS inc. All rights reserved.
- ''
- Imports System.IO
- Imports System.Drawing
- Imports System.Text
- Imports System.Data
- Imports System.Linq
- Imports System.Globalization
- Imports GrapeCity.Documents.Word
-
- '' This sample uses data templates to generate a table with rows
- '' corresponding to oceans, and a nested table with seas.
- Public Class DataTplNestedTable
- Function CreateDocx() As GcWordDocument
- '' The data source (ocean And sea data from Wikipedia):
- 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
- '' (note that in this release, only one data source can be added):
- doc.DataTemplate.DataSources.Add("ds", oceans)
-
- '' Add a table for oceans, And a nested table for seas:
- Dim t = doc.Body.Tables.Add(3, 1)
- t.Style = doc.Styles.Add("my table style", StyleType.Table)
- t.Style.BaseStyle = doc.Styles(BuiltInStyleId.ListTable5DarkAccent1)
- Dim tnested = t.Rows(0).Cells(2).GetRange().Tables.Add(1, 1)
- tnested.Style = doc.Styles.Add("my nested table style", StyleType.Table)
- tnested.Style.BaseStyle = t.Style.BaseStyle
- tnested.Style.Font.Color.RGB = Color.PaleGoldenrod
- tnested.Style.Font.Size -= 1
-
- '' Specify data bindings
- t.Rows(0).Cells(0).GetRange().Paragraphs.First.GetRange().Runs.Add("{{#ds}}{{name}}")
- t.Rows(0).Cells(1).GetRange().Paragraphs.First.GetRange().Runs.Add("{{areaOfWorldOcean}:format(0.#%)}")
- tnested.Rows(0).Cells(0).GetRange().Paragraphs.First.GetRange().Runs.Add("{{seas.name}}")
- t.Rows(0).Cells(2).GetRange().Paragraphs.First.GetRange().Runs.Add("{{/ds}}")
-
- '' This call expands all data templates in the document,
- '' replacing template tags with data (iterating over all data items):
- doc.DataTemplate.Process(CultureInfo.GetCultureInfo("en-US"))
-
- '' Done
- Return doc
- End Function
- End Class
-