简体   繁体   English

错误异常:访问具有 ID 的文档时服务电子表格失败

[英]Error Exception: Service Spreadsheet failed while accessing document with id

I could not find the solution to this error in the previous answers.我在以前的答案中找不到此错误的解决方案。 I'm running this script under Google Apps Scripts with Google Sheets.我正在使用 Google 表格在 Google Apps 脚本下运行此脚本。 So I would like you to review my simple line of code to see if there is something I overlooked:因此,我希望您查看我的简单代码行,看看是否有我忽略的内容:

var firstCSV = SpreadsheetApp.openByUrl("https://drive.google.com/file/d/14EA51XsRpohpFVCwpO3sZwf_H3o6Dp_o/edit#gid=0");

Error on this line -此行有错误 -

Exception: Service Spreadsheets failed while accessing document with id 14EA51XsRpohpFVCwpO3sZwf_H3o6Dp_o. GregReport @ Receipts Calculator.gs:37

  • I first tried using "openById" using just the ID number and got the same error message.我首先尝试仅使用 ID 号使用“openById”并得到相同的错误消息。

  • Next I tried using the "openByUrl" using the document's URL and got接下来,我尝试使用文档的 URL 使用“openByUrl”并得到
    the same error message.相同的错误信息。

  • I checked the file on Google drive and it's there and I can open it.我检查了谷歌驱动器上的文件,它在那里,我可以打开它。

  • I ran this line of code in a script by itself and got the same error.我自己在脚本中运行了这行代码并得到了同样的错误。

  • I changed the URL in the code to a Sheets document URL an I got the我将代码中的 URL 更改为表格文档 URL 我得到了
    same error.同样的错误。

  • The original file has a.csv extension but my understanding is this原始文件的扩展名为.csv 但我的理解是这样的
    should work just fine in Sheets.在表格中应该可以正常工作。

  • With both document formats and different methods I'm getting this通过文档格式和不同的方法,我得到了这个
    same error.同样的错误。

  • Any suggestions, or code updates I'm not aware would be appreciated.任何我不知道的建议或代码更新将不胜感激。 All I'm trying to do is open a spreadsheet and extract some data from it using a script built in Sheets.我要做的就是打开一个电子表格并使用表格中内置的脚本从中提取一些数据。

Unfortunately, it is not possible to directly call a CSV file as a spreadsheet in Apps Script whether by using the file ID or the drive url.不幸的是,无论是使用文件 ID 还是驱动器 url,都无法在 Apps 脚本中将 CSV 文件作为电子表格直接调用。

What you need to do is to parse the CSV and get the content of it and paste it into a spreadsheet in Apps Script.您需要做的是解析 CSV 并获取它的内容并将其粘贴到 Apps Script 中的电子表格中。 Please see sample code below:请看下面的示例代码:

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.

相关问题 例外:访问带有 id google sheet 的文档时服务电子表格失败 - Exception: Service Spreadsheets failed while accessing document with id google sheet 异常:服务电子表格在访问具有 id 的文档时失败 - Exception: Service Spreadsheets failed while accessing document with id 例外:我认为访问带有 id *** / getsheetname() 错误的文档时服务电子表格失败 - Exception: Service Spreadsheets failed while accessing document with id *** / getsheetname()error I think DocumentApp 服务抛出“服务文档在访问带有 id 的文档时失败”错误 - DocumentApp service throws a “Service Documents failed while accessing document with id” error 服务电子表格在访问 ID 为 xxx 的文档时失败 - Service Spreadsheets failed while accessing document with ID xxx 异常:服务电子表格在访问 ID 为 XXX 的文档时超时 - Exception: Service Spreadsheets timed out while accessing document with id XXX 错误消息:访问 ID 为 1HjEecpeXGdR3iF_0W6CdLIm-hE-W9tbuxmvtKlte1OY 的文档时服务电子表格失败 - Error Msg: Service Spreadsheets failed while accessing document with id 1HjEecpeXGdR3iF_0W6CdLIm-hE-W9tbuxmvtKlte1OY 电子邮件中的地理图表 | 访问具有 ID 的文档时服务电子表格失败 | 谷歌表格 - Geo Charts in Emails | Service Spreadsheets failed while accessing document with id | Google Sheets Google Sheet 错误:访问带有 id 的文档时服务电子表格超时 - Google Sheet Error: Service Spreadsheets timed out while accessing document with id 插入大量数据时如何修复“访问文档时服务文档失败”? - How to fix "Service Documents failed while accessing document" while inserting a lot of data?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM