The following code will update a Google sheet:
function doGet(e) { // This function handles GET requests (for simplicity in this example) // Get parameters from the URL var sheetName = e.parameter.sheetName; var row = parseInt(e.parameter.row); var col = parseInt(e.parameter.col); var value = e.parameter.value; // Basic error handling if (!sheetName || isNaN(row) || isNaN(col) || value == = undefined) { return ContentService.createTextOutput("Error: Missing parameters (sheetName, row, col, value)").setMimeType(ContentService.MimeType.TEXT); } try { // Get the spreadsheet and the specific sheet var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheetByName(sheetName); if (!sheet) { return ContentService.createTextOutput("Error: Sheet not found: " + sheetName).setMimeType(ContentService.MimeType.TEXT); } // Update the specified cell (row and column are 1-based) sheet.getRange(row, col).setValue(value); return ContentService.createTextOutput("Cell updated successfully! Sheet: " + sheetName + ", Row: " + row + ", Col: " + col + ", Value: " + value).setMimeType(ContentService.MimeType.TEXT); } catch (error) { return ContentService.createTextOutput("Error: " + error).setMimeType(ContentService.MimeType.TEXT); } }
Never thought updating a Google Sheet could be this simple with just a GET request. Kinda wild that you can pass row, col, and value straight in the URL. Gonna try this out for some quick tracking at work. Also, found some other neat tools like YouTube Vanced that make life easier when tinkering with small scripts.
ReplyDelete