Last active
November 3, 2017 22:34
-
-
Save leachdaniel/1e94865bf90f5005064c4061b1fa9f64 to your computer and use it in GitHub Desktop.
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
var DocumentAppUtility = (function (dau, da) { | |
dau.Tables = (function(dautables, da) { | |
function findTableByHeaders(tables, headersMatch) { | |
for (var i=0; i<tables.length; i++) { | |
var table = tables[i], | |
headerRow = table.getRow(0), | |
numCells = headerRow.getNumCells(), | |
columnLookup = {}, | |
headerNames = []; | |
if (numCells < headersMatch.length) { | |
continue; | |
} | |
for (var j=0; j<numCells; j++) { | |
var cellText = headerRow.getCell(j).getText(); | |
headerNames.push(cellText); | |
for (var k=0; k<headersMatch.length; k++) { | |
var h = headersMatch[k]; | |
if (cellText.match(h)) { | |
columnLookup[h] = j; | |
} | |
} | |
} | |
if (Object.keys(columnLookup).length === headersMatch.length) { | |
return { | |
columnLookup: columnLookup, | |
headerNames: headerNames, | |
table: table, | |
tableIndex: i | |
}; | |
} | |
} | |
} | |
dautables.findByHeaders = findTableByHeaders; | |
return dautables; | |
} (dau.Tables || {}, da)); | |
return dau; | |
}(DocumentAppUtility || {}, DocumentApp)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment