Get a specific cell value in a Google Spreadsheet

2019-08-29 07:29发布

问题:

I am trying to modify a little script to email myself the results of a Google Form. The script is working in its basic form, but I can't seem to be able to retrieve the value from a cell and copy it in the subject field.

Here is what I am trying:

var lastRow = SpreadsheetApp.getActiveSheet().getMaxRows();
var title = SpreadsheetApp.getActiveSheet().getRange(lastRow, 2).getValues();
var subject = "Todo List: " + title; 

The script stops working though, when I do that :) Any idea why? Thanks

回答1:

Never tried this but looking at 'title' you have ...getValues() suggesting a collection of titles which you assign to a single variable what does getValues()[0] give you. Try indexing into that collection maybe..



回答2:

getValues() will return a 2-dimensional Javascript array (so I think getValues()[0][0] should work); but as you are wanting to retrieve a single value from a single cell, you may as well just use getValue().

var title = SpreadsheetApp.getActiveSheet().getRange(lastRow, 2).getValue();