How to merge two Excel XLSX files together in C# .NET Framework

Need to combine multiple Excel files? Not a problem. We will have things up and ready in under ten minutes. Let’s jump in.

To begin with, we will need to install our API client via NuGet, which can be done simply enough by pasting this snippet into the console of Package Manager.

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 2.2.0

Now we can use the code below to call MergeDocumentXlsx. We need to provide two input XLSX files to perform our merge on.

using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;namespace Example{public class MergeDocumentXlsxExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new MergeDocumentApi();var inputFile1 = new System.IO.Stream(); // System.IO.Stream | First input file to perform the operation on.var inputFile2 = new System.IO.Stream(); // System.IO.Stream | Second input file to perform the operation on (more than 2 can be supplied).try{// Merge Two Excel XLSX Togetherbyte[] result = apiInstance.MergeDocumentXlsx(inputFile1, inputFile2);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling MergeDocumentApi.MergeDocumentXlsx: " + e.Message );}}}}

Done! No, I’m serious, it’s really that easy. Note that this function can be performed repeatedly to combine numerous Excel files together.

Image for post

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store