如何在 Google Apps 脚本中解析 Range 对象

How to parse the Range object in Google Apps Script

我需要在 Google Apps 脚本中解析和编辑 Range 对象(SpreadsheetApp.getActiveRange() 的结果)。

目标:在Google 表格中:用户单击一个项目(在A 列中)并按下工具栏中的“创建二维码”按钮。这会将相应的 QR 码放在行的后面(C 列)。

我期待类似 (伪代码):

var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var cell = SpreadsheetApp.getActiveRange()
//Logger.log(cell) --> "A2"
cell = cell.split("");
cell[0] = "B";
cell = cell.join("")
//Logger.log(cell) --> "B2"
ss.getRange(cell).setFormula('=image("https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl="' + cell'));

不建议解析范围对象。使用 range.offset 代替:

SpreadsheetApp
    .getActiveRange()
    .offset(0,1)
    .setFormula('=1+0')