Naz*_*zin 5 javascript google-spreadsheet-api google-drive-api
似乎使用新版本的谷歌电子表格不再可能使用 JS 下载整个谷歌电子表格。到目前为止,我一直在使用这种方法(对于之前创建的文件仍然可以正常工作):
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();
Run Code Online (Sandbox Code Playgroud)
https://docs.google.com/spreadsheets/d/_ID_/export?format=xlsx&id=_ID_
Run Code Online (Sandbox Code Playgroud)
但不幸的是,没有Access-Control-Allow-Origin标题,因此无法使用 JS 访问该链接。我还有其他可能下载文件吗?
Google Drive API 将导出 url 显示为:
https://docs.google.com/spreadsheets/export?id=_ID_&exportFormat=xlsx
Run Code Online (Sandbox Code Playgroud)
但也没有Access-Control-Allow-Origin标题。
是否有其他可能仅使用 JS 下载此文件?
您应该能够使用以下网址下载它:
https://docs.google.com/spreadsheet/pub?key=XXX&output=xls
Run Code Online (Sandbox Code Playgroud)
我创建了一个可以在这里使用的示例:
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);
Run Code Online (Sandbox Code Playgroud)
http://jsfiddle.net/kmturley/b47wno47/
| 归档时间: |
|
| 查看次数: |
2557 次 |
| 最近记录: |