Google apps script Google Sheets脚本getCurrentCell()

Google apps script Google Sheets脚本getCurrentCell(),google-apps-script,Google Apps Script,我是谷歌脚本新手,需要帮助找到以下代码的解决方案: var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); // Returns the current highlighted cell in the one of the active ranges. var currentCell = sheet.getCurrentCell(); 当我保存它时,它不允许我运行脚本。我缺少什么吗?用这个- function

我是谷歌脚本新手,需要帮助找到以下代码的解决方案:

var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

// Returns the current highlighted cell in the one of the active ranges.

var currentCell = sheet.getCurrentCell();
当我保存它时,它不允许我运行脚本。我缺少什么吗?

用这个-

function getCurrentCellValue() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var currentCell = sheet.getCurrentCell();
  // do what you need to do
}

要执行代码,它必须包含在函数中。所有非封闭代码仅作为实例执行的一部分执行,即当执行函数时。回顾一下谢谢,你会为代码推荐什么类型的函数?@manuelordaz把它包装成一个函数{/*你的代码*/}谢谢。对于下面的一个,我会遵循相同的概念吗?私有子工作表\u SelectionChangeByVal目标为Range RangeA1.Value=ActiveCell.Address End Sub恐怕我不知道您编写的语言。