繁体   English   中英

如何在谷歌电子表格中使用 updateDimensionProperties

[英]How exactly to use updateDimensionProperties in google-spreadsheet

我尝试使用这个在我的 Google 表格中添加列。 但我总是收到错误UnhandledPromiseRejectionWarning: TypeError: doc.updateDimensionProperties is not a function

这是我的代码:

const doc = new GoogleSpreadsheet('google-id');

async function updateTable(token){
  await doc.useServiceAccountAuth(require('./credentials.json'));
  await doc.updateDimensionProperties("COLUMNS", 5, 1);
}

我相信你的目标和你的情况如下。

  • 您想通过google-spreadsheet使用updateDimensionProperties()
  • 您已经能够使用 Sheets API 获取和放置值。
  • 您使用的是最新版本的 google-spreadsheet。

改装要点:

  • 当我看到“node-google-spreadsheet”的脚本时,似乎需要将updateDimensionProperties()用于sheet对象。 参考
  • 而且,似乎updateDimensionProperties()的参数是columnsOrRowspropsboundsbounds.startIndexbounds.endIndex

当以上几点反映到你的脚本中时,它变成如下。

修改后的脚本:

从:
 await doc.useServiceAccountAuth(require('./credentials.json')); await doc.updateDimensionProperties("COLUMNS", 5, 1);
到:
 await doc.useServiceAccountAuth(require('./credentials.json')); await doc.loadInfo(); const sheet = doc.sheetsByIndex[0]; await sheet.updateDimensionProperties("COLUMNS", { pixelSize: 200 }, { startIndex: 2, endIndex: 3 });
  • 在这个修改后的脚本中,作为示例,电子表格中第 1 个工作表的“C”列的宽度更改为 200 像素。

参考:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM