![](/img/trans.png)
[英]Exception: Service Spreadsheets failed while accessing document with id google sheet
[英]Error Exception: Service Spreadsheet failed while accessing document with id
我在以前的答案中找不到此错误的解决方案。 我正在使用 Google 表格在 Google Apps 脚本下运行此脚本。 因此,我希望您查看我的简单代码行,看看是否有我忽略的内容:
var firstCSV = SpreadsheetApp.openByUrl("https://drive.google.com/file/d/14EA51XsRpohpFVCwpO3sZwf_H3o6Dp_o/edit#gid=0");
此行有错误 -
Exception: Service Spreadsheets failed while accessing document with id 14EA51XsRpohpFVCwpO3sZwf_H3o6Dp_o. GregReport @ Receipts Calculator.gs:37
我首先尝试仅使用 ID 号使用“openById”并得到相同的错误消息。
接下来,我尝试使用文档的 URL 使用“openByUrl”并得到
相同的错误信息。
我检查了谷歌驱动器上的文件,它在那里,我可以打开它。
我自己在脚本中运行了这行代码并得到了同样的错误。
我将代码中的 URL 更改为表格文档 URL 我得到了
同样的错误。
原始文件的扩展名为.csv 但我的理解是这样的
在表格中应该可以正常工作。
通过文档格式和不同的方法,我得到了这个
同样的错误。
任何我不知道的建议或代码更新将不胜感激。 我要做的就是打开一个电子表格并使用表格中内置的脚本从中提取一些数据。
不幸的是,无论是使用文件 ID 还是驱动器 url,都无法在 Apps 脚本中将 CSV 文件作为电子表格直接调用。
您需要做的是解析 CSV 并获取它的内容并将其粘贴到 Apps Script 中的电子表格中。 请看下面的示例代码:
function myFunction() {
var file = DriveApp.getFilesByName(your-filename-here).next();
var csvData = Utilities.parseCsv(file.getBlob().getDataAsString());
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(1,1,csvData.length, csvData[0].length).setValues(csvData)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.