Where can we find non-documented attributes of Google Objects

时间秒杀一切 提交于 2019-12-24 10:21:04

问题


I know that auto-completion sometimes helps you find unreferenced methods of Google objects such as for the Sheets API v4 but how can I find the attributes.

example with spreadsheets:

function onEdit(e)
{
  Logger.log(e.range.columnStart)
  //returns the start column of the range I've edited
  Logger.log(SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getDataRange().columnStart)
  //Weird result, even if my sheet is populated with values it returns 'undefined'
}

In this example you see the attribute columnStartbut I can't find it in documentation however a lot of people seems to use it.

Another point that can be out of subject but interesting, both e.range and getDataRange returns a Range object but one seems to have a populated columnStartattribute when the other don't.


回答1:


  • You want to retrieve the object of e.range from onEdit(e).

If my understanding is correct, how about this answer? Unfortunately, the detail properties cannot seen at the document of Event Objects. So, for example, it confirms each properties from the event object using JSON.stringify().

Sample script:

function onEdit(e) {
  Logger.log(JSON.stringify(e)) // or console.log(JSON.stringify(e))
}

Result:

{
  "authMode": {},
  "range": {
    "columnStart": 1,
    "rowStart": 1,
    "rowEnd": 1,
    "columnEnd": 1
  },
  "source": {},
  "user": {
    "nickname": "### name ###",
    "email": "### email ###"
  },
  "value": "sample"
}

Note:

  • If Logger.log(JSON.stringify(e.range)) is run, {"columnStart":1,"rowStart":1,"rowEnd":1,"columnEnd":1} is retrieved. In this case, "A1" is edited.

Reference:

  • Event Objects


来源:https://stackoverflow.com/questions/52248268/where-can-we-find-non-documented-attributes-of-google-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!