'''' This code is part of Document Solutions for Word demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.DrawingImportsGrapeCity.Documents.Word '' This sample demonstrates various conditional table formatting options.PublicClassConditionalTableStylesFunctionCreateDocx() AsGcWordDocumentDim doc = NewGcWordDocument() '' Table dimensions:Dim rows = 20Dim cols = 7 doc.Body.Paragraphs.Add($"A {cols} columns by {rows} rows table, with conditional styles applied to most elements:") '' 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 conditional styles, we need to set corresponding flags on the table's style options.'' In this case, we set all of them: t.Format.StyleOptions =TableStyleOptions.FirstRowOrTableStyleOptions.LastRowOrTableStyleOptions.FirstColumnOrTableStyleOptions.LastColumnOrTableStyleOptions.RowBandsOrTableStyleOptions.ColumnBands '' Set up the table for row and column bands: ts1.Table.RowStripe = 1 ts1.Table.ColumnStripe = 1 '' Shortcut to access table's conditionals:Dim conds = ts1.Table.Conditionals '' Odd rows' style: conds(TableStyleOverride.Band1Horizontal).Font.Bold = True'' Band*Vertical styles override Band*Horizontal styles if there is a conflict.'' Here, becase we set vertical band backgrounds, horizontal ones '' will not be seen in the document: conds(TableStyleOverride.Band1Horizontal).Shading.Texture = TexturePattern.Clear'' overridden conds(TableStyleOverride.Band1Horizontal).Shading.BackgroundPatternColor.RGB = Color.Magenta'' overridden'' Even rows' style: conds(TableStyleOverride.Band2Horizontal).Font.Italic = True'' Won't be seen in the document (see comment above): conds(TableStyleOverride.Band2Horizontal).Shading.Texture = TexturePattern.Clear'' overridden conds(TableStyleOverride.Band2Horizontal).Shading.BackgroundPatternColor.RGB = Color.Brown'' overridden '' Odd columns' style: conds(TableStyleOverride.Band1Vertical).Shading.Texture = TexturePattern.Clear conds(TableStyleOverride.Band1Vertical).Shading.BackgroundPatternColor.RGB = Color.FromArgb(&HE6, &HFF, &HE6)'' Even columns' style: conds(TableStyleOverride.Band2Vertical).Shading.Texture = TexturePattern.Clear conds(TableStyleOverride.Band2Vertical).Shading.BackgroundPatternColor.RGB = Color.FromArgb(&HFF, &HFF, &HE6) '' First/last/corner styles will override horizontal and vertical bands if there is a conflict: conds(TableStyleOverride.FirstColumn).Shading.Texture = TexturePattern.Clear conds(TableStyleOverride.FirstColumn).Shading.BackgroundPatternColor.RGB = Color.CadetBlue conds(TableStyleOverride.FirstRow).Shading.Texture = TexturePattern.Clear conds(TableStyleOverride.FirstRow).Shading.BackgroundPatternColor.RGB = Color.PaleVioletRed conds(TableStyleOverride.LastColumn).Shading.Texture = TexturePattern.Clear conds(TableStyleOverride.LastColumn).Shading.BackgroundPatternColor.RGB = Color.PapayaWhip conds(TableStyleOverride.LastRow).Shading.Texture = TexturePattern.Clear conds(TableStyleOverride.LastRow).Shading.BackgroundPatternColor.RGB = Color.PaleGoldenrod conds(TableStyleOverride.NorthWestCell).Shading.Texture = TexturePattern.Clear conds(TableStyleOverride.NorthWestCell).Shading.BackgroundPatternColor.RGB = Color.Red conds(TableStyleOverride.NorthEastCell).Shading.Texture = TexturePattern.Clear conds(TableStyleOverride.NorthEastCell).Shading.BackgroundPatternColor.RGB = Color.Green conds(TableStyleOverride.SouthWestCell).Shading.Texture = TexturePattern.Clear conds(TableStyleOverride.SouthWestCell).Shading.BackgroundPatternColor.RGB = Color.Blue conds(TableStyleOverride.SouthEastCell).Shading.Texture = TexturePattern.Clear conds(TableStyleOverride.SouthEastCell).Shading.BackgroundPatternColor.RGB = Color.Purple '' Done:Return docEndFunctionEndClass