xlsxir icon indicating copy to clipboard operation
xlsxir copied to clipboard

Xlsxir reads the wrong sheet name from workbook created with Elixlsx

Open norpan opened this issue 5 years ago • 4 comments

I'm not sure if the bug is with Elixlsx or with Xlsxir, but the file works when opened in Excel.

bug.xlsx

iex(19)> %Elixlsx.Workbook{sheets: [%Elixlsx.Sheet{name: "Sheet1", rows: [["A"]]}, %Elixlsx.Sheet{name: "Sheet2", rows: [["A"], ["B"]]}]} |> Elixlsx.write_to("bug.xlsx")
{:ok, 'bug.xlsx'}
iex(20)> [{:ok, sheet1}, {:ok, sheet2}] = Xlsxir.multi_extract("bug.xlsx")
[
  ok: #Reference<0.1684016233.731512836.50328>,
  ok: #Reference<0.1684016233.731512836.50330>
]
iex(21)> Xlsxir.get_info(sheet1)
[rows: 1, cols: 1, cells: 1, name: nil]
iex(22)> Xlsxir.get_info(sheet2)
[rows: 2, cols: 1, cells: 2, name: "Sheet1"]

norpan avatar Jul 22 '19 18:07 norpan

I've encountered the same error. It's not a parsing problem: the attributes are correctly extracted and stored in the workbook ETS table. The issue occurs when retrieving the name of the sheet being parsed to populate the {:info, :worksheet_name, ...} tuple stored the sheet ETS table.

This library seems to assume that the sheets are named sheet<rid>.xml which is apparently not standard behavior.

It might work on a lucky day but it is entirely depending on the implementation of the software writing the package.

For instance, an xlsx file written by Apple Numbers uses the sheetId attribute as a file basename suffix (and it looks like Elixlsx does the same. In that case, using sheet_id instead of rid as ETS table key fixes it.

I suppose that the only reliable solution is to rely on the explicit mapping provided in _rels/workbook.xml.rels to map sheet XML files with their corresponding r:id.

xavier avatar Nov 06 '19 14:11 xavier

Since there hasn't been activity on this for quite some time, I'll just mention here for others visiting this issue, it has not been resolved as of this comment.

grantwest avatar Jan 05 '23 17:01 grantwest

Got the same problem :)

larshei avatar Feb 10 '24 10:02 larshei

when I download xlsx file from google sheets, it works fine but when I download xlsx file from sharepoint, I get this error

what made this a disaster for me was that I relied on the sheet labels

maysam avatar Apr 27 '24 12:04 maysam