Last active
December 22, 2015 11:09
-
-
Save draffensperger/6463857 to your computer and use it in GitHub Desktop.
Google Apps Script, number of people scheduled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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