Document Solutions for Excel, Java Edition | Document Solutions
Features / Worksheet / Range Operations / Get Row and Column Count
In This Topic
    Get Row and Column Count
    In This Topic

    When you have a worksheet with bulk data, it becomes cumbersome to manually fetch the number of rows and columns.

    DsExcel Java allows users to quickly get the row and column count of the specific areas or all the areas in a range.

    The fields and methods of the IRange interface represent the cell count of all the areas in a range.

    Refer to the following example code in order to get the row count and column count in a worksheet.

    Java
    Copy Code
    IRange range = worksheet.getRange("A5:B7, C3, H5:I6");
            
    // Cell count is 11. All areas cell count
    int cellcount = range.getCount();
    System.out.println(cellcount);
            
    // Cell count is 11. All areas cell count
    int cellcount1 = range.getCells().getCount();
    System.out.println(cellcount1);
            
    // Row count is 3. First area's row count
    int rowcount = range.getRows().getCount();
    System.out.println(rowcount);
            
    // Column count is 2. First area's column count
    int columncount = range.getColumns().getCount();