【发布时间】:2021-07-22 22:02:07
【问题描述】:
我有一个将 csv 转换为数组并使用数据更新工作表的函数。
在 7 个 csv 文件中,有两个给了我一个非常奇怪的错误:
Error: Invalid data[0]: Requested writing within range [Sheet1!A:N], but tried writing to column [O]
column[0] 到底是什么?此 csv 文件具有与其他文件相同的标题。我之前遇到过这个错误,但是 column[] 里面有一个字母。
我的函数如下所示:
const sheets = google.sheets({version: 'v4', auth: authorize()});
const rows = await csv({output: "csv", noheader: true}).fromFile(filepath);
await sheets.spreadsheets.values.batchUpdate({
spreadsheetId: folderId,
resource: {
// How the input data should be interpreted.
valueInputOption: 'RAW',
// The new values to apply to the spreadsheet.
data: [{
range: 'Sheet1!A:N',
majorDimension: 'ROWS',
values: rows
}],
}
}, {}, callback...
}
您知道数据中的什么问题导致了这种情况(如果这是问题所在)?
【问题讨论】:
-
rows变量长什么样?此外,您能否确认您提供的范围是准确的?
标签: node.js google-sheets google-sheets-api