TableStyleElementCollection.Item
Contents
[
Hide
]TableStyleElementCollection indexer (1 of 2)
Gets an element of the table style by the index.
public TableStyleElement this[int index] { get; }
| Parameter | Description |
|---|---|
| index | The index. |
Return Value
Returns TableStyleElement object
Examples
using System;
using Aspose.Cells;
using Aspose.Cells.Tables;
namespace AsposeCellsExamples
{
public class TableStyleElementCollectionPropertyItemDemo
{
public static void Run()
{
Workbook workbook = new Workbook();
Style firstColStyle = workbook.CreateStyle();
firstColStyle.Pattern = BackgroundType.Solid;
firstColStyle.BackgroundColor = System.Drawing.Color.LightBlue;
string styleName = "CustomTableStyle";
TableStyleCollection tableStyles = workbook.Worksheets.TableStyles;
int styleIndex = tableStyles.AddTableStyle(styleName);
TableStyle tableStyle = tableStyles[styleIndex];
TableStyleElementCollection elements = tableStyle.TableStyleElements;
int elementIndex = elements.Add(TableStyleElementType.FirstColumn);
TableStyleElement element = elements[elementIndex];
element.SetElementStyle(firstColStyle);
Cells cells = workbook.Worksheets[0].Cells;
cells["A1"].PutValue("Header");
cells["A2"].PutValue("Data");
int tableIndex = workbook.Worksheets[0].ListObjects.Add(0, 0, 1, 0, true);
ListObject table = workbook.Worksheets[0].ListObjects[tableIndex];
table.ShowTableStyleFirstColumn = true;
table.TableStyleName = styleName;
workbook.Save("TableStyleElementDemo.xlsx");
}
}
}
See Also
- class TableStyleElement
- class TableStyleElementCollection
- namespace Aspose.Cells.Tables
- assembly Aspose.Cells
TableStyleElementCollection indexer (2 of 2)
Gets the element of the table style by the element type.
public TableStyleElement this[TableStyleElementType type] { get; }
| Parameter | Description |
|---|---|
| type | The element type. |
Return Value
Returns TableStyleElement object
Examples
namespace AsposeCellsExamples
{
using Aspose.Cells;
using Aspose.Cells.Tables;
using System;
public class TableStyleElementCollectionPropertyItemDemo1
{
public static void Run()
{
// Create a new workbook
Workbook workbook = new Workbook();
// Create a custom table style
string styleName = "CustomTableStyle";
TableStyleCollection tableStyles = workbook.Worksheets.TableStyles;
int styleIndex = tableStyles.AddTableStyle(styleName);
TableStyle tableStyle = tableStyles[styleIndex];
// Access the TableStyleElementCollection
TableStyleElementCollection elements = tableStyle.TableStyleElements;
// Add a table style element
int elementIndex = elements.Add(TableStyleElementType.FirstColumn);
try
{
// Access the Item property using the indexer (which uses the Item property internally)
TableStyleElement element = elements[elementIndex];
// Display information about the element
Console.WriteLine("Table Style Element Type: " + element.Type);
Console.WriteLine("Element has been successfully accessed via Item property");
// Save the workbook
workbook.Save("TableStyleElementItemDemo.xlsx");
Console.WriteLine("Workbook saved successfully.");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
}
See Also
- class TableStyleElement
- enum TableStyleElementType
- class TableStyleElementCollection
- namespace Aspose.Cells.Tables
- assembly Aspose.Cells