TypeError: Cannot call method “getActiveSheet” of

2019-08-20 08:52发布

问题:

TypeError: Cannot call method "getActiveSheet" of null

SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange("D2").setValue(99)

Please look into the screenshot All i want to set the value into the sheet with given range.

Code.gs

sheat01

Here is the code

function myF() {
var app = SpreadsheetApp;
var g_as = app.getActiveSpreadsheet();
var as = g_as.getActiveSheet();
as.getRange("D2").setValue(99);

}

回答1:

I did this and it works. The Logger comes back with the word Range. I had no expectation that it would come back with anything.

function myF()
{
   SpreadsheetApp.getActive().getActiveSheet().getRange('D2').setValue(99);
}

It changes O19 to 99 every time.

Whenever I start getting weird stuff going on I shut down the browser and come back up and that generally does the trick.