我正在尝试使用NODEJS和"谷歌电子表格"模块,我已经设法在单元格中写入,读取,删除,但我不能在单元格中放入评论,并且我看到的教程只教中断的形式,有人可以帮助我吗?非常感谢。
const { GoogleSpreadsheet } = require('google-spreadsheet');
const creds = require('./googleSheetCredentials.json');
async function accessSpreadSheet() {
const doc = new GoogleSpreadsheet('XXXXXXXXXXXX');
await doc.useServiceAccountAuth(creds);
await doc.loadInfo();
const sheet = doc.sheetsByIndex[0];
await sheet.addRow({
Login: 'hello world', // column A
Date: '2020-01-01' // column B
});
const row = await sheet.getRows();
console.log(row);
//await sheet.addComment('2', 'Login', 'Hello world'); Doesn't work
}
accessSpreadSheet();
我相信你的目标是这样的。
- 您想要向单元格插入注释。
- 从您的显示脚本和
await sheet.addComment('2', 'Login', 'Hello world');
中,我猜测您想要在列";a &;"中插入注释。
- 从您的显示脚本和
- 你想要使用node-google-spreadsheet来实现这一点。
在这种情况下,下面的修改如何?
修改脚本:
const { GoogleSpreadsheet } = require('google-spreadsheet');
const creds = require('./googleSheetCredentials.json');
async function accessSpreadSheet() {
const doc = new GoogleSpreadsheet('XXXXXXXXXXXX');
await doc.useServiceAccountAuth(creds);
await doc.loadInfo();
const sheet = doc.sheetsByIndex[0];
// I modified below script.
const res = await sheet.addRow({
Login: "hello world", // column A
Date: "2020-01-01", // column B
});
await sheet.loadCells();
sheet.getCellByA1("A" + res.rowIndex).note = "sample note";
await sheet.saveUpdatedCells();
}
accessSpreadSheet();
- 当您运行这个脚本时,
sample note
的注释被插入到列" a ">
注意:
- 这个修改的脚本假设您已经能够使用
google-spreadsheet
和await sheet.addRow
脚本的表API获得并将值放入谷歌电子表格。请小心。 参考:
- node-google-spreadsheet