数据"/>
Google Sheets API v4写入数据
我正在尝试使用Nodejs API v4将数据写入Google表格。我可以成功读取和清除数据,因此我已正确设置了所有内容。但是,使用docs here中的示例作为更新方法,我无法确定如何指定要放入Google表格中的数据。我想要一个示例,说明如何将const data
保留的数据粘贴到指定的工作表中。这是我到目前为止的内容:
const data = [
[1, 2],
[3, 4],
];
const auth = new google.auth.GoogleAuth({
scopes: [""],
});
const authClient = await auth.getClient();
const sheets = google.sheets({ version: "v4", auth: authClient });
const request = {
spreadsheetId: "my-spreadsheet-id",
range: "Sheet1!A:E",
valueInputOption: "",
resource: {},
auth: authClient,
};
const response = await sheets.spreadsheets.values.update(request);
回答如下:您必须指定值输入选项
可能的值是:
USER_ENTERED
RAW
INPUT_VALUE_OPTION_UNSPECIFIED
资源是您的数据数组。
示例:
const request = {
spreadsheetId: "my-spreadsheet-id",
range: "Sheet1!A:E",
valueInputOption: "USER_ENTERED",
resource: {values: [
[1, 2],
[3, 4],
]},
auth: authClient,
};
更多推荐
Google Sheets API v4写入数据
发布评论