I did find a couple other spots on this, but no answers (or old answers where hopefully things have changed).
I simply want to put a formula in a Google Sheet cell (via a script) and have it fully refresh/recalc. The problem is, the formula returns an array of values, as in:
SORT(TRANSPOSE(QUERY(A2:B299,"Select count(A) pivot(B)")),2,FALSE)
I can make everything work up to the point of placing the formula in the cell I want and selecting that cell. But I still need to manually press CTRL+E to make the array fill in (it is a summary of how many bottles in my beer collection belong to each brewer).
I have tried all the "flush" and re-calc commands I have been able to find via research, and nothing makes the formula "take". Alternately, I looked for a brute force solution -- send a CTRL+E to the cell as if I had pressed the keys myself -- but was unable to find anything that can do something like a Visual Basic "SendKeys" or a Visual Foxpro "KEYBOARD" command.
Here is the Google Script code behind a button that calls "refreshBrewerTable()":
function refreshBrewerTable() {
return refreshQuery(9, 13, "B", 2, "FALSE");
}
function refreshQuery(rootrow, rootcol, pivotColumn, sortColumn, sortAsc) {
var range = sheet.getRange(rootrow, rootcol, sheet.getLastRow(), rootcol + 1)
range.clearContent();
range = sheet.getRange(rootrow, rootcol);
range.setFormula('=SORT(TRANSPOSE(QUERY(A2:' + pivotColumn + sheet.getLastRow().toString() + ',"Select count(A) pivot(' + pivotColumn + ')")),' + sortColumn.toString() + ',' + sortAsc + ')');
sheet.setActiveSelection(range.getCell(1, 1).getA1Notation());
return true;
}
Any ideas? I basically want to have a button that will refresh this pivoted summary data as I add new beer bottles to my walls.