static void DuplicateTableStyle(Workbook workbook) { #region #DuplicateTableStyle Worksheet worksheet = workbook.Worksheets["Duplicate Table Style"]; workbook.Worksheets.ActiveWorksheet = worksheet; // Access table. Table table1 = worksheet.Tables[0]; Table table2 = worksheet.Tables[1]; // Obtain the built-in table style. TableStyle sourceTableStyle = workbook.TableStyles[BuiltInTableStyleId.TableStyleMedium17]; // Duplicate the table style. TableStyle newTableStyle = sourceTableStyle.Duplicate(); // Modify the duplicated table style's formatting. newTableStyle.TableStyleElements[TableStyleElementType.HeaderRow].Fill.BackgroundColor = Color.FromArgb(0xA7, 0xEA, 0x52); // Apply styles to tables. table1.Style = sourceTableStyle; table2.Style = newTableStyle; worksheet.Visible = true; #endregion #DuplicateTableStyle }
TableStyle DuplicateAndModifyTableStyle(IWorkbook workbook, string sourceStyleName) { // Get the table style to be duplicated. TableStyle sourceTableStyle = workbook.TableStyles[sourceStyleName]; // Duplicate the table style. TableStyle newTableStyle = sourceTableStyle.Duplicate(); // Modify the required formatting characteristics of the created table style. // For example, remove exisitng formatting from the header row element. newTableStyle.TableStyleElements[TableStyleElementType.HeaderRow].Clear(); return(newTableStyle); }
static void DuplicateTableStyle(IWorkbook workbook) { #region #DuplicateTableStyle Worksheet worksheet = workbook.Worksheets["Duplicate Table Style"]; workbook.Worksheets.ActiveWorksheet = worksheet; Table table1 = worksheet.Tables[0]; Table table2 = worksheet.Tables[1]; TableStyle sourceTableStyle = workbook.TableStyles[BuiltInTableStyleId.TableStyleMedium19]; TableStyle newTableStyle = sourceTableStyle.Duplicate(); newTableStyle.TableStyleElements[TableStyleElementType.HeaderRow].Clear(); table1.Style = sourceTableStyle; table2.Style = newTableStyle; worksheet.Visible = true; #endregion #DuplicateTableStyle }