Document Solutions for Excel, Java Edition | Document Solutions
Features / Worksheet / Range Operations / Access a Range
In This Topic
    Access a Range
    In This Topic

    An array of cells defined in a worksheet is called range.

    Using DsExcel Java, you can define a range and access the rows and columns in order to perform essential tasks like cell formatting, insert, merge and delete operations etc.

    In order to access a range using different methods, refer to the following example code.

    Copy Code
    // Create a new workbook
    Workbook workbook = new Workbook();
    IWorksheet worksheet = workbook.getWorksheets().get(0);
    // Using index to access cell A1.
    worksheet.getRange(0, 0).getInterior().setColor(Color.GetLightGreen());
    // Using index to access cell range A1:B2
    worksheet.getRange(0, 0, 2, 2).setValue(5);
    // Using string to access range.
    worksheet.getRange("A5:B7, C3, H5:N6").setValue(2);
    // Using index to access rows
    // Using string to access rows
    // Using index to access columns
    // Using string to access columns
    // Using Cells to access range.
    worksheet.getCells().get(5, 5).getInterior().setColor(Color.GetLightYellow());
    // Access all rows in worksheet
    String allRows = worksheet.getRows().toString();
    // Access all columns in worksheet
    String allColumns = worksheet.getColumns().toString();
    // Access the entire sheet range
    String entireSheet = worksheet.getCells().toString();
    Note: DsExcel also supports defined names, which can be used to name the range. For more information, see Defined Names.