Global variable defined in function appears not defined?

后端 未结 2 983
隐瞒了意图╮
隐瞒了意图╮ 2021-01-26 04:32

I\'m writing a script for Google Spreadsheets, I want to have my headers index available globally throughout the script.

According to the theory, I should be able to def

2条回答
  •  执念已碎
    2021-01-26 05:23

    I've found a solution I believe, but I'm not sure it is the "proper" way to do this.

    I'm simply defining the global variable above in the script:

    headerNameIndex = SpreadsheetApp.getActiveSheet().getDataRange().getValues()[0].indexOf("First-Last")

    Which seems to work.

    I had wrongly assumed it would only work if it was defined in the onOpen() function.

提交回复
热议问题