【发布时间】:2014-05-05 16:01:59
【问题描述】:
似乎使用新版本的 Google 电子表格不再能够使用 JS 下载整个 Google 电子表格。到目前为止,我一直在使用这种方法(对于之前创建的文件仍然可以正常工作):
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_
但遗憾的是没有Access-Control-Allow-Origin 标头,因此无法使用JS 访问链接。我还有其他可能下载文件吗?
Google Drive API 将导出网址显示为:
https://docs.google.com/spreadsheets/export?id=_ID_&exportFormat=xlsx
但也没有Access-Control-Allow-Origin 标头。
有没有其他方法可以只用 JS 下载这个文件?
【问题讨论】:
标签: javascript google-drive-api google-spreadsheet-api