Skip to main content

IXlSheetSelection.SelectedRanges Property

Returns cell ranges selected in a worksheet.

Namespace: DevExpress.Export.Xl

Assembly: DevExpress.Printing.v24.1.Core.dll

NuGet Package: DevExpress.Printing.Core

Declaration

IList<XlCellRange> SelectedRanges { get; }

Property Value

Type Description
IList<XlCellRange>

A list of selected ranges.

Remarks

The following properties allow you to select cells in a worksheet:

  • IXlSheet.Selection.SelectedRanges - specifies selected cell ranges. If you don’t select any range in a worksheet, the selection includes only an active cell.

  • IXlSheet.Selection.ActiveCell - specifies an active cell (“A1” is active by default). An active cell can belong to the current selection or lie outside the selected ranges.

XL-Export-Selection

The following code example sets a selection and an active cell as shown in the image above. Note that you should specify a selection before you begin to generate the worksheet’s content.

// Create a new document and begin to write it to the stream.
using (IXlDocument document = exporter.CreateDocument(stream))
{
    // Add a new worksheet to the document.
    using (IXlSheet sheet = document.CreateSheet())
    {
        // Specify the selected ranges.
        IList<XlCellRange> selectedRanges = sheet.Selection.SelectedRanges;
        selectedRanges.Add(XlCellRange.FromLTRB(0, 1, 2, 3)); // A2:C4
        selectedRanges.Add(XlCellRange.FromLTRB(2, 5, 3, 8)); // C6:D9

        // Set the active cell.
        sheet.Selection.ActiveCell = new XlCellPosition(1, 2); // B3

        // Generate the document content.
        // ...
    }
}
See Also