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:
- Installing Java Excel Manipulation Library
- Put Data in a Range of Cells in Excel using Java
- Java Autofill in Excel Cells Range
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>22.12</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.
- First, instantiate the object of Workbook class.
- Then, obtain the Cells collection from default Worksheet object.
- After that, create the range of cells using the Cells.createRange method.
- Then, insert the values in the cells located sequentially in the Range object.
- 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.
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:
- First, load the Excel file using the Workbook class.
- Second, get the cells of default Excel worksheet.
- Third, create the source and destination ranges of cells using the Cells.createRange method.
- Forth, auto-fill the destination range according to the source range using the Range.autoFill method.
- 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.
Get a Free License
You can download a free temporary license to test the API without evaluation limitations.
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.