Skip to content

Commit

Permalink
Add basic google app script to check a spreadsheet's validity
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall committed Jul 22, 2024
1 parent e5a580c commit 9b1cc2c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions scripts/code.gs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Lehigh Preserve')
.addItem('Check My Work', 'sendSheetData')
.addToUi();
}

function sendSheetData() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var data = sheet.getDataRange().getValues();

var payload = JSON.stringify(data);

var url = 'https://preserve.lehigh.edu/workbench/check';

var options = {
'method': 'POST',
'contentType': 'application/json',
'payload': payload
};

var response = UrlFetchApp.fetch(url, options);
var result = JSON.parse(response.getContentText());

displayErrors(result);
}

function displayErrors(errors) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

for (var cell in errors) {
var error = errors[cell];
sheet.getRange(cell).setBackground('red').setNote(error);
}

SpreadsheetApp.getUi().alert('Errors highlighted in the sheet.');
}

0 comments on commit 9b1cc2c

Please sign in to comment.