Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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() {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of calling it oneOffScript, I think it's better to name it specifically about what it actually does.
So it's much easier for user to understand what will happen if they click on it.
Also update the doc.

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);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get one cell instead of the entire row?

const stage = range.getCell(1, stageColumnNumber);
const n = stage.getValue();
if (Number.isFinite(n) && n < 1000) {
stage.setValue(n * 10);
}
}
}

function testAll() {
Condition.testAll();
}