The below code successfully downloads the xls file but the data are in the same column. how can I make it to the different column. The code seems working perfectly if I use csv but with xls it is not working like expected. I just want to make it like it appears on csv data.
var data = [
['name1', 'city1', 'some other info'],
['name2', 'city2', 'more info'],
['name2', 'city2', 'more info'],
['name2', 'city2', 'more info'],
['name2', 'city2', 'more info'],
['name2', 'city2', 'more info']
];
var csvContent = '';
data.forEach(function(infoArray, index) {
dataString = infoArray.join(" ");
csvContent += index < data.length ? dataString + '\n' : dataString;
});
var download = function(content, fileName, mimeType) {
var a = document.createElement('a');
mimeType = mimeType || 'application/octet-stream';
if (navigator.msSaveBlob) {
navigator.msSaveBlob(new Blob([content], {
type: mimeType
}), fileName);
} else if (URL && 'download' in a) {
a.href = URL.createObjectURL(new Blob([content], {
type: mimeType
}));
a.setAttribute('download', fileName);
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
} else {
location.href = 'data:application/octet-stream,' + encodeURIComponent(content);
}
}
download(csvContent, 'dowload.xls', 'text/xls;encoding:utf-8');
Any help will be greatly appreciated. Thanks.