disambiguate duplicate header names #194

Closed
patricklam wants to merge 0 commits from master into master
patricklam commented 2015-03-29 02:13:44 +00:00 (Migrated from github.com)

If multiple columns have the same header, rename subsequent columns to HEADER_1, HEADER_2, etc.

If multiple columns have the same header, rename subsequent columns to HEADER_1, HEADER_2, etc.
SheetJSDev commented 2015-03-29 03:27:04 +00:00 (Migrated from github.com)

@patricklam so if I'm reading the code correctly (haven't tested it), if the table is

Foo Bar Bar Bar Bar
1 2 3 4 5

then the row object will be

{
    "Foo": 1,
    "Bar": 2,
    "Bar_1": 3,
    "Bar_2": 4,
    "Bar_3": 5
}

Do we want to rename the first Bar to Bar_1 ?

@notatestuser @nathanathan thoughts?

@patricklam so if I'm reading the code correctly (haven't tested it), if the table is | Foo | Bar | Bar | Bar | Bar | | --- | --- | --- | --- | --- | | 1 | 2 | 3 | 4 | 5 | then the row object will be ``` json { "Foo": 1, "Bar": 2, "Bar_1": 3, "Bar_2": 4, "Bar_3": 5 } ``` Do we want to rename the first Bar to Bar_1 ? @notatestuser @nathanathan thoughts?
patricklam commented 2015-03-29 03:29:38 +00:00 (Migrated from github.com)

The first ambiguous one will be "Bar_1" not "Bar_2" right now. That's kind
of like what happens when you download files and you have a duplicate,
which then gets called File (1) or whatever. I'm indifferent as to what it
is exactly, just have to pick something. It would be another 5 minutes of
implementation to rename the first Bar.

On Sat, Mar 28, 2015 at 11:27 PM, SheetJSDev notifications@github.com
wrote:

@patricklam https://github.com/patricklam so if I'm reading the code
correctly (haven't tested it), if the table is
Foo Bar Bar Bar Bar 1 2 3 4 5

then the row object will be

{
"Foo": 1,
"Bar": 2,
"Bar_2": 3,
"Bar_3": 4,
"Bar_4": 5
}

Do we want to rename the first Bar to Bar_1 ?

@notatestuser https://github.com/notatestuser @nathanathan
https://github.com/nathanathan thoughts?


Reply to this email directly or view it on GitHub
https://github.com/SheetJS/js-xlsx/pull/194#issuecomment-87346537.

The first ambiguous one will be "Bar_1" not "Bar_2" right now. That's kind of like what happens when you download files and you have a duplicate, which then gets called File (1) or whatever. I'm indifferent as to what it is exactly, just have to pick something. It would be another 5 minutes of implementation to rename the first Bar. On Sat, Mar 28, 2015 at 11:27 PM, SheetJSDev notifications@github.com wrote: > @patricklam https://github.com/patricklam so if I'm reading the code > correctly (haven't tested it), if the table is > Foo Bar Bar Bar Bar 1 2 3 4 5 > > then the row object will be > > { > "Foo": 1, > "Bar": 2, > "Bar_2": 3, > "Bar_3": 4, > "Bar_4": 5 > } > > Do we want to rename the first Bar to Bar_1 ? > > @notatestuser https://github.com/notatestuser @nathanathan > https://github.com/nathanathan thoughts? > > — > Reply to this email directly or view it on GitHub > https://github.com/SheetJS/js-xlsx/pull/194#issuecomment-87346537.
YueZhaoDreams commented 2016-01-26 19:49:31 +00:00 (Migrated from github.com)

Is this implemented in the current version? I have a concern that when the headers are [Bar, Bar, Bar_1] will the fix work fine?

Is this implemented in the current version? I have a concern that when the headers are [Bar, Bar, Bar_1] will the fix work fine?
laurence-hudson-tessella commented 2016-06-17 10:08:52 +00:00 (Migrated from github.com)

+1

+1
r1z1a commented 2017-04-20 13:30:06 +00:00 (Migrated from github.com)

Is there way to disable this?

Is there way to disable this?
SheetJSDev commented 2017-04-20 15:58:53 +00:00 (Migrated from github.com)

If you are running into this issue @r1z1a that means your data file has multiple column headers with the same value, like the example from an earlier post in the thread:

Foo Bar Bar Bar Bar
1 2 3 4 5

The old behavior used the last column, so you would have seen {Foo:1,Bar:5}. The current behavior disambiguates so you would see {Foo:1,Bar:2,Bar_1:3,Bar_2:4,Bar_3:5}. If you really want to do it, you can generate custom headers in an array and pass it to sheet_to_json, as shown in the README: XLSX.utils.sheet_to_json(ws, {header:['Foo', undefined, undefined, undefined, 'Bar']})

If you are running into this issue @r1z1a that means your data file has multiple column headers with the same value, like [the example from an earlier post in the thread](https://github.com/SheetJS/js-xlsx/pull/194#issuecomment-87346537): | Foo | Bar | Bar | Bar | Bar | | --- | --- | --- | --- | --- | | 1 | 2 | 3 | 4 | 5 | The old behavior used the last column, so you would have seen `{Foo:1,Bar:5}`. The current behavior disambiguates so you would see `{Foo:1,Bar:2,Bar_1:3,Bar_2:4,Bar_3:5}`. If you really want to do it, you can generate custom headers in an array and pass it to sheet_to_json, as shown in the README: `XLSX.utils.sheet_to_json(ws, {header:['Foo', undefined, undefined, undefined, 'Bar']})`

Pull request closed

Sign in to join this conversation.
No description provided.