while using header option with XLSX.utils.json_to_sheet , headers not overriding
See original GitHub issueWhile 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.
Here is my code
const ws: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json, {header: headerColumns});
const wb: XLSX.WorkBook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'Transactions');
const excelBuffer: any = XLSX.write(wb, { bookType: 'xlsx', type: 'array' });
this.saveAsExcelFile(excelBuffer, excelFileName);
Also see attached exported file. sample.xlsx
why is it happening? I just want to rename the headers , everything else is working file.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top Results From Across the Web
while using header option with XLSX.utils.json_to_sheet ...
The basic job of "header" option is not to override, rather just shift the starting option of the columns. i.e. any value passed...
Read more >XLSX Json to Sheet with custom headers - StackBlitz
A angular-cli project based on rxjs, xlsx, core-js, zone.js, @angular/core ... XLSX.utils.sheet_add_aoa(ws, Heading);. //Starting in the second row to avoid.
Read more >Utility Functions - SheetJS Community Edition
XLSX.utils.json_to_sheet takes an array of objects and returns a worksheet with automatically-generated "headers" based on the keys of the objects.
Read more >Process Excel to json - Laracasts
I have this code that processes an excel file to a json array in order to import it ... mine so I'm not...
Read more >docbits/82_util.md | sheetjs@v0.18.3 - Deno
XLSX.utils.aoa_to_sheet takes an array of arrays of JS values and returns a worksheet ... skipHeader, false, If true, do not include header row...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@paustint that’s an unrelated issue and should be tracked separately.
@SandeshSarfare @dottodot This is intended behavior. If you want to overwrite the values in the header cells, use
aoa_to_sheet
and directly modify the header names.As described in the docs,
header
option is “Use specified column order (defaultObject.keys
)”.This option exists because of a fundamental ambiguity. Suppose you were trying to write the following to a worksheet:
In what order should fields be written? If you applied the naive approach of using Object.keys order, you’d get a table like
That probably doesn’t make sense. So
header
lets you control the order of the output columns. Each value in the header array is a key that is checked against each object. So if you pass the header["Price", "Name"]
you will seeBut if you pass
["Name", "Price"]
you will seeWhen a key is present in an object but missing from the header array, it is added to the end
I’m having the same issue as above.