It seems that with new version of Google spreadsheet it is no longer possible to download entire Google Spreadsheet using JS. So far I have been using this method (which still works fine for files which were created earlier):
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://docs.google.com/feeds/download/spreadsheets/Export?key=' + id + '&exportFormat=xlsx');
xhr.responseType = 'arraybuffer';
xhr.setRequestHeader('Authorization', 'Bearer ' + gapi.auth.getToken().access_token);
xhr.onload = function() {
...
};
xhr.send();
I have found the new download url:
https://docs.google.com/spreadsheets/d/_ID_/export?format=xlsx&id=_ID_
But unfortunately there is no Access-Control-Allow-Origin
header so the link cannot be accessed using JS. Is there any other possibility I can download the file?
Google Drive API displays export url as:
https://docs.google.com/spreadsheets/export?id=_ID_&exportFormat=xlsx
But there is also no Access-Control-Allow-Origin
header.
Is there any other possibility to download this file using only JS?
You should be able to download it using this url:
https://docs.google.com/spreadsheet/pub?key=XXX&output=xls
I've created an example that works here:
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (this.readyState === 4 && this.status === 200) {
console.log('success', this.responseText.length);
}
};
xhr.open('GET', 'https://docs.google.com/spreadsheet/pub?key=0AsnymCBa0S5PdEtZdnEzcjlTenBIcldRNFMtSUdNUkE&output=xls', true);
xhr.send(null);
http://jsfiddle.net/kmturley/b47wno47/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With