-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parse.gs
106 lines (90 loc) · 2.88 KB
/
Parse.gs
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
function parseData(idNum, columnNum) {
/// CHANGE id FOR PARSING DATA AT A GOOGLE SPREADSHEET ///
let id = '1C2DGt8YiKjUylyivOi8EEtkbKDsc-EPpJFqdqSp7-W8'
var ss = SpreadsheetApp.openById(id);
SpreadsheetApp.setActiveSpreadsheet(ss);
return SpreadsheetApp.getActiveSpreadsheet()
.getDataRange().getValues();
//let data = SpreadsheetApp.getActiveSpreadsheet()
// .getDataRange().getValues();
//Logger.log(data[idNum][columnNum]);
//return data[idNum][columnNum];
}
function loadSourceSheet() {
/// CHANGE id FOR PARSING SOURCE SPREADSHEET ///
id = '10Mz7mPm7_zXodu5ceDbxCyXPqpMR6e0hJMQ94WmL9vE';
var ss = SpreadsheetApp.openById(id);
let sheets = ss.getSheets();
return sheets;
}
function backupSheet() {
/// CHANGE id FOR BACK-UP SPREADSHEET ///
let id = '1_FbqHapL9_cDH716es2YA3I2_QjBHEKWJAFvraMBPoI'
var ss = SpreadsheetApp.openById(id);
let backupSheets = ss.getSheets();
let sourceSheet = loadSourceSheet();
for (let i = 0; i < sourceSheet.length; i++) {
let sheet = sourceSheet[i];
let sheetName = sheet.getSheetName();
let parsedSheet = ss.getSheetByName(sheetName);
let data = sheet.getDataRange().getValues();
if (parsedSheet === null) {
ss.insertSheet(sheetName);
}
parsedSheet.clear();
console.log(parsedSheet)
data.forEach(row => {
let rowArr = [];
row.forEach(val => {
rowArr.push(val);
})
//console.log(row);
/// For a new sheet ///
parsedSheet === null ? console.log('There is no sheet') : false;
parsedSheet.appendRow(row);
})
}
}
function backupDoubleCheck() {
try {
backupSheet();
} catch(err) {
backupSheet();
}
}
function dataFromSheet() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
let sheetIdx = ss.getSheetByName('Parsed_Data').getIndex();
let parsedSheet = ss.getSheets()[sheetIdx - 1];
let data = parsedSheet.getDataRange().getValues();
return data;
}
function createSheet() {
/// CHANGE id FOR PARSING TARGET SPREADSHEET ///
id = '10Mz7mPm7_zXodu5ceDbxCyXPqpMR6e0hJMQ94WmL9vE'
var ss = SpreadsheetApp.openById(id);
//var templateSheet = ss.getSheetByName('Sales');
/// This is for making a new sheet in current excel ///
let parsedSheet = ss.getSheetByName('Parsed_Data');
if (parsedSheet !== null) {
Logger.log('Already has parsedSheet');
} else {
ss.insertSheet('Parsed_Data');
}
let data = parseData();
//let sheetData = SpreadsheetApp.getActiveSpreadsheet().getDataRange();
parsedSheet.clear();
data.length === 1 || data === null ? console.log('There is no data to parse') : false;
Logger.log('data: ' + data);
let test = [1, 2]
data.forEach(row => {
let rowArr = [];
row.forEach(val => {
rowArr.push(val);
})
console.log(row);
/// For a new sheet ///
parsedSheet === null ? console.log('There is no sheet') : false;
parsedSheet.appendRow(row);
})
}