Fill Out a Series of Cells in Excel in Java

The insertion of data into a range of cells in Excel represents a critical aspect of effective and efficient data management in diverse industries. The importance of inserting data into a range of cells in Excel cannot be overstated, particularly for those seeking to streamline their data management processes and gain insights from their data. The automated insertion of data into a range of cells in Excel utilizing Java guarantees data accuracy while saving time. This approach diminishes the risk of human error, delivering an added layer of reliability. In this article, we will explain (step-by-step) how to fill out a series of cells in Excel in Java with and without the Autofill feature.

The following points will be covered in this article:

Java Excel Manipulation Library - Installation

The installation procedure of this Java Excel Manipulation Library is very simple. The Maven users can simply add the following configurations in the pom.xml file.

<repository>
	<id>ConholdateJavaAPI</id>
	<name>Conholdate Java API</name>
	<url>https://releases.conholdate.com/java/repo</url>
</repository>        
<dependency>
	<groupId>com.conholdate</groupId>
	<artifactId>conholdate-total</artifactId>
	<version>23.6</version>
	<type>pom</type>
</dependency>

Then run the following commands.

mvn clean    
mvn install -U

To configure other Java frameworks, please visit releases.conholdate.com.

Java Insert Data in a Range of Cells in Excel

Suppose you selected a range of cells that extends over A1:C4. This matrix will create 12 cells which are arranged sequentially. We will describe simple steps to help you easily insert data into that range of cells in Excel using our Java Excel manipulation API.

  1. First, instantiate the object of Workbook class.
  2. Then, obtain the Cells collection from default Worksheet object.
  3. After that, create the range of cells using the Cells.createRange method.
  4. Then, insert the values in the cells located sequentially in the Range object.
  5. Finally, save the workbook.

The following code sample demonstrates how to insert data in a range of cells in Excel using Java. The resultant Excel file will look like the following screenshot.

Java Insert Data in a Range of Cells in Excel

Autofill Cells Range in Excel in Java - Steps to Write Code

Autofill works by detecting the value pattern in the first few cells of a range and then automatically filling the following cells with the same pattern.

Suppose you have a series of dates in cell A1 that begin with “1/1/2022”. Drag the fill handle down the column, Excel will automatically fill the cells below with the following date in the sequence, such as “1/2/2022,” “1/3/2022,” and so on.

Our Java Excel library allows you to do this task programmatically with just a few lines of code.

Following are the steps to auto-fill cells range in Excel in Java:

  1. First, load the Excel file using the Workbook class.
  2. Second, get the cells of default Excel worksheet.
  3. Third, create the source and destination ranges of cells using the Cells.createRange method.
  4. Forth, auto-fill the destination range according to the source range using the Range.autoFill method.
  5. Finally, save the workbook.

The following code sample demonstrates how to auto-fill data in a range of cells in Excel using Java. The following image shows the input and output screenshots side-by-side.

Java Autofill in Excel Cells Range

Get a Free License

You can download a free temporary license to test the API without evaluation limitations.

Conclusion

To conclude, we hope you have learned how to fill out a series of cells in Excel in Java using a Java Excel management library. We have discussed the simple ways to put the values in cells of a range in Excel with and without the Autofill feature.

You may visit the documentation to learn more about the Java Excel management API.

Finally, please keep visiting conholdate.com for regular updates.

Ask a Question

You can post your questions or comments in our forum.

See Also