How to Convert CSV Files to XLSX in JavaScript

Cloudmersive
2 min readAug 3, 2021

--

The Comma-Separated Values (CSV) file format is a simple and straightforward format that is text only and doesn’t mess around with any bells or whistles, such as macros and formulas; as a developer, these features are often exactly what you’re looking for. However, if you need to share the data contained in the files with a partner or client, the CSV format becomes less desirable due to its busy and hard-to-read nature. By utilizing the following API in JavaScript, you will be able to automatically convert multiple CSV files into a single XLSX spreadsheet, creating a clear and comprehendible document.

Let’s start the processs by running this command to install jQuery:

bower install jquery

Now, we can input the CSV files (up to 10) and our API key into the below example code:

var form = new FormData();
form.append("inputFile1", fileInput.files[0], "file");
form.append("inputFile2", fileInput.files[0], "file");
form.append("inputFile3", fileInput.files[0], "file");
form.append("inputFile4", fileInput.files[0], "file");
form.append("inputFile5", fileInput.files[0], "file");
form.append("inputFile6", fileInput.files[0], "file");
form.append("inputFile7", fileInput.files[0], "file");
form.append("inputFile8", fileInput.files[0], "file");
form.append("inputFile9", fileInput.files[0], "file");
form.append("inputFile10", fileInput.files[0], "file");
var settings = {
"url": "https://api.cloudmersive.com/convert/csv/multi/to/xlsx",
"method": "POST",
"timeout": 0,
"headers": {
"worksheetNames": "<string>",
"Content-Type": "multipart/form-data",
"Apikey": "YOUR-API-KEY-HERE"
},
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
$.ajax(settings).done(function (response) {
console.log(response);
});

Your Excel spreadsheet will be returned as a result, with each worksheet tab corresponding to each CSV file. If you need to obtain an API key for the operation, you can do so by register for a free account on the Cloudmersive website — this provides 800 monthly calls across any of our APIs.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet