tbeseda
6/27/2013 - 8:30 PM

The utility I use to insert data into a Google Spreadsheet with Google Apps Script

The utility I use to insert data into a Google Spreadsheet with Google Apps Script

SheetLogger = function() {}

SheetLogger.prototype = {
  set_cell: function(sheet_name, range, value) {
    var sheet = SpreadsheetApp.getActive().getSheetByName(sheet_name);
    sheet.getRange(range).setValue(value);
  },
  
  append_row_to_sheet: function(sheet_name, value) {
    var sheet = SpreadsheetApp.getActive().getSheetByName(sheet_name);
    sheet.appendRow(value);
  }
}

Usage

var logger = new SheetLogger();
logger.set_cell('Sheet 1', 'A1', 'foobar');
logger.append_row_to_sheet('Running Log', ['foo', 'bar', 'baz']);