Get maximum number of rows in Excel

Different formats of MS Excel support a different number of rows and columns in a file. For example, the maximum number of rows and columns would be different for sheets in XLS and XLSX formats. While generating or processing the Excel sheets programmatically, you may need to get information about how many rows in the sheets are available. In this article, you will learn how to get the maximum number of rows in an Excel sheet in Java.

Get Maximum Number of Rows in Excel - Java Library

Aspose.Cells for Java is a popular spreadsheet manipulation library that provides an amazing set of features to generate and manipulate Excel files. We’ll use this library to find the maximum number of rows that are supported in an Excel file or format. You can either download its JAR or install it using the following Maven configuration.

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository>

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-cells</artifactId>
    <version>22.11</version>
</dependency>

Steps to Get Maximum Number of Rows in an Excel Sheet

You need to perform only a couple of steps to get the maximum number of rows in an Excel file using Aspose.Cells for Java.

  • Load the Excel file from the disk or stream.
  • Read the supported number of rows.

And that is it. Let’s now write the code and see how we can get this number from within Java applications.

Java: Find Maximum Number of Rows in an Excel File

The following steps demonstrate which classes and methods are used to load an Excel file and then find the number of rows which are supported in that file.

  • First, load the Excel file using the Workbook class.
  • Then, use Workbook.getSettings().getMaxRow() method to get the index of the maximum row.
  • Add 1 to the index value and you will get the maximum number of rows that are supported in that Excel file.

The following Java code sample shows how to find the maximum number of rows in an Excel file in Java.

Get Maximum Number of Rows in an Excel Format in Java

You can also find out the maximum number of rows supported by a specific Excel format, i.e. XLSX, XLS, etc. For this, you need to initialize the Workbook object with the desired format using FileFormatType.

The following code sample shows how to find the maximum number of rows supported in a specific Excel format.

Java Excel Library - Get a Free License

You can get a free temporary license to manipulate Excel rows and columns without evaluation limitations.

Conclusion

In this article, you have learned how to find the maximum number of rows in an Excel file in Java. Also, you can get the maximum number of rows supported by a specific Excel format. You can easily install Aspose.Cells and integrate the provided code samples into your application.

Read More about Java Spreadsheet Library

You can explore more about the Java Excel library using the documentation. Furthermore, you can share your queries with us via our forum.

See Also