WorksheetCollection.Item

WorksheetCollection indexer (1 of 2)

Gets the Worksheet element at the specified index.

public Worksheet this[int index] { get; }
ParameterDescription
indexThe 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


WorksheetCollection indexer (2 of 2)

Gets the Worksheet element with the specified name.

public Worksheet this[string sheetName] { get; }
ParameterDescription
sheetNameWorksheet 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