Search code examples
node.jsgoogle-sheetsgoogle-apigoogle-sheets-api

How to unfreeze a google sheets with nodejs and api


I'm stucked with a gsheets i want to update because there are some rows and columns frozen.

I'm using the google-spreadsheet npm package but nothing in it to explicitly unfreeze a sheet.

I found this:

await worksheet.updateProperties({
  gridProperties: {
    frozenColumnCount: 0,
    frozenRowCount: 0,
  }
});

and it's "shorthand"

await worksheet.updateGridProperties({
  frozenColumnCount: 0,
  frozenRowCount: 0,
});

But in the two cases, it still say that i can't delete row frozen.


Solution

  • Seems that google-spreadsheet had a bug.

    Method updateProperties and its shorthand updateGridProperties use internal getFieldMask method to determine which field are updated. And didn't manage correctly the gridProperties ones.

    I opened a pull request to fix it: https://github.com/theoephraim/node-google-spreadsheet/pull/674

    A workaround is to directly make your request with field hand-provided:

    worksheet._makeSingleUpdateRequest('updateSheetProperties', {
      properties: {
        sheetId: worksheet.sheetId,
        gridProperties: {
          frozenColumnCount: 0,
          frozenRowCount: 0,
        },
      },
      fields: 'gridProperties.frozenColumnCount,gridProperties.frozenRowCount',
    });