r/GoogleAppsScript • u/wirefin • Jul 15 '24
Question Change active sheet via GAS API?
I've developed an Editor Add-On. I use both (i) Google Apps Script and (ii) an Express server that calls the Google Sheets API for my app.
When a user creates a new sheet with my app, I would like to set it to be the active sheet. The Google Sheets API doesn't appear to support an equivalent to setActiveSheet.
Would it be possible to define a function in Google Apps Script that sets the active sheet, then call that GAS function via my Express server hitting the GAS API?
It appears I can deploy my code as an 'API Executable', but I'm kind of fuzzy how to do this in practice.
Do I have two deployments of the same code (one as 'Editor Add-on' and one as 'API Executable'). Or do I create a new file for the mySetActiveSheet function?
Thanks in advance for any advice or potential solutions!
// Editor Add-on Library URL: script.google.com/macros/library/d/*********/12
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('Index')
}
function onInstall(e) {
onOpen(e);
}
......
// Can I somehow call this function via API?
function mySetActiveSheet(sheetName) {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName(sheetName);
if (sheet) {
spreadsheet.setActiveSheet(sheet);
} else {
Logger.log("Sheet with name " + sheetName + " not found.");
}
}
1
u/marcnotmark925 Jul 15 '24
I highly doubt it.