Two and more spreadsheets are often required to get merged. In order to combine Excel files in large numbers or merge them within your application, you can write just a few lines of Java code. This article discusses ways how you can merge Excel files and spreadsheets into a single one in Java. Further, it also shows how to join specific sheets from different files.

The following topics are covered in this article:

Java API to Merge Excel Files

GroupDocs showcases document automation Java APIs for merging identical and distinct types of documents. Along with merging multiple Excel files, it also allows documents to split, move certain pages, and remove, swap, or extract pages from various documents using very thin code.

This article uses GroupDocs.Merger for Java in the examples. You can download the JAR file from the downloads section or use the latest repository and dependency configurations within your Maven-based Java applications.

<dependency>
  <groupId>com.groupdocs</groupId>
  <artifactId>groupdocs-merger</artifactId>
  <version>22.12</version>
</dependency>

How to Merge Excel Files and Spreadsheets in Java

If two spreadsheets have identical or matching records, these can be combined to eliminate data redundancy and confusion. The following are the steps for how to combine Excel files (XLS or XLSX) within the Java application.

  • Load the first Excel spreadsheet using the Merger class.
  • Combine the second spreadsheet using the join method.
  • Keep joining more spreadsheets using the same join Method.
  • Save the merged spreadsheet output file using the save method.

The following Java code snippet merges multiple Excel spreadsheets.

How to Merge Specific Sheets of Multiple Excel files in Java

You can also merge specific sheets of your choice from the multiple Excel spreadsheet files. The following steps show how to merge specific sheets from Excel files in Java.

  • Load the first Excel file using the Merger class.
  • Select the specific sheets to join using the JoinOptions class.
  • Now, combine both sets of spreadsheets using the join method with the prepared join options.
  • Save the merged spreadsheets into a separate file using the save method.

The following Java code snippet combines the selected spreadsheets of the multiple Excel files into one.

Free API License

You can get a free temporary license and merge your Excel files data without evaluation limitations.

Conclusion

To sum up, today we discussed how two or more Excel spreadsheets can be merged within the Java application. More specifically first, we combined all the sheets of Excel files. Later, we merged a few selected sheets from multiple files into one. You can use the document merging feature within your Java applications to combine multiple Excel files online.

Learn More & Get in Touch

In case you want to know more about the .NET Merger API by GroupDocs, visit: Documentation | API Reference | GitHub Examples

Contact us on the forum about any queries.

See Also