martijn / xsv

High performance, lightweight .xlsx parser for Ruby that provides nothing a CSV parser wouldn't
https://storck.io/posts/announcing-xsv-1-0-0/
MIT License
194 stars 20 forks source link

Cell values are mapped to incorrect keys in Hash mode #56

Closed myabc closed 6 months ago

myabc commented 6 months ago

To reproduce:

Parsing the following file complex-headers.xlsx

@sheet = Xsv.open("./complex-headers.xlsx").sheets[0]
@sheet.parse_headers!
p @sheet[0]

Expected

{nil=>nil, "Customer nr."=>537066, "Customer name"=>"Unilever", "Item number"=>391790102, "Description"=>"Soap", "Qty outst."=>6, "Another Ref"=>"18-01-2024", "Reference"=>"#JL-65568", "Site address"=>"5 Cross Street", "Zdepot"=>"GG"}

Actual

=> {nil=>"GG", "Customer nr."=>nil, "Customer name"=>537066, "Item number"=>"Unilever", "Description"=>391790102, "Qty outst."=>"Soap", "Another Ref"=>6, "Reference"=>"18-01-2024", "Site address"=>"#JL-65568", "Zdepot"=>"5 Cross Street"}

See #55 for a failing test case.

martijn commented 6 months ago

Thanks for reporting and submitting a test case. The situation of multiple headers with nil values was always a bit messy. Can you see if the fix in #57 works for you?

myabc commented 6 months ago

Hoi @martijn. Thanks for looking into this and coming up with a fix so quickly! I've tested with a real-world .xlsx file that was previously failing and this fixes the issue. 👍🏻 Dank je wel!

martijn commented 6 months ago

Fix released in Xsv 1.3.1