Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing spreadsheet in Google Script

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;
}
like image 239
user1761850 Avatar asked Oct 20 '12 16:10

user1761850


People also ask

How do you open a sheet in Google App Script?

Click Extensions > Apps Script to open the script editor, then copy the script text from the original spreadsheet and paste it into the script editor of another spreadsheet.

How do I get data from another sheet in Google script?

Use the IMPORTRANGE function In Sheets, open a spreadsheet. In an empty cell, enter =IMPORTRANGE. The URL of the spreadsheet in Sheets. The sheet name (optional) and the range of cells to import.

Can you script Google Sheets?

Google Apps Script lets you do new and cool things with Google Sheets. You can use Apps Script to add custom menus, dialogs, and sidebars to Google Sheets. It also lets you write custom functions for Sheets, as well as integrate Sheets with other Google services like Calendar, Drive, and Gmail.


1 Answers

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();
like image 118
Cătălin George Feștilă Avatar answered Sep 20 '22 16:09

Cătălin George Feștilă