Table of Contents

Interface IListObject

Namespace
Spire.Xls.Core
Assembly
Spire.XLS.dll

Represents a table on a worksheet.

public interface IListObject

Properties

AutoFilters

Gets the AutoFiltersCollection collection in the table. Read-only.

AutoFiltersCollection AutoFilters { get; }

Property Value

AutoFiltersCollection

BuiltInTableStyle

Gets or sets the built-in table style for the specified ListObject object. The following code illustrates how to set TableBuiltInStyles.TableStyleMedium9 to BuiltInTableStyle property:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create table
IListObject table1 = worksheet.ListObjects.Create("Table1", worksheet["A1:C6"]);

//Apply builtin style
table1.BuiltInTableStyle = TableBuiltInStyles.TableStyleMedium9;

//Save to file
workbook.SaveToFile("Table.xlsx");
TableBuiltInStyles BuiltInTableStyle { get; set; }

Property Value

TableBuiltInStyles

Columns

Gets collection of all columns of the list object. The following code illustrates how to access Columns property of the table:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create table
IListObject table1 = worksheet.ListObjects.Create("Table1", worksheet["A1:C6"]);

//Total row
table1.DisplayTotalRow = true;
table1.Columns[0].TotalsRowLabel = "Total";
table1.Columns[1].TotalsCalculation = ExcelTotalsCalculation.Sum;
table1.Columns[2].TotalsCalculation = ExcelTotalsCalculation.Sum;

//Save to file
workbook.SaveToFile("Table.xlsx");
IList<IListObjectColumn> Columns { get; }

Property Value

IList<IListObjectColumn>

DisplayFirstColumn

Gets or sets a value indicating whether first column is present. The following code illustrates how to set DisplayFirstColumn to "true" to enable the format for the first column:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create table
IListObject table1 = worksheet.ListObjects.Create("Table1", worksheet["A1:C6"]);

//Set Column Visiblity
table1.DisplayFirstColumn = true;
table1.DisplayLastColumn = true;

//Save to file
workbook.SaveToFile("Table.xlsx");
bool DisplayFirstColumn { get; set; }

Property Value

bool

DisplayHeaderRow

Gets or sets a Boolean value indicating whether to hide/display header row. The following code illustrates how to hide the header row of the table:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create table
IListObject table1 = worksheet.ListObjects.Create("Table1", worksheet["A1:C6"]);

//Set Header Visiblity
table1.DisplayHeaderRow = true;

//Save to file
workbook.SaveToFile("Table.xlsx");
bool DisplayHeaderRow { get; set; }

Property Value

bool

DisplayLastColumn

Gets or sets a value indicating whether last column is present. The following code illustrates how to set DisplayLastColumn to "true" to enable the format for the last column:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create table
IListObject table1 = worksheet.ListObjects.Create("Table1", worksheet["A1:C6"]);

//Set Column Visiblity
table1.DisplayFirstColumn = true;
table1.DisplayLastColumn = true;

//Save to file
workbook.SaveToFile("Table.xlsx");
bool DisplayLastColumn { get; set; }

Property Value

bool

DisplayName

Gets or sets list object name. The following code illustrates how the get the DisplayName and print it to console:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create table
IListObject table1 = worksheet.ListObjects.Create("Table1", worksheet["A1:C6"]);

//Get Table display name
Console.WriteLine(table1.DisplayName);

//Save to file
workbook.SaveToFile("Table.xlsx");
string DisplayName { get; set; }

Property Value

string

DisplayTotalRow

Gets or sets a value indicating whether the Total row is visible. The following code illustrates how to enable it by setting it to "True" and show the sum of values in second and third columns in the totals row:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create table
IListObject table1 = worksheet.ListObjects.Create("Table1", worksheet["A1:C6"]);

//Show total row
table1.DisplayTotalRow = true;
table1.Columns[0].TotalsRowLabel = "Total";
table1.Columns[1].TotalsCalculation = ExcelTotalsCalculation.Sum;
table1.Columns[2].TotalsCalculation = ExcelTotalsCalculation.Sum;

//Save to file
workbook.SaveToFile("Table.xlsx");
bool DisplayTotalRow { get; set; }

Property Value

bool

Index

