11

I am writing a google script on top of a spreadsheet. I want to deploy it as a web app. It shows some values. Unfortunately, with my current code, google reminds me:

TypeError: Cannot call method "getSheetByName" of null.

I have no idea where the mistake is.

Here's the code

function doGet(e) {
    var app = UiApp.createApplication().setTitle('Details');
    var ss = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
    var dataFromCell = ss.getRange("B4").getValue();

    var mypanel = app.createVerticalPanel();
    var label = app.createLabel(dataFromCell);

    app.add(mypanel);
    app.add(label);

    return app;
}

2 Answers 2

32

In standalone webapps you cannot use getActiveSpreadsheet because no one is using it actively... Use SpreadsheetApp.openById('ID') instead, you can get the ID in the url of your spreadsheet like in this example :

https://docs.google.com/spreadsheet/ccc?key=0AnqSFd3iikE3d-------nZIV0JQQ0c1a3dWX1dQbGc#gid=0

between key= and #, ie 0AnqSFd3iikE3d-------nZIV0JQQ0c1a3dWX1dQbGc

6
3

Not need to use ID , just try this code ( change mygooglelocation with your Spreadsheet name and range of cells. Working very well for me with google maps...

  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('mygooglelocation');
  var ss = SpreadsheetApp.getActive();
  var mylocationInfo   = ss.getRange("A2:B4").getValues();
4
  • 1
    I'm afraid you misunderstood the question... this was about webapps that run independently of the spreadsheet in a doGet/return structure. If you want to prove your point please show a full example. Aug 18, 2013 at 10:58
  • then will be my mistake ... I saw many errors on internet about getRange(...).getValue() and I suppose it's same problem... Aug 18, 2013 at 15:42
  • "Your vote are locked unless your answer is edited..." i try to edit to give back you the vote but I don't let me even I add comment ... Aug 20, 2013 at 0:07
  • 1
    No worries... 7 was a nice number but 6 is not bad after all. :-) Aug 20, 2013 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.