Export google spreadsheet in xlsx format using javascript

It seems that with the new version of the Google spreadsheet, it is no longer possible to download the entire Google spreadsheet using JS. So far I have used this method (which still works great for files that 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 found a new download URL :

https://docs.google.com/spreadsheets/d/_ID_/export?format=xlsx&id=_ID_

But, unfortunately, there is no title Access-Control-Allow-Origin, so the link cannot be accessed using JS. Is there any other way to upload a file?

The Google Drive API displays the export URL:

https://docs.google.com/spreadsheets/export?id=_ID_&exportFormat=xlsx

But also there is no title Access-Control-Allow-Origin.

Is there any other way to download this file using only JS?

+4
source share
1

URL:

https://docs.google.com/spreadsheet/pub?key=XXX&output=xls

, :

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/

-1

Source: https://habr.com/ru/post/1539307/


All Articles