Aspose::Cells::Tables::TableStyle class

TableStyle class

Represents the table style.

class TableStyle

Methods

MethodDescription
GetName()Gets the name of table style.
GetTableStyleElements()Gets all elements of the table style.
IsNull() constChecks whether the implementation object is nullptr.
explicit operator bool() constoperator bool()
operator=(const TableStyle& src)operator=
TableStyle(TableStyle_Impl* impl)Constructs from an implementation object.
TableStyle(const TableStyle& src)Copy constructor.
~TableStyle()Destructor.

Fields

FieldDescription
_implThe implementation object.

Examples

Aspose::Cells::Startup();
Workbook workbook;
Style firstColumnStyle = workbook.CreateStyle();
firstColumnStyle.SetPattern(BackgroundType::Solid);
firstColumnStyle.SetBackgroundColor(Color{ 0xff, 0xff, 0, 0 });//Red

Style lastColumnStyle = workbook.CreateStyle();
lastColumnStyle.GetFont().SetIsBold(true);
lastColumnStyle.SetPattern(BackgroundType::Solid);
lastColumnStyle.SetBackgroundColor(Color{ 0xff, 0xff, 0, 0 });//Red
U16String tableStyleName = u"Custom1";
TableStyleCollection tableStyles = workbook.GetWorksheets().GetTableStyles();
int index1 = tableStyles.AddTableStyle(tableStyleName);
TableStyle tableStyle = tableStyles.Get(index1);
TableStyleElementCollection elements = tableStyle.GetTableStyleElements();
index1 = elements.Add(TableStyleElementType::FirstColumn);
TableStyleElement element = elements.Get(index1);
element.SetElementStyle(firstColumnStyle);
index1 = elements.Add(TableStyleElementType::LastColumn);
element = elements.Get(index1);
element.SetElementStyle(lastColumnStyle);
Cells cells = workbook.GetWorksheets().Get(0).GetCells();
for (int i = 0; i < 5; i++)
{
    cells.Get(0, i).PutValue(CellsHelper::ColumnIndexToName(i));
}
for (int row = 1; row < 10; row++)
{
    for (int column = 0; column < 5; column++)
    {
        cells.Get(row, column).PutValue(row * column);
    }
}
ListObjectCollection tables = workbook.GetWorksheets().Get(0).GetListObjects();
int index = tables.Add(0, 0, 9, 4, true);
ListObject table = tables.Get(0);
table.SetShowTableStyleFirstColumn(true);
table.SetShowTableStyleLastColumn(true);
table.SetTableStyleName(tableStyleName);
workbook.Save(u"Book1.xlsx");

Aspose::Cells::Cleanup();

See Also