Document Solutions for Excel, .NET Edition | Document Solutions
Features / Table / Table Style / Modify Table with Custom Style
In This Topic
    Modify Table with Custom Style
    In This Topic

    In order to manage the collection of table styles in your workbook, you can modify the existing table style with your own custom table style that you have created. Each table style element represents the formatting for a particular element of the table. When you define a custom style for your table, you need to first access the existing table style element to customize table borders, set custom fill for your table, style row stripes or column stripes etc.

    As a default characteristic, you will find your workbook possessing a collection of table style for you to apply formatting to tables. These default table styles are built-in table styles which represent no formatting is applied to the tables. However, when you create a custom table style, it automatically gets added to the table style collection of your workbook and can be reused as and when you require.

    If you want to change the table style, you can use the TableStyle property. For accomplishing this task, you will first need to use the indexer notation of ITableStyleCollection to set the table style instance.

    In case you want to delete the applied table style, you can use the Delete method.

    Copy Code
    //Add one custom table style.
    ITableStyle style = workbook.TableStyles.Add("test");
    //Set WholeTable element style.
    style.TableStyleElements[TableStyleElementType.WholeTable].Font.Italic = true;
    style.TableStyleElements[TableStyleElementType.WholeTable].Font.ThemeColor = ThemeColor.Accent6;
    style.TableStyleElements[TableStyleElementType.WholeTable].Font.Strikethrough = true;
    style.TableStyleElements[TableStyleElementType.WholeTable].Borders.LineStyle = BorderLineStyle.Dotted;
    style.TableStyleElements[TableStyleElementType.WholeTable].Borders.ThemeColor = ThemeColor.Accent2;
    style.TableStyleElements[TableStyleElementType.WholeTable].Interior.Color = Color.FromArgb(24, 232, 192);
    //Set FirstColumnStripe element style.
    style.TableStyleElements[TableStyleElementType.FirstColumnStripe].Font.Bold = true;
    style.TableStyleElements[TableStyleElementType.FirstColumnStripe].Font.Color = Color.FromArgb(255, 0, 0);
    style.TableStyleElements[TableStyleElementType.FirstColumnStripe].Borders.LineStyle = BorderLineStyle.Thick;
    style.TableStyleElements[TableStyleElementType.FirstColumnStripe].Borders.ThemeColor = ThemeColor.Accent5;
    style.TableStyleElements[TableStyleElementType.FirstColumnStripe].Interior.Color = Color.FromArgb(255, 255, 0);
    style.TableStyleElements[TableStyleElementType.FirstColumnStripe].StripeSize = 2;
    //Set SecondColumnStripe element style.
    style.TableStyleElements[TableStyleElementType.SecondColumnStripe].Font.Color = Color.FromArgb(255, 0, 255);
    style.TableStyleElements[TableStyleElementType.SecondColumnStripe].Borders.LineStyle = BorderLineStyle.DashDot;
    style.TableStyleElements[TableStyleElementType.SecondColumnStripe].Borders.Color = Color.FromArgb(42, 105, 162);
    style.TableStyleElements[TableStyleElementType.SecondColumnStripe].Interior.Color = Color.FromArgb(204, 204, 255);
    ITable table = worksheet.Tables.Add(worksheet.Range["A1:C3"], true);
    //Set custom table style to table.
    table.TableStyle = style;
    table.ShowTableStyleColumnStripes = true;