Vineeth Varma
Vineeth Varma

Reputation: 609

How to Set value in Google Spreadsheet using google-script?

Help me to code a google script to set a value into particular cell of google spreadsheet!

 function ...
 {     
    var email_address = ....
 }
 ....
 ....
 var values = copyDoc.getSheetValues(1, 1, 33, 7);
 Logger.log('values:');
 Logger.log(values);
 Logger.log('values logged');

Now after this I wanna set a value into my spreadsheet! How can I do that? I tried the following code, but dint work.

 for(var i=1;i<34;i++)
 {
   for(var j=1;j<8;j++)
   {
     if (values[i][j]=="varEmail")
     {
       values[i][j]=email_address;
     }
   }
 }

I have alloted 'varEmail' as cell value in my spreadsheet for row 10 and column A,B,c (like big horizontal cell). Now I wanna replace it with value in variable email_address. Please tell me how can I do it?

Upvotes: 1

Views: 13187

Answers (1)

Serge insas
Serge insas

Reputation: 46794

In your example values is an array containing data starting at row 1 col 1, so just write it back in place like below :

SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(1,1,values.length,values[0].length).setValues(values);

You might want to get the sheet differently depending on your use case, using getSheetByName or getSheets()[sheet index] but that will be your choice

Upvotes: 1

Related Questions