How to call a Google Sheet formula from within a custom function?

▼魔方 西西 提交于 2020-07-10 03:18:55

问题


Is it possible to call any of the Google Sheets formulas from within your own Google Apps script custom function? If so, how?

It obviously doesn't work to merely use the formula name like you would inside the sheet. Like this, which is what I was hoping would work:

function myCustomFunction() {
  return TDIST(1,30,1); // calling =myCustomFunction() does not work due to TDIST giving a ReferenceError, even though =TDIST(1,30,1) works inside the spreadsheet
}

But since Google's built-in formulas probably rely on some JS implemented functions, it would be strange if there wasn't an API so that we could reuse those functions easily. I've looked at the Google Sheets API reference, but it seems made for calling your custom functions from external services. It seems you may call Google's own formulas through such a POST request. But that seems terribly cumbersome, when you ought to be able to refer to them directly from within your custom script which is tied to the specific Google Sheet environment anyway. If not, then what is the least roundabout way of using those inbuilt formula functions from within a custom function?


回答1:


This has been a feature request since 2011 and has been declined by Google citing inter team issues.

Status: Won't Fix (Infeasible) by ev....@google.com

We have requested this of the Spreadsheet team, and are marking as "Won't Fix" for now.

Apparently, The spreadsheet team hasn't responded yet. A related product forum post states that Google has no intention of integrating spreadsheet functions with scripts.



来源:https://stackoverflow.com/questions/61390574/how-to-call-a-google-sheet-formula-from-within-a-custom-function

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