/// <summary> /// Format cells in the range into a table with possible title /// </summary> /// <param name="range">The table's cells</param> /// <param name="title">The table's title, if null, the table won't have title</param> /// <param name="color">Color palette of the table</param> /// <param name="showColumnHeader">Defines if the table has column header</param> /// <param name="showRowHeader">Defines if the table has row header</param> /// <returns></returns> public static int FormatAsTableWithTitle(this ExcelRange range, string title, ExcelColor color = ExcelColor.Primary, bool showColumnHeader = true, bool showRowHeader = true) { var ws = range.Worksheet; var palette = PaletteStorage.GetPalette(color); ExcelRange tableRange = range; var nextRow = range.Start.Row; if (title != null) { //Get the title's cells and format title var titleCells = ws.Cells[range.Start.Row, range.Start.Column, range.Start.Row, range.End.Column]; titleCells.Fill(palette.DarkColor); titleCells.Merge(); titleCells.BorderAround(); titleCells.Value = title; //if there's title then the range should be changed after (pushed down by one row) tableRange = ws.Cells[range.Start.Row + 1, range.Start.Column, range.End.Row + 1, range.End.Column]; nextRow++; } //Format table under title tableRange.FormatAsTable(color, showColumnHeader, showRowHeader); return(nextRow); }