简体   繁体   中英

How exactly to use updateDimensionProperties in google-spreadsheet

I tried to add columns in my Google Sheet, using this . But I always get error 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 .
  • You have already been able to get and put values using Sheets API.
  • You are using the latest version of 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. Ref
  • And also, it seems that the arguments of updateDimensionProperties() are columnsOrRows , props , bounds , bounds.startIndex and bounds.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.

References:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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