Skip to content

[Bug] addRows replace heading row when there are hidden columns #706

@nktnet1

Description

@nktnet1

Below is the code I'm currently using:

const serviceAccountAuth = new JWT({
  email: process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL,
  key: process.env.GOOGLE_PRIVATE_KEY,
  scopes: ['https://www.googleapis.com/auth/spreadsheets'],
});

const doc = new GoogleSpreadsheet('<some sheet ID>', serviceAccountAuth);
await doc.loadInfo();

const data = getRowData();

if (data.length > 0) {
  const sheet = doc.sheetsByTitle['some title'];
  await sheet.clear();
  await sheet.setHeaderRow(Object.keys(data[0]));

  // This replaces the heading row if there are hidden columns
  await sheet.addRows(data);
}

This works fine when there are no hidden columns. However, if I were to hide some columns using Google Sheet's GUI interface, the heading gets replaced by the first row when using sheet.addRows(data)

By hidden columns, I mean this:

hide-columns

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions