简体   繁体   English

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

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

I tried to add columns in my Google Sheet, using this .我尝试使用这个在我的 Google 表格中添加列。 But I always get error UnhandledPromiseRejectionWarning: TypeError: doc.updateDimensionProperties is not a function但我总是收到错误UnhandledPromiseRejectionWarning: TypeError: doc.updateDimensionProperties is not a function

Here is my code:这是我的代码:

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

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

I believe your goal and your situation as follows.我相信你的目标和你的情况如下。

  • You want to use updateDimensionProperties() using google-spreadsheet .您想通过google-spreadsheet使用updateDimensionProperties()
  • You have already been able to get and put values using Sheets API.您已经能够使用 Sheets API 获取和放置值。
  • You are using the latest version of google-spreadsheet.您使用的是最新版本的 google-spreadsheet。

Modification points:改装要点:

  • When I saw the script of "node-google-spreadsheet", it seems that updateDimensionProperties() is required to be used for sheet object.当我看到“node-google-spreadsheet”的脚本时,似乎需要将updateDimensionProperties()用于sheet对象。 Ref 参考
  • And also, it seems that the arguments of updateDimensionProperties() are columnsOrRows , props , bounds , bounds.startIndex and bounds.endIndex .而且,似乎updateDimensionProperties()的参数是columnsOrRowspropsboundsbounds.startIndexbounds.endIndex

When above points are reflected to your script, it becomes as follows.当以上几点反映到你的脚本中时,它变成如下。

Modified script:修改后的脚本:

From: 从:
 await doc.useServiceAccountAuth(require('./credentials.json')); await doc.updateDimensionProperties("COLUMNS", 5, 1);
To: 到:
 await doc.useServiceAccountAuth(require('./credentials.json')); await doc.loadInfo(); const sheet = doc.sheetsByIndex[0]; await sheet.updateDimensionProperties("COLUMNS", { pixelSize: 200 }, { startIndex: 2, endIndex: 3 });
  • In this modified script, as the sample, the width of the column "C" of the 1st sheet in the Spreadsheet is changed to 200 pixels.在这个修改后的脚本中,作为示例,电子表格中第 1 个工作表的“C”列的宽度更改为 200 像素。

References:参考:

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

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