T
T
teodor7teodor72020-05-24 12:27:00
Google Apps Script
teodor7teodor7, 2020-05-24 12:27:00

How to recalculate formulas on demand?

There is a table, a script is written for it. The data changes periodically and is stored in the cache. The cells have various data, using the formula get('id1'), get('id2') ... and so on. There is a request and getting data from the cache. Data may change and must be updated. Is there a way to recalculate the data for example by executing a function??? is it possible to recalculate all the formulas on the sheet that can change their position?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ivanov, 2020-05-24
@oshliaer

No. All formulas participate in the same event loop.
You can only force a complete recalculation of the entire Table by calling SpreadsheetApp.flush(). There will be no sense
in custom formulas . flushSet-operators do not work in these formulas either.
Using CacheService is of little use
5ecf2d47878ae972525511.png
Translated the entire script into a digestible form and made a small example of how such a function works

/**
 * @OnlyCurrentDoc
 */

/**
 *
 * The TESTCACHESERVICE function
 *
 * @param {param} param
 * @return {number}
 * @customfunction
 */
function TESTCACHESERVICE(param) {
  const cache = CacheService.getScriptCache();
  const cached = param === 'break' ? 0 : +cache.get('cached') + 1 || 0;
  cache.put('cached', cached);
  return cached;
}

Example in Spreadsheet https://docs.google.com/spreadsheets/d/11Z1pT2y28B...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question