GemBox.Spreadsheet

CellRange.GetSubrange Method 

Returns new cell range using start and end position.

public CellRange GetSubrange(
   string firstCell,
   string lastCell
);

Parameters

firstCell
Name of first (top-left) cell.
lastCell
Name of last (bottom-right) cell.

Remarks

New cell range must be within this cell range.

Exceptions

Exception Type Condition
ArgumentOutOfRangeException Thrown if arguments are out of range.

Example

Following code creates horizontal, vertical and rectangular cell ranges and demonstrates how indexing works different in different context. SetBorders method is used to mark outside borders of the rectangular range.

[Visual Basic]
    Dim cr As CellRange = excelFile.Worksheets(0).Rows(1).Cells

    cr(0).Value = cr.IndexingMode
    cr(3).Value = "D2"
    cr("B").Value = "B2"

    cr = excelFile.Worksheets(0).Columns(4).Cells

    cr(0).Value = cr.IndexingMode
    cr(2).Value = "E3"
    cr("5").Value = "E5"

    cr = excelFile.Worksheets(0).Cells.GetSubrange("F2", "J8")
    cr.SetBorders(MultipleBorders.Outside, Color.Navy, LineStyle.Dashed)

    cr("I7").Value = cr.IndexingMode
    cr(0, 0).Value = "F2"
    cr("G3").Value = "G3"
    cr(5).Value = "F3" ' Cell range width is 5 (F G H I J).
[C#]
    CellRange cr = excelFile.Worksheets[0].Rows[1].Cells;                

    cr[0].Value = cr.IndexingMode;
    cr[3].Value = "D2";
    cr["B"].Value = "B2";

    cr = excelFile.Worksheets[0].Columns[4].Cells;

    cr[0].Value = cr.IndexingMode;
    cr[2].Value = "E3";
    cr["5"].Value = "E5";

    cr = excelFile.Worksheets[0].Cells.GetSubrange("F2", "J8");
    cr.SetBorders(MultipleBorders.Outside, Color.Navy, LineStyle.Dashed);

    cr["I7"].Value = cr.IndexingMode;
    cr[0,0].Value = "F2";
    cr["G3"].Value = "G3";
    cr[5].Value = "F3"; // Cell range width is 5 (F G H I J).

See Also

CellRange Class | GemBox.Spreadsheet Namespace | StartPosition | EndPosition | GetSubrangeAbsolute | GetSubrangeRelative