From 9c0ac107a1d04412c59e0c01a839bb002b487ffc Mon Sep 17 00:00:00 2001 From: Aaron Stacy Date: Fri, 30 Oct 2020 10:20:32 -0500 Subject: [PATCH] Add one-off script menu option This was a useful little quick hack that seems like it'd be good to keep around. Even though I probably won't need the code again for this specific task, it seems like a good little recipe for iterating through rows. --- index.ts | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index f4a8f19..6b52140 100644 --- a/index.ts +++ b/index.ts @@ -68,7 +68,8 @@ function onOpen(e: { authMode: GoogleAppsScript.Script.AuthMode }) { .addSeparator() .addSubMenu( ui.createMenu('DEBUG') - .addItem('Run tests', 'testAll')); + .addItem('Run tests', 'testAll') + .addItem('Run one-off script', 'oneOffScript')); } menu.addToUi(); } @@ -118,6 +119,34 @@ function cancelTriggers() { }); } +/** + * Runs a one-off script on the sheet. + * + * This may be helpful for a quick hack to make a change on a big sheet, and it + * can be run either from the DEBUG menu in the sheet itself or the + * script.google.com editor. + */ +function oneOffScript() { + const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('rules'); + const numRows = sheet.getLastRow(); + const numColumns = sheet.getLastColumn(); + let stageColumnNumber = -1; + for (let column = 1; column <= numColumns; column++) { + const r = sheet.getRange(1, column); + if (r.getValue() === 'stage') { + stageColumnNumber = column; + } + } + for (let row = 1; row <= numRows; row++) { + const range = sheet.getRange(row, 1, row, numColumns); + const stage = range.getCell(1, stageColumnNumber); + const n = stage.getValue(); + if (Number.isFinite(n) && n < 1000) { + stage.setValue(n * 10); + } + } +} + function testAll() { Condition.testAll(); }