簡體   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