【问题标题】:Cell reference in Google Sheets ScriptGoogle 表格脚本中的单元格引用
【发布时间】:2021-10-20 01:13:16
【问题描述】:

根据我的问题,您会知道我是 Google 表格脚本的新手。 我正在创建一个宏以在特定列中的特定字符串下方插入一个单元格。例如,我需要在值为“Red”的单元格下方插入一个单元格。如果“红色”在 A5 中,那么我需要单元格 A6,而 A6 将在宏中多次使用。任何答案表示赞赏!

一切顺利!

【问题讨论】:

  • 如何获得A6?非常感谢!

标签: google-apps-script


【解决方案1】:
function findRed() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName('Sheet1');
  let f = sh.createTextFinder('Red').findAll();
  let fA = f.map(r => { return {row: r.getRow(),col: r.getColumn()}} );
  Logger.log(JSON.stringify(fA));
}

Execution log
11:12:41 AM Notice  Execution started
11:12:41 AM Info    [{"row":1,"col":1},{"row":4,"col":2},{"row":6,"col":4},{"row":8,"col":6},{"row":10,"col":8}]
11:12:42 AM Notice  Execution completed
Col1 Col2 Col3 Col5 Col5 Col6 Col7 Col8
Red
Red
Red
Red
Red

【讨论】:

  • 嗨,库珀,感谢您的快速回复!一切顺利!肖恩
  • 你好,如果只找到A1,那么我需要写A2,或者有时我可能需要写A2:G2,如何在脚本中写?我很感激!
  • @AccountingAutomation 最好在新帖子中提出后续问题。
  • 您可以看到我的代码为找到的每个项目返回行和列,如果 row,col = 1,1 那么它下面的将始终位于 row +1 列,或者您可以使用 sheet .getRange(row,col).offset(1,0);并且有用于扩展范围的带有更多参数的偏移命令。你会在 Class Range 中找到它们。
  • 嗨库珀,我很感激!祝你有美好的一天!肖恩
猜你喜欢
  • 1970-01-01
  • 2017-01-20
  • 1970-01-01
  • 2021-10-22
  • 1970-01-01
  • 1970-01-01
  • 2012-06-01
  • 2023-01-17
  • 1970-01-01
相关资源
最近更新 更多