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); } }
No comments:
Post a Comment