How to Convert Excel XLSX to XML using JavaScript
When you’re frequently converting between common file types, it’s best to pursue solutions that allow you to complete those conversions at scale. Our conversion API endpoint provides dozens of scalable, secure document conversion services for both common & uncommon file formats — and they’re all free to use with a free Cloudmersive account & API key (you can register your account on our website here and you’ll receive a limit of 800 API calls per month).
Below, I’ll demonstrate how to structure a call to our Excel XLSX to XML conversion API. The parameters are nice and simple, so all you need to do is copy/paste from ready-to-run code snippets & include your API key, and you’re good to go.
We can structure our API call in two different ways using JavaScript. The first method uses the XHR feature built into JavaScript:
var data = new FormData();
data.append("inputFile", fileInput.files[0], "file");
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});xhr.open("POST", "https://api.cloudmersive.com/convert/xlsx/to/xml");xhr.setRequestHeader("Apikey", "YOUR-API-KEY-HERE");xhr.send(data);
The second method will utilize jQuery. To install the jQuery library, run the below command:
bower install jquery
Then, copy & paste the following:
var form = new FormData();
form.append("inputFile", fileInput.files[0], "file");var settings = {
"url": "https://api.cloudmersive.com/convert/xlsx/to/xml",
"method": "POST",
"timeout": 0,
"headers": {
"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);
});
All done — no more code required. You can put your XLSX to XML conversion needs to rest!