-
Notifications
You must be signed in to change notification settings - Fork 0
/
GSheetTo2DArray.js
27 lines (23 loc) · 948 Bytes
/
GSheetTo2DArray.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// GSheet area to 2-dimensional array
function GSheetTo2DArray(json, rowMin, rowMax, colMin, colMax) {
var rowBounds = [rowMin, rowMax];
var colBounds = [colMin, colMax];
// Calculate data area height and width
var height = rowBounds[1]-rowBounds[0]+1;
var width = colBounds[1]-colBounds[0]+1;
// Filter only desired data area
allData = json.feed.entry;
filteredData = [];
allData.forEach(elem => {
var row = parseInt(elem.gs$cell.row);
var col = parseInt(elem.gs$cell.col);
if(row >= rowBounds[0] && row <= rowBounds[1] && col >= colBounds[0] && col <= colBounds[1]) {
// console.log(data[i].gs$cell);
filteredData.push(elem.gs$cell);
}
});
// Create 2-dimensional array of data
cleanData = Array(height).fill(null).map(()=>Array(width).fill(null));
filteredData.forEach(elem => cleanData[parseInt(elem.row)-rowBounds[0]][parseInt(elem.col)-colBounds[0]] = elem.$t);
return cleanData;
}