Merge Multiple Excel, CSV, PDF Files with Aspose.Cells Cloud REST API
Introduction
The Aspose.Cells Cloud API is a potent cloud-based solution designed for the creation, editing, and conversion of spreadsheet files. In this article, we walk you through the process of using the Aspose.Cells Cloud API to merge multiple spreadsheet files, covering typical use cases and providing example code.
Overview
The Aspose.Cells Cloud API provides robust APIs for merging multiple spreadsheet files into a single file across various formats, including Excel (XLS, XLSX), CSV, HTML, PDF, and more. By leveraging the Aspose.Cells Cloud API, you can seamlessly consolidate multiple spreadsheets into a file in widely used formats, supporting diverse business requirements.
Multiple APIs are available for file merging, each compatible with various online environments. Below is a detailed comparison of these APIs:
| Function | Description | API Reference |
|---|---|---|
| MergeSpreadsheets | Merge local spreadsheet files into a specified format file. | MergeSpreadsheets |
| MergeRemoteSpreadsheet | Merge two cloud-based spreadsheet files (primary + secondary) into a specified format file. | MergeRemoteSpreadsheet |
| MergeSpreadsheetsInRemoteFolder | Batch-merge multiple spreadsheets in a cloud folder matching a pattern into a specified format file. | MergeSpreadsheetsInRemoteFolder |
Merge Multiple Files Using Aspose.Cells Cloud API
The Aspose.Cells Cloud API supports multiple SDKs for various programming languages. Choose the SDK that aligns with your preferred language and follow the installation and initialization guide. Alternatively, you can build your own SDK using the secure API reference. In this section, we use C# as an example to detail the file-merging process.
Prerequisites
- Aspose.Cells Cloud account (free signup)
- Basic familiarity with C#/.NET
- Two local
.xlsxfiles for testing - .NET environment supporting .NET Standard 2.0+ (e.g., .NET Core 3.1+, .NET 5+)
Registration and Obtaining API Key
To begin, register an Aspose Cloud account and obtain an API key for authentication. After logging into the official Aspose Cloud website, create a free account and retrieve your Client ID and Client Secret.
Installing and Initializing the Aspose.Cells Cloud SDK
Install the Aspose.Cells-Cloud NuGet package in your .NET project using either the NuGet Package Manager Console or Visual Studio’s Package Manager UI.
To install via the Package Manager Console:
Install-Package Aspose.Cells-Cloud
Initialize the CellsApi instance using your credentials:
CellsApi cellsInstance = new CellsApi(
System.Environment.GetEnvironmentVariable("ProductClientId"),
System.Environment.GetEnvironmentVariable("ProductClientSecret")
);
Ensure environment variables ProductClientId and ProductClientSecret are set with your actual credentials.
Construct the API Request and Call the API
Merge local spreadsheets and output in any required format
using System.Collections.Generic;
using System.IO;
var cellsApi = new Aspose.Cells.Cloud.SDK.Api.CellsApi(
System.Environment.GetEnvironmentVariable("ProductClientId"),
System.Environment.GetEnvironmentVariable("ProductClientSecret")
);
// Build merged spreadsheet request
var request = new Aspose.Cells.Cloud.SDK.Request.MergeSpreadsheetsRequest();
// Set files to be merged
IDictionary<string, Stream> mapFiles = new Dictionary<string, Stream>();
mapFiles.Add("Book1.xlsx", File.OpenRead("Book1.xlsx"));
mapFiles.Add("Book2.xlsx", File.OpenRead("Book2.xlsx"));
request.Spreadsheet = mapFiles;
// Set output format
request.outFormat = "pdf";
// Perform merge and save locally
cellsApi.MergeSpreadsheets(request, "MergedResultFile.pdf");
Merge two cloud-based spreadsheets and output locally or back to cloud storage
var cellsApi = new Aspose.Cells.Cloud.SDK.Api.CellsApi(
System.Environment.GetEnvironmentVariable("ProductClientId"),
System.Environment.GetEnvironmentVariable("ProductClientSecret")
);
var request = new Aspose.Cells.Cloud.SDK.Request.MergeRemoteSpreadsheetRequest();
request.name = "Book1.xlsx"; // Primary file in cloud storage
request.folder = "RemoteFolder1"; // Folder of primary file
request.mergedSpreadsheet = "RemoteFolder2/Book2.xlsx"; // Secondary file
request.outFormat = "pdf";
cellsApi.MergeRemoteSpreadsheet(request, "MergedResultOutPutToLocalFile.pdf");
Auto-merge matching files in a cloud directory and output locally or back to cloud storage
var cellsApi = new Aspose.Cells.Cloud.SDK.Api.CellsApi(
System.Environment.GetEnvironmentVariable("ProductClientId"),
System.Environment.GetEnvironmentVariable("ProductClientSecret")
);
var request = new Aspose.Cells.Cloud.SDK.Request.MergeSpreadsheetsInRemoteFolderRequest();
request.folder = "RemoteFolder";
request.fileMatchExpression = "*.xlsx"; // Regex pattern for matching files
request.outFormat = "pdf";
cellsApi.MergeSpreadsheetsInRemoteFolder(request, "MergedResultOutPutToLocalFile.pdf");
Use Cases
The file merging capability of the Aspose.Cells Cloud API supports numerous practical scenarios:
- Merge multiple Excel files into a single Excel file for consolidated data analysis and reporting.
- Consolidate data files (e.g., CSV, JSON) into Excel format for downstream analysis or visualization.
- Combine images or reports into a PDF for easy sharing and archiving.
- Merge multiple files into HTML for embedding reports in web pages or dashboards.
Troubleshooting
- 401 Unauthorized: Ensure
ProductClientIdandProductClientSecretare correctly set as environment variables. - File not found: Verify file paths (local or cloud storage paths) are valid and accessible.
- Format incompatibility: Confirm all source files are supported and not corrupted.
- Timeout errors: For large files, consider async processing or splitting the operation.
Version Compatibility
- SDK version:
Aspose.Cells-Cloud v23.9+ - API version:
v4 - Supported .NET targets: .NET Standard 2.0, .NET Core 3.1+, .NET 5+
Conclusion
With the Aspose.Cells Cloud API, you can efficiently merge multiple spreadsheet files into a single document using simple, secure API calls. By configuring appropriate parameters and leveraging the SDKs, you can fulfill diverse merging requirements—whether local, cloud-based, or batch operations.
Integrate Aspose.Cells Cloud into your applications to streamline document consolidation, improve productivity, and reduce development overhead.
For further capabilities—such as splitting, converting, protecting, or analyzing spreadsheets—consult the Aspose.Cells Cloud developer guide.
We hope this article helps you implement robust, scalable file-merging workflows using Aspose.Cells Cloud. Good luck with your integration!