Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 如何从谷歌电子表格单元格中获取文本?_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script 如何从谷歌电子表格单元格中获取文本?

Google apps script 如何从谷歌电子表格单元格中获取文本?,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我正在尝试编写一个谷歌应用程序脚本,其中包括从谷歌电子表格中的表格单元格中获取文本。为了说明这种情况,假设单词“hello”在单元格B4中,我的函数应该从该单元格中获取该字符串。我该怎么办?我试过以下方法,但都不管用 function getText() { var body = DocumentApp.getActiveDocument().getBody(); var text = body.getText(); } 每当我尝试使用该函数时,都会出现此错误 错误:

我正在尝试编写一个谷歌应用程序脚本,其中包括从谷歌电子表格中的表格单元格中获取文本。为了说明这种情况,假设单词“hello”在单元格B4中,我的函数应该从该单元格中获取该字符串。我该怎么办?我试过以下方法,但都不管用

 function getText() {
     var body = DocumentApp.getActiveDocument().getBody(); 
     var text = body.getText();
 }
每当我尝试使用该函数时,都会出现此错误

错误:您没有调用getActiveDocument的权限


即使在获得脚本授权后,我仍然会收到相同的错误。关于如何解决这个问题有什么想法吗?

如果您说您试图检索电子表格信息,但使用Document类,它们不能像那样互换,您必须使用电子表格类

例如

var allVals = SpreadsheetApp.getActiveSheet().getDataRange().getValues();
Logger.log(allVals);