WorksheetCollection.CreateRange

WorksheetCollection.CreateRange method

Creates a Range object from an address of the range.

public Range CreateRange(string address, int sheetIndex)
ParameterTypeDescription
addressStringThe address of the range.
sheetIndexInt32The sheet index.

Return Value

A Range object

Examples

using System;
using Aspose.Cells;

namespace AsposeCellsExamples
{
    public class WorksheetCollectionMethodCreateRangeWithStringInt32Demo
    {
        public static void Run()
        {
            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            // Populate some sample data
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    worksheet.Cells[i, j].PutValue($"Cell {i+1},{j+1}");
                }
            }

            // Create range using string address and sheet index
            Aspose.Cells.Range range = workbook.Worksheets.CreateRange("A1:F10", 0);

            // Demonstrate range usage
            Console.WriteLine($"Range has {range.RowCount} rows and {range.ColumnCount} columns");
            Console.WriteLine($"First cell value: {range[0, 0].StringValue}");
            Console.WriteLine($"Last cell value: {range[9, 5].StringValue}");
        }
    }
}

See Also