'''' This code is part of Document Solutions for Word demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.DrawingImportsGrapeCity.Documents.Word '' This sample uses conditional table formatting to build a table'' with alternating row backgrounds.PublicClassAlternatingRowsFunctionCreateDocx() AsGcWordDocumentDim doc = NewGcWordDocument() '' Random-ish table dimensions:Dim rand = Util.NewRandom()Dim rows = rand.Next(10, 100)Dim cols = rand.Next(4, 6) doc.Body.Paragraphs.Add($"A {cols} columns by {rows} rows table, with conditional styles applied to alternating rows:") '' Add an empty table:Dim t = doc.Body.Tables.Add(0, 0) '' Add some rows and cells to it:Dim cells = New List(OfString)(cols)For col = 1To cols cells.Add(String.Empty)NextFor row = 0To rows - 1For col = 0To cols - 1 cells(col) = $"Row {row + 1}, col {col + 1}"Next t.Rows.Add(cells.ToArray())Next '' Create a table style on which we will define conditional formatting:Dim ts1 = doc.Styles.Add("Table Style 1", StyleType.Table)'' And assign the style to the table: t.Style = ts1 '' Set up simple borders:ForEach border In ts1.Table.Borders border.LineStyle = LineStyle.Single border.LineWidth = 0.5F border.Color.RGB = Color.DarkGrayNext'' Add some padding: ts1.Table.Padding.All = 2 '' To use certain table styles, we need to set corresponding flags on the table's style options: t.Format.StyleOptions = TableStyleOptions.RowBands '' Set up the style to use alternating background colors on odd and even rows: ts1.Table.RowStripe = 1'' Odd rows' style: ts1.Table.Conditionals(TableStyleOverride.Band1Horizontal).Shading.Texture = TexturePattern.Clear ts1.Table.Conditionals(TableStyleOverride.Band1Horizontal).Shading.BackgroundPatternColor.RGB = Color.FromArgb(&HE6, &HFF, &HE6)'' Even rows' style: ts1.Table.Conditionals(TableStyleOverride.Band2Horizontal).Shading.Texture = TexturePattern.Clear ts1.Table.Conditionals(TableStyleOverride.Band2Horizontal).Shading.BackgroundPatternColor.RGB = Color.FromArgb(&HFF, &HFF, &HE6) '' Done:Return docEndFunctionEndClass