jsonkenl / xlsxir

Xlsx parser for the Elixir language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Xlsxir reads the wrong sheet name from workbook created with Elixlsx

norpan opened this issue · 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"]

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.

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.

Got the same problem :)

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