ICellsDataTable.Columns
ICellsDataTable.Columns property
Gets the columns’ name.
public string[] Columns { get; }
Examples
namespace AsposeCellsExamples
{
using Aspose.Cells;
using System;
public class ICellsDataTablePropertyColumnsDemo
{
public static void Run()
{
// Create a new workbook
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
// Create sample data
worksheet.Cells["A1"].PutValue("Product");
worksheet.Cells["B1"].PutValue("Price");
worksheet.Cells["C1"].PutValue("Stock");
worksheet.Cells["A2"].PutValue("Laptop");
worksheet.Cells["B2"].PutValue(999.99);
worksheet.Cells["C2"].PutValue(15);
try
{
// Export data range to ICellsDataTable
ICellsDataTable dataTable = (ICellsDataTable)worksheet.Cells.ExportDataTable(0, 0, 2, 3);
// Display the column names
Console.WriteLine("Column names in the data table:");
foreach (string column in dataTable.Columns)
{
Console.WriteLine(column);
}
// Display the count of columns
Console.WriteLine($"Total columns: {dataTable.Columns.Length}");
// Save the workbook
workbook.Save("ColumnsDemo.xlsx");
Console.WriteLine("Columns property demonstrated successfully.");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
}
See Also
- interface ICellsDataTable
- namespace Aspose.Cells
- assembly Aspose.Cells