0
votes

I'm trying to write a Google Apps script that involves getting the text from a table cell inside a Google Spreadsheet. To illustrate the situation, let's say the word "hello" is in the cell B4, and my function is supposed to get that string from that cell. How would I go about this? I've tried the following but that hasn't worked for me.

 function getText() {
     var body = DocumentApp.getActiveDocument().getBody(); 
     var text = body.getText();
 }

I get this error whenever I try to use the function.

Error: You do not have permission to call getActiveDocument

Even after getting authorization for the script, I still get the same error. Any ideas on how to solve this?

1

1 Answers

0
votes

You say you're trying to retrieve a Spreadsheet information but uses the Document class, they're not interchangeable like that, you'll have to use Spreadsheet class.

Eg.

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