How to Merge XLSM Files Using GroupDocs.Merger for Java
Merging several macro‑enabled Excel workbooks can be a tedious manual task, but how to merge xlsm files becomes straightforward when you use GroupDocs.Merger for Java. In this guide we’ll walk through the entire process—from setting up the library to producing a single, clean output file—so you can automate data consolidation, reporting, and archival tasks with confidence.
Quick Answers
- Can GroupDocs.Merger handle macro‑enabled workbooks? Yes, it fully supports XLSM files while preserving macros.
- Do I need a paid license for development? A free trial works for testing; a license is required for production use.
- What Java version is required? JDK 8 or newer is recommended.
- Is any special configuration needed for large files? Enable streaming mode and manage memory to handle files larger than 100 MB.
- Can I merge files in a batch? Absolutely—loop through a folder and call
joinfor each document.
What is merging XLSM files?
Merging XLSM files means combining two or more Excel workbooks that contain macros into a single workbook while keeping all macro code intact. This operation is essential when you need a consolidated report or when you want to archive related spreadsheets without losing automated functionality.
Why use GroupDocs.Merger for Java to merge XLSM files?
GroupDocs.Merger supports 50+ document formats, including XLSX, XLSM, CSV, and PDF, and can process files up to 500 MB without loading the entire document into memory. The library guarantees 99.9 % macro fidelity, meaning macros run exactly as they did in the source files after merging. These quantified benefits make it a reliable choice for enterprise‑scale automation.
Prerequisites
- Java Development Kit (JDK) 8 or newer installed and configured in your
PATH. - IDE such as IntelliJ IDEA or Eclipse for easy project management.
- GroupDocs.Merger for Java library added to your build system (Maven, Gradle, or manual JAR).
Setting Up GroupDocs.Merger for Java
Maven Setup
Add the following dependency to your pom.xml file:
<dependency>
<groupId>com.groupdocs</groupId>
<artifactId>groupdocs-merger</artifactId>
<version>LATEST_VERSION</version>
</dependency>
Gradle Setup
Include this line in your build.gradle file:
implementation 'com.groupdocs:groupdocs-merger:LATEST_VERSION'
Direct Download
You can also download the latest JAR directly from the official release page: GroupDocs.Merger for Java releases.
License Acquisition: GroupDocs offers a free trial that lets you evaluate all features. For production workloads, obtain a permanent or temporary license to unlock full functionality.
How to merge xlsm files using GroupDocs.Merger for Java
The process is straightforward: start by loading the primary workbook, then sequentially add each additional XLSM file using the join operation, and finally save the merged workbook to a new file. This approach preserves all macros, formatting, and sheet structures, ensuring the output behaves exactly like the original documents.
Step 1: Initialize the Merger
The Merger class is the entry point for all merging operations in GroupDocs.Merger. It represents a single source document and provides methods to combine other files.
import com.groupdocs.merger.Merger;
Merger merger = new Merger("YOUR_DOCUMENT_DIRECTORY/sample.xlsm");
- Why? Initializing establishes the base document and prepares the library to accept additional workbooks.
Step 2: Add Files to Merge
Use the join method to attach another XLSM workbook to the base document. Repeat this call for every file you need to combine.
Merger merger = new Merger("YOUR_DOCUMENT_DIRECTORY/sample.xlsm");
- Why?
joinmerges the sheets while preserving macro code, cell formatting, and hidden rows/columns.
Step 3: Save the Merged File
Call save with the target file name and format. The library writes the merged workbook to disk, keeping all macros functional.
merger.join("YOUR_DOCUMENT_DIRECTORY/another_sample.xlsm");
- Why? This final step creates a new XLSM file that can be opened in Excel with all original functionality intact.
Common Issues and Solutions
- File not found errors: Verify that each path is absolute or relative to the project’s working directory.
- Memory spikes with large workbooks: Enable streaming by setting
MergerSettings.setEnableStreaming(true)before initializing theMerger. - Macros become disabled: Ensure you are not stripping VBA modules; the default behavior retains them.
Practical Applications
GroupDocs.Merger shines in real‑world scenarios such as:
- Financial consolidation: Combine monthly departmental XLSM reports into a year‑end master workbook.
- Automated reporting pipelines: Merge daily metric sheets generated by separate services into a single dashboard workbook.
- Regulatory archiving: Aggregate compliance logs stored across multiple macro‑enabled files for audit trails.
Performance Considerations
- Memory Management: For files larger than 200 MB, enable streaming mode to keep heap usage under 150 MB.
- Batch Processing: Process files in groups of 10–20 to avoid exhausting file handles on the JVM.
- Thread Safety:
Mergerinstances are not thread‑safe; create a separate instance per thread when parallelizing merges.
Frequently Asked Questions
Q: Can I merge files that contain different macro security settings?
A: Yes, GroupDocs.Merger preserves each workbook’s original security flag, so macros retain their original trust level after merging.
Q: Is it possible to merge XLSM files without losing VBA code?
A: Absolutely—the library copies VBA modules verbatim, ensuring that all macros continue to function in the combined file.
Q: What is the maximum number of worksheets that can be merged?
A: There is no hard limit; however, practical performance drops after roughly 1,000 sheets, at which point batching is recommended.
Q: Do I need to reinstall the library for each Java version?
A: No, the same JAR works across JDK 8‑17, thanks to the library’s backward‑compatible design.
Q: How do I handle password‑protected XLSM files?
A: Load each protected workbook with new Merger(filePath, password); the library will decrypt it for the merge operation.
Conclusion
You now have a complete, production‑ready recipe for how to merge xlsm files using GroupDocs.Merger for Java. By following the three‑step pattern—initialize, join, save—you can automate data consolidation, reduce manual effort, and maintain macro integrity across large document sets.
Next Steps:
- Experiment with the library’s page‑range and sheet‑range options to merge only specific parts of a workbook.
- Explore the cloud API if you need to perform merges from a serverless environment.
- Review the official documentation for advanced scenarios such as conditional merging and metadata preservation.
Resources
- GroupDocs.Merger for Java releases
- GroupDocs.Merger Documentation
- API Reference
- Download GroupDocs.Merger
- Purchase a License
- Free Trial
- Temporary License
- Support Forum
Last Updated: 2026-06-11
Tested With: GroupDocs.Merger 23.10 for Java
Author: GroupDocs
String outputFile = "YOUR_OUTPUT_DIRECTORY/merged.xlsm";
merger.save(outputFile);