Class TableStyleElementCollection
Contents
[
Hide
]TableStyleElementCollection class
Represents all elements of the table style.
public class TableStyleElementCollection : CollectionBase<TableStyleElement>
Properties
Name | Description |
---|---|
Capacity { get; set; } | |
Count { get; } | |
Item { get; } | Gets an element of the table style by the index. (2 indexers) |
Item { get; set; } |
Methods
Name | Description |
---|---|
Add(TableStyleElementType) | Adds an element. |
BinarySearch(TableStyleElement) | |
BinarySearch(TableStyleElement, IComparer<TableStyleElement>) | |
BinarySearch(int, int, TableStyleElement, IComparer<TableStyleElement>) | |
Clear() | |
Contains(TableStyleElement) | |
CopyTo(TableStyleElement[]) | |
CopyTo(TableStyleElement[], int) | |
CopyTo(int, TableStyleElement[], int, int) | |
Exists(Predicate<TableStyleElement>) | |
Find(Predicate<TableStyleElement>) | |
FindAll(Predicate<TableStyleElement>) | |
FindIndex(Predicate<TableStyleElement>) | |
FindIndex(int, Predicate<TableStyleElement>) | |
FindIndex(int, int, Predicate<TableStyleElement>) | |
FindLast(Predicate<TableStyleElement>) | |
FindLastIndex(Predicate<TableStyleElement>) | |
FindLastIndex(int, Predicate<TableStyleElement>) | |
FindLastIndex(int, int, Predicate<TableStyleElement>) | |
GetEnumerator() | |
IndexOf(TableStyleElement) | |
IndexOf(TableStyleElement, int) | |
IndexOf(TableStyleElement, int, int) | |
LastIndexOf(TableStyleElement) | |
LastIndexOf(TableStyleElement, int) | |
LastIndexOf(TableStyleElement, int, int) | |
RemoveAt(int) |
Examples
[C#]
namespace Demos
{
using Aspose.Cells;
using Aspose.Cells.Tables;
using System;
public class TableStyleElementCollectionDemo
{
public static void TableStyleElementCollectionExample()
{
// Create a new workbook
Workbook workbook = new Workbook();
// Create styles for the first and last columns
Style firstColumnStyle = workbook.CreateStyle();
firstColumnStyle.Pattern = BackgroundType.Solid;
firstColumnStyle.BackgroundColor = System.Drawing.Color.Red;
Style lastColumnStyle = workbook.CreateStyle();
lastColumnStyle.Font.IsBold = true;
lastColumnStyle.Pattern = BackgroundType.Solid;
lastColumnStyle.BackgroundColor = System.Drawing.Color.Red;
// Define a custom table style name
string tableStyleName = "Custom1";
// Access the table styles collection
TableStyleCollection tableStyles = workbook.Worksheets.TableStyles;
// Add a new table style to the collection
int index1 = tableStyles.AddTableStyle(tableStyleName);
TableStyle tableStyle = tableStyles[index1];
// Access the table style elements collection
TableStyleElementCollection elements = tableStyle.TableStyleElements;
// Add and configure the first column style element
index1 = elements.Add(TableStyleElementType.FirstColumn);
TableStyleElement element = elements[index1];
element.SetElementStyle(firstColumnStyle);
// Add and configure the last column style element
index1 = elements.Add(TableStyleElementType.LastColumn);
element = elements[index1];
element.SetElementStyle(lastColumnStyle);
// Populate the worksheet with sample data
Cells cells = workbook.Worksheets[0].Cells;
for (int i = 0; i < 5; i++)
{
cells[0, i].PutValue(CellsHelper.ColumnIndexToName(i));
}
for (int row = 1; row < 10; row++)
{
for (int column = 0; column < 5; column++)
{
cells[row, column].PutValue(row * column);
}
}
// Add a table to the worksheet
ListObjectCollection tables = workbook.Worksheets[0].ListObjects;
int index = tables.Add(0, 0, 9, 4, true);
ListObject table = tables[index];
// Apply the custom table style to the table
table.ShowTableStyleFirstColumn = true;
table.ShowTableStyleLastColumn = true;
table.TableStyleName = tableStyleName;
// Save the workbook
workbook.Save("TableStyleElementCollectionExample.xlsx");
}
}
}
See Also
- class CollectionBase<T>
- class TableStyleElement
- namespace Aspose.Cells.Tables
- assembly Aspose.Cells