【问题标题】:How exactly to use updateDimensionProperties in google-spreadsheet如何在谷歌电子表格中准确使用 updateDimensionProperties
【发布时间】:2020-09-30 19:21:49
【问题描述】:

我尝试使用this 在我的 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);
}

【问题讨论】:

    标签: javascript node.js google-sheets


    【解决方案1】:

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

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

    修改点:

    • 当我看到“node-google-spreadsheet”的脚本时,似乎updateDimensionProperties() 需要用于sheet 对象。 Ref
    • 而且,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 });
    
    • 在此修改后的脚本中,作为示例,电子表格中第一张工作表的“C”列的宽度更改为 200 像素。

    参考资料:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多