forked from BenjaminLevy/cg-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spreadsheet.js
57 lines (49 loc) · 1.83 KB
/
spreadsheet.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
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
// const creds = require('./google-sheets-node/client_secret.json');
// const { promisify } = require('util');
//
//
// async function accesssSpreadsheet(){
// const doc = new GoogleSpreadsheet('1kU4AhgzqQWYGxvbK8Fj4wA6eSO_IWcBZJYcTVcEUhEY')
// await promisify(doc.useServiceAccountAuth)(creds);
// const info = await promisify(doc.getInfo)();
// const sheet = info.worksheets[0];
// console.log(`Title: ${sheet.title}, Rows: ${sheet.rowCount}`);
// }
//
// accesssSpreadsheet();
const { GoogleSpreadsheet } = require('google-spreadsheet');
const creds = require('./client_secret.json');
// spreadsheet key is the long id in the sheets URL
const doc = new GoogleSpreadsheet('1kU4AhgzqQWYGxvbK8Fj4wA6eSO_IWcBZJYcTVcEUhEY');
async function accessSpreadsheet() {
await doc.useServiceAccountAuth({
client_email: creds.client_email,
private_key: creds.private_key,
});
await doc.loadInfo(); // loads document properties and worksheets
console.log(doc.title);
const sheet = doc.sheetsByIndex[0]; // or use doc.sheetsById[id]
const rows = await sheet.getRows();
const c6 = sheet.getCellByA1
// const testCell = await sheet.getCell(0, 0);
console.log(sheet.title);
console.log(sheet.rowCount);
await sheet.loadCells('A1:F31'); // loads a range of cells
console.log(sheet.cellStats); // total cells, loaded, how many non-empty
const a1 = sheet.getCell(1, 0); // access cells using a zero-based index
console.log(sheet.getCell(1, 0).value);
for(let i = 0; i < rows.length; i++){
let currentCell = sheet.getCell(i,0)
if(currentCell.value == "Ellen"){
console.log(sheet.getCell(i,1).value);
}
}
// for(let i = 0; i < rows.length; i++){
// if(rows[13]._rawData[0] = "jfjj"){
// console.log(i);
// }
// }
// if(rows[i]._rawData[0] = "dfdfd"){
// console.log(rows[i]);
}
accessSpreadsheet();