static void CustomTableStyle(Workbook workbook)
        {
            #region #CustomTableStyle
            Worksheet worksheet = workbook.Worksheets["Custom Table Style"];
            workbook.Worksheets.ActiveWorksheet = worksheet;

            // Access a table.
            Table table = worksheet.Tables[0];

            String styleName = "testTableStyle";

            // If a style with the specified name exists in the collection,
            // apply this style to the table.
            if (workbook.TableStyles.Contains(styleName))
            {
                table.Style = workbook.TableStyles[styleName];
            }
            else
            {
                // Add a new table style under the "testTableStyle" name
                // to the table style collection.
                TableStyle customTableStyle = workbook.TableStyles.Add("testTableStyle");

                // Modify table style formatting.
                // Specify format characteristics for different table elements.
                customTableStyle.BeginUpdate();
                try
                {
                    customTableStyle.TableStyleElements[TableStyleElementType.WholeTable].Font.Color = Color.FromArgb(107, 107, 107);

                    // Format the header row.
                    TableStyleElement headerRowStyle = customTableStyle.TableStyleElements[TableStyleElementType.HeaderRow];
                    headerRowStyle.Fill.BackgroundColor = Color.FromArgb(64, 66, 166);
                    headerRowStyle.Font.Color           = Color.White;
                    headerRowStyle.Font.Bold            = true;

                    // Format the total row.
                    TableStyleElement totalRowStyle = customTableStyle.TableStyleElements[TableStyleElementType.TotalRow];
                    totalRowStyle.Fill.BackgroundColor = Color.FromArgb(115, 193, 211);
                    totalRowStyle.Font.Color           = Color.White;
                    totalRowStyle.Font.Bold            = true;

                    // Specify banded row formatting for the table.
                    TableStyleElement secondRowStripeStyle = customTableStyle.TableStyleElements[TableStyleElementType.SecondRowStripe];
                    secondRowStripeStyle.Fill.BackgroundColor = Color.FromArgb(234, 234, 234);
                    secondRowStripeStyle.StripeSize           = 1;
                }
                finally
                {
                    customTableStyle.EndUpdate();
                }
                // Apply the custom style to the table.
                table.Style = customTableStyle;
            }

            worksheet.Visible = true;
            #endregion #CustomTableStyle
        }
        TableStyle CreateCustomTableStyle(IWorkbook workbook, Table table)
        {
            String styleName = "testTableStyle";

            // If the style under the specified name already exists in the collection, return this style.
            if (workbook.TableStyles.Contains(styleName))
            {
                return(workbook.TableStyles[styleName]);
            }
            else
            {
                // Add a new table style under the "testTableStyle" name to the TableStyles collection.
                TableStyle customTableStyle = workbook.TableStyles.Add("testTableStyle");

                // Modify the required formatting characteristics of the table style.
                // Specify the format for different table elements.
                customTableStyle.BeginUpdate();
                try {
                    customTableStyle.TableStyleElements[TableStyleElementType.WholeTable].Font.Color = Color.FromArgb(107, 107, 107);

                    // Specify formatting characteristics for the table header row.
                    TableStyleElement headerRowStyle = customTableStyle.TableStyleElements[TableStyleElementType.HeaderRow];
                    headerRowStyle.Fill.BackgroundColor = Color.FromArgb(64, 66, 166);
                    headerRowStyle.Font.Color           = Color.White;
                    headerRowStyle.Font.Bold            = true;

                    // Specify formatting characteristics for the table total row.
                    TableStyleElement totalRowStyle = customTableStyle.TableStyleElements[TableStyleElementType.TotalRow];
                    totalRowStyle.Fill.BackgroundColor = Color.FromArgb(115, 193, 211);
                    totalRowStyle.Font.Color           = Color.White;
                    totalRowStyle.Font.Bold            = true;

                    // Specify banded row formatting for the table.
                    TableStyleElement secondRowStripeStyle = customTableStyle.TableStyleElements[TableStyleElementType.SecondRowStripe];
                    secondRowStripeStyle.Fill.BackgroundColor = Color.FromArgb(234, 234, 234);
                    secondRowStripeStyle.StripeSize           = 1;
                }
                finally {
                    customTableStyle.EndUpdate();
                }
                return(customTableStyle);
            }
        }
示例#3
0
        static void CustomTableStyle(IWorkbook workbook)
        {
            #region #CustomTableStyle
            Worksheet worksheet = workbook.Worksheets["Custom Table Style"];
            workbook.Worksheets.ActiveWorksheet = worksheet;
            Table table = worksheet.Tables[0];

            String styleName = "testTableStyle";
            if (workbook.TableStyles.Contains(styleName))
            {
                table.Style = workbook.TableStyles[styleName];
            }
            else
            {
                TableStyle customTableStyle = workbook.TableStyles.Add("testTableStyle");
                customTableStyle.BeginUpdate();
                try {
                    customTableStyle.TableStyleElements[TableStyleElementType.WholeTable].Font.Color = Color.FromArgb(107, 107, 107);
                    TableStyleElement headerRowStyle = customTableStyle.TableStyleElements[TableStyleElementType.HeaderRow];
                    headerRowStyle.Fill.BackgroundColor = Color.FromArgb(64, 66, 166);
                    headerRowStyle.Font.Color           = Color.White;
                    headerRowStyle.Font.Bold            = true;
                    TableStyleElement totalRowStyle = customTableStyle.TableStyleElements[TableStyleElementType.TotalRow];
                    totalRowStyle.Fill.BackgroundColor = Color.FromArgb(115, 193, 211);
                    totalRowStyle.Font.Color           = Color.White;
                    totalRowStyle.Font.Bold            = true;
                    TableStyleElement secondRowStripeStyle = customTableStyle.TableStyleElements[TableStyleElementType.SecondRowStripe];
                    secondRowStripeStyle.Fill.BackgroundColor = Color.FromArgb(234, 234, 234);
                    secondRowStripeStyle.StripeSize           = 1;
                }
                finally {
                    customTableStyle.EndUpdate();
                }
                table.Style = customTableStyle;
            }

            worksheet.Visible = true;
            #endregion #CustomTableStyle
        }