Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nktnet1 opened this issue Oct 5, 2024 · 2 comments
Open

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

nktnet1 opened this issue Oct 5, 2024 · 2 comments

Comments

@nktnet1
Copy link

nktnet1 commented Oct 5, 2024

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

@nktnet1 nktnet1 changed the title [Bug] heading row gets replaced when there are hidden columns [Bug] addRows replace heading row when there are hidden columns Oct 5, 2024
@narendra-paiteq
Copy link

hello, @nktnet1 have you found any workaround for this issue?

@nktnet1
Copy link
Author

nktnet1 commented Oct 18, 2024

Not really - other than manually un-hiding the columns, run my script, then hiding them again.

Other alternatives might be to use the official Google API, or for a hacky solution, include the header row as the first array item in addRows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants