Skip to content

Instantly share code, notes, and snippets.

@draffensperger
Last active December 22, 2015 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save draffensperger/6463857 to your computer and use it in GitHub Desktop.
Save draffensperger/6463857 to your computer and use it in GitHub Desktop.
Google Apps Script, number of people scheduled
function peopleBusy(people, startRow, startCol, endRow, endCol) {
startRow = startRow || 2;
startCol = startCol || 2;
endRow = endRow || 40;
endCol = endCol || 9;
people = people.split(",");
var ss = SpreadsheetApp.getActiveSpreadsheet();
var n, i, j;
var sheet, range;
numRows = endRow - startRow + 1;
numCols = endCol - startCol + 1;
var busy = new Array(numRows);
for (i = 0; i < numRows; i++) {
busy[i] = new Array(numCols);
for (j = 0; j < numCols; j++) {
busy[i][j] = "";
}
}
var lock = LockService.getPublicLock();
lock.waitLock(180000);
for (n = 0; n < people.length; n++) {
person = people[n].trim();
sheet = ss.getSheetByName(person);
vals = sheet.getRange(startRow, startCol, numRows, numCols).getValues();
for (i = 0; i < numRows; i++) {
for (j = 0; j < numCols; j++) {
if (vals[i][j] != "") {
busy[i][j] += person.substring(0,1);
}
}
}
}
lock.releaseLock();
for (i = 0; i < numRows; i++) {
for (j = 0; j < numCols; j++) {
if (busy[i][j] != "") {
busy[i][j] = "x" + busy[i][j];
}
}
}
return busy;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment