问题
I have a custom function that uses fetch to save some information to a spreadsheet. The problem is, it's meant to be used many times on the spreadsheet, fetching from various pages. As the amount of uses increases, needlessly re-fetching information every time the spreadsheet opens will become more and more of a problem.
Is there any way to avoid this default behavior? I still want it to recalculate every time the cell is edited, even if the parameters are exactly the same. Is there perhaps a way to tell if it's a manual edit vs. automatic recalculation, or simply disable the behavior entirely?
回答1:
Is there perhaps a way to tell if it's a manual edit vs. automatic recalculation, or simply disable the behavior entirely?
No and no.
One of possible workarounds is to have a "switch" in some cell of the spreadsheet: say, if cell A1 has "Update" then custom functions recalculate normally; otherwise they do nothing. That cell (A1) can have data validation with dropdown, for easy switching between states. The custom functions would be modifying to include the following:
function customFunction(...) {
var currentStatus = SpreadsheetApp.getActiveSheet().getRange("A1").getValue();
if (currentStatus != "Update") {
return;
}
// the rest of function
来源:https://stackoverflow.com/questions/46186526/stop-a-custom-function-from-recalculating-every-time-the-spreadsheet-is-open