WorksheetCollection.Item
Contents
[
Hide
]WorksheetCollection indexer (1 of 2)
Gets the Worksheet element at the specified index.
public Worksheet this[int index] { get; }
| Parameter | Description |
|---|---|
| index | The zero based index of the element. |
Return Value
The element at the specified index.
Examples
using System;
using Aspose.Cells;
namespace AsposeCellsExamples
{
public class WorksheetCollectionPropertyItemDemo1
{
public static void Run()
{
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;
// Using Item property to access cell
Cell cell = cells[0, 0];
cell.Formula = "=SUM(1, 2, 3)";
workbook.CalculateFormula();
Console.WriteLine("Cell value: " + cell.IntValue);
}
}
}
See Also
- class Worksheet
- class WorksheetCollection
- namespace Aspose.Cells
- assembly Aspose.Cells
WorksheetCollection indexer (2 of 2)
Gets the Worksheet element with the specified name.
public Worksheet this[string sheetName] { get; }
| Parameter | Description |
|---|---|
| sheetName | Worksheet name |
Return Value
The element with the specified name.
Examples
using System;
using Aspose.Cells;
namespace AsposeCellsExamples
{
public class WorksheetCollectionPropertyItemDemo
{
public static void Run()
{
// Create a new workbook
Workbook workbook = new Workbook();
// Access worksheets using Item property by index and name
Worksheet sheet1 = workbook.Worksheets[0];
sheet1.Name = "FirstSheet";
Worksheet sheet2 = workbook.Worksheets.Add("SecondSheet");
// Access worksheet by name using Item property
Worksheet accessedSheet = workbook.Worksheets["FirstSheet"];
// Add data to demonstrate worksheet access
Cells cells = accessedSheet.Cells;
cells["A1"].PutValue("Worksheet accessed successfully!");
cells["A2"].PutValue(DateTime.Now.ToString());
// Insert a column in the second sheet
workbook.Worksheets["SecondSheet"].Cells.InsertColumn(1);
// Save the workbook
workbook.Save("WorksheetCollectionItemDemo.xlsx");
}
}
}
See Also
- class Worksheet
- class WorksheetCollection
- namespace Aspose.Cells
- assembly Aspose.Cells