Gets index of the current list object. The following code illustrates how to access the index of the table:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create table
IListObject table1 = worksheet.ListObjects.Create("Table1", worksheet["A1:C6"]);

//Print Table index
Console.WriteLine(table1.Index);

//Save to file
workbook.SaveToFile("Table.xlsx");
int Index { get; }

Property Value

int

Location

Gets or sets list object's location. The following code illustrates how table range can be set and accessed:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create table
IListObject table1 = worksheet.ListObjects.Create("Table1", worksheet["A1:C6"]);

//Set Table Range
table1.Location = worksheet.Range["A1:C7"];

//Get Table Range
Console.WriteLine(table1.Location.RangeAddressLocal.ToString());

//Save to file
workbook.SaveToFile("Table.xlsx");
IXLSRange Location { get; set; }

Property Value

IXLSRange

Name

Gets or sets name of the list object. The following code illustrates how to access Name property of the table:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create table
IListObject table1 = worksheet.ListObjects.Create("Table1", worksheet["A1:C6"]);

//Set Table Name
table1.Name = "Products";

//Get Table Name
Console.WriteLine(table1.Name);

//Save to file
workbook.SaveToFile("Table.xlsx");
string Name { get; set; }

Property Value

string

ShowTableStyleColumnStripes

Gets or sets a value indicating whether column stripes should be present. The following code illustrates how to set ShowTableStyleRowStripes to "False" and set ShowTableStyleColumnStripes to "True" to change the default formatting of the table:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create table
IListObject table1 = worksheet.ListObjects.Create("Table1", worksheet["A1:C6"]);

//Set Row Column Stripe Visiblity
table1.ShowTableStyleRowStripes = false;
table1.ShowTableStyleColumnStripes = true;

//Apply builtin style
table1.BuiltInTableStyle = TableBuiltInStyles.TableStyleMedium9;

//Create style for table number format
IStyle style1 = workbook.Styles.Add("CurrencyFormat");
style1.NumberFormat = "_($* #,##0.00_);_($* (#,##0.00);_($* \" - \"??_);_(@_)";

//Apply number format
worksheet["B2:C6"].CellStyleName = "CurrencyFormat";

//Save to file
workbook.SaveToFile("Table.xlsx");
bool ShowTableStyleColumnStripes { get; set; }

Property Value

bool

ShowTableStyleRowStripes

Gets or sets a value indicating whether row stripes should be present. The following code illustrates how to set ShowTableStyleRowStripes to "False" and set ShowTableStyleColumnStripes to "True" to enable table formatting in columns only:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create table
IListObject table1 = worksheet.ListObjects.Create("Table1", worksheet["A1:C6"]);

//Set Row Column Stripe Visiblity
table1.ShowTableStyleRowStripes = false;
table1.ShowTableStyleColumnStripes = true;

//Apply builtin style
table1.BuiltInTableStyle = TableBuiltInStyles.TableStyleMedium9;

//Create style for table number format
IStyle style1 = workbook.Styles.Add("CurrencyFormat");
style1.NumberFormat = "_($* #,##0.00_);_($* (#,##0.00);_($* \" - \"??_);_(@_)";

//Apply number format
worksheet["B2:C6"].CellStyleName = "CurrencyFormat";

//Save to file
workbook.SaveToFile("Table.xlsx");
bool ShowTableStyleRowStripes { get; set; }

Property Value

bool

TotalsRowCount

Gets number of totals rows. The following code illustrates how to get the totals rows count:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create table
IListObject table1 = worksheet.ListObjects.Create("Table1", worksheet["A1:C6"]);

//Check totals row count
Console.WriteLine(table1.TotalsRowCount);

//Save to file
workbook.SaveToFile("Table.xlsx");
int TotalsRowCount { get; }

Property Value

int

Worksheet

Gets parent worksheet object. The following code illustrates how the parent worksheet can be accessed:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Create table
IListObject table1 = worksheet.ListObjects.Create("Table1", worksheet["A1:C6"]);

//Get parent worksheet's name
Console.WriteLine(table1.Worksheet.Name);

//Save to file
workbook.SaveToFile("Table.xlsx");
IWorksheet Worksheet { get; }

Property Value

IWorksheet