Insert remove rows or columns in Excel in Java

If you’re a programmer, you might need to work with Excel spreadsheets. Sometimes you’ll need to create and fill Excel files, which I explained in a previous article. Today, I’ll show you another useful feature: inserting and deleting Excel rows and columns in Java. This can come in handy when you want to add or remove rows and columns as needed. Let’s see how you can do this in Java.

Java Library to Insert or Delete Excel Rows and Columns

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 manipulate rows and columns of the Excel sheets. 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>23.4</version>
</dependency>

Insert Rows in Excel using Java

The following are the steps to insert rows in an Excel worksheet in Java.

The following code sample shows how to insert rows in an Excel worksheet in Java.

Insert Columns in an Excel Sheet in Java

The procedure of adding the columns to an Excel sheet is similar to addition of the rows. Below are the steps to insert columns in a worksheet in Java.

The following code sample shows how to insert columns in an Excel sheet in Java.

Let’s now have a look at how to delete the rows and columns in Excel sheets using Java. First, we will discuss the deletion of rows.

Delete Rows in an Excel Sheet in Java

The following are the steps to delete rows from an Excel worksheet in Java.

The following code sample shows how to delete rows from an Excel worksheet in Java.

Delete Columns in Excel Sheet in Java

The following are the steps to delete columns from an Excel worksheet in Java.

The following code sample shows how to delete columns from an Excel worksheet using Java.

Free Java Excel Library

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 manipulate rows and columns in Excel programmatically. Particularly, you have seen how to insert and delete rows and columns in Excel worksheets using Java.

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