-2

I am trying to write to a spreadsheet using the API, and after reading the documentation, I saw that I needed use spreadsheets.values.update. However, the arguments to it are spreadsheet ID, range, and ValueRange. I know how to format the first two, but I do not know about Value Ranges and cannot find anything about them.
Does anybody know how to format Value Ranges, or know how to write to a Google spreadsheet?

BestCharlemagne
  • 91
  • 2
  • 10
  • [ValueRange](https://developers.google.com/sheets/reference/rest/v4/spreadsheets.values#ValueRange) – gonzo Aug 09 '16 at 17:10

1 Answers1

-1
// Can also get a sheet by name, URL, and ID I believe, you will have to check the docs
var sheet = SpreadsheetApp.getActive();    // get the sheet you are editing the script for
var range = sheet.getDataRange();

var cell = range.getCell(row_number, column_number); 
cell.setValue(some_value);

This works for me in the scripts I have running on some of my spreadsheets. You can do some clever finagling to get the rows and columns for the cells you need, but this will set the value in the selected cell to whatever some_value is.

I think their are other ways I've done this in other sheets but this one seems to work best general purpose as far as I know.

getDataRange() docs

getCell(row, column) docs

TheRealKernel
  • 351
  • 3
  • 11