question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`json_to_sheet` mutates header array

See original GitHub issue

While I try to change header titles by passing array of titles to options like below it does not override the headers. Instead it writes new headers first and original data with old headers again from next cell.

I am experiencing the same problem.

In addition, sheets js is mutating the header array passed in, which is not something I would ever expect.

Example:

const header = ['field2', 'field3'];
const data = [{field1: 'foo', 'field2': 'bar', 'field3': 'baz'}]

const worksheet = XLSX.utils.json_to_sheet(data, {header});

console.log(header); // RESULTS:  ["field2", "field3", "field1"]

_Originally posted by @paustint in https://github.com/SheetJS/sheetjs/issues/1487#issuecomment-706759470_

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
SheetJSDevcommented, Oct 11, 2020

Now that you understand this, maybe you can help improve the docs 😃 We’ll accept a PR that clarifies the behavior.

0reactions
reviewhercommented, Sep 11, 2021

af34ae4178390974977101221d9f48869d5a1228

Read more comments on GitHub >

github_iconTop Results From Across the Web

while using header option with XLSX.utils.json_to_sheet ...
While I try to change header titles by passing array of titles to options like below it does not override the headers. Instead...
Read more >
How to read and write Excel file in Node.js ? - GeeksforGeeks
We use two main functions in this program i.e json_to_sheet() which accepts an array of objects and converts them into a worksheet and ......
Read more >
Data Grids and Tables | SheetJS Community Edition
The sheet_to_json utility function generates arrays of objects, which is suitable for a number of libraries. When more advanced shapes are ...
Read more >
[Solved]-angular material data table export to excel-angular.js
In my case, alternative to table_to_sheet is to use json_to_sheet . Since I don't know how to properly export the table (with pagination)...
Read more >
How to Import Export Excel & CSV In React 2022
json_to_sheet converts an array of JS objects to a worksheet ... Open the App.js file and make the following changes.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found