Google Sheets API v4写入数据

编程入门 行业动态 更新时间:2024-10-07 20:33:58

Google Sheets API v4写入<a href=https://www.elefans.com/category/jswz/34/1771445.html style=数据"/>

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写入数据

本文发布于:2024-05-07 14:28:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1756684.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   Sheets   Google   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!