简体   繁体   中英

Can't alter cells outside of the first column of a Google Sheet using getRange and setValue

I just want to change a cell in E5 but I can only seem to edit the first column.

var cell = sheet.getRange(2,5)
    cell.setValue("TEXT");

All this does is put "TEXT" into cell E2 .

EDIT: Below is the entire code.

var sheet = SpreadsheetApp.openById("SheetID").getSheetByName('Sheet1');

function doGet(e) {
  
  var amount = JSON.parse(e.parameter.amount)

  var student = JSON.parse(e.parameter.student)

var cell = sheet.getRange(student,2)

cell.setValue(amount);
}

SAMPLE URL https://script.google.com/macros/s/mygooglesheetID/exec?amount=6&student=6

The code in the question should is adding TEXT to E2 but you want to be added to E5 .

The first parameter is the row, the second is the column, so in order to get E5

instead of

var cell = sheet.getRange(2,5) 

use

var cell = sheet.getRange(5,5);

Regarding the full code

instead of

var cell = sheet.getRange(student,2)

use

var cell = sheet.getRange(student,5)

Reference

NOTE: As a good practice, include a semicolon ( ; ) at the end of the JavaScript statements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM