最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Google Sheets API v4写入数据

网站源码admin22浏览0评论

Google Sheets API v4写入数据

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,
};

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论