Google docs script set cell value

I want to set the text or number in google spreadsheet from a script, I know how to do it in MS Excel, but I don’t know how to do it in Google Spreadsheet.

I want to set Hello or the number 9 to cell F2.
I found this code so far

SpreadsheetApp.getActiveRange().setValue('hello'); 

but this does not indicate which cell

+58
google-spreadsheet google-apps-script
Jul 04 '12 at 19:05
source share
4 answers

The following code does what is required

 function doTest() { SpreadsheetApp.getActiveSheet().getRange('F2').setValue('Hello'); } 
+101
Jul 04 '12 at 19:27
source share

Use the setValue Range method to set the value of a specific cell

 function storeValue() { var ss = SpreadsheetApp.getActiveSpreadsheet(); // ss is now the spreadsheet the script is associated with var sheet = ss.getSheets()[0]; // sheets are counted starting from 0 // sheet is the first worksheet in the spreadsheet var cell = sheet.getRange("B2"); cell.setValue(100); } 

You can also select a cell using row and column numbers.

 var cell = sheet.getRange(2, 3) // here cell is C2 

It is also possible to immediately set the value of several cells

 var values = [ [ "2.000", "1,000,000", "$2.99" ] ]; var range = sheet.getRange("B2:D2"); range.setValues(values); 
+16
Mar 12 '16 at 23:35
source share

The setting value in the cell in the spreadsheet to which the script is attached

 SpreadsheetApp.getActiveSpreadsheet().getSheetByName(SHEET_NAME).getRange(RANGE).setValue(VALUE); 

The value of the setting in the cell in the sheet that is currently open and to which the script is attached

 SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(RANGE).setValue(VALUE); 

The value of the parameter in the cell in any spreadsheet that the script is not connected to (name of the target sheet name)

 SpreadsheetApp.openById(SHEET_ID).getSheetByName(SHEET_NAME).getRange(RANGE).setValue(VALUE); 

The value of the parameter in the cell in any spreadsheet to which the script is NOT connected (the position of the destination location is known)

 SpreadsheetApp.openById(SHEET_ID).getSheets()[POSITION].getRange(RANGE).setValue(VALUE); 

These are constants, you must define them yourself

 SHEET_ID SHEET_NAME POSITION VALUE RANGE 

By a script attached to a sheet, I mean that the script is in the script editor of this sheet. Not attached means that it is not in the script editor of this sheet. It can be anywhere else.

0
Dec 20 '17 at 8:06
source share

I have a sheet with two columns. Date and help.

The sheet is filled with the date and with the number of those who help.

I would like the Assist column to automatically insert 0 if the date entered is specified, and only if there is no number in the Assist column.

I have the following script so far and it is starting onOpen.

 `function storeValue() { var ss = SpreadsheetApp.getActiveSpreadsheet(); // ss is now the spreadsheet the script is associated with var sheet = ss.getSheets()[0]; // sheets are counted starting from 0 // sheet is the first worksheet in the spreadsheet var cell = sheet.getRange("J3:J"); cell.setValue(0); }` 
-one
May 10 '17 at 18:48
source share



All Articles