jsonkenl / xlsxir

Xlsx parser for the Elixir language.
MIT License
212 stars 83 forks source link

Support cells with CellMetadata, ValueMetadata, and Phonetic attributes #98

Closed dbernheisel closed 4 years ago

dbernheisel commented 4 years ago

In the OpenXML spec, there are three additional XML attributes that may be present: cm, vm, and ph. Before this commit, this would raise an error specifying "Unknown attribute".

The Cell Metadata index isn't required for rendering the data within the cell. Neither is Value Metadata. Both of these are for extensions to operate upon the cells.

The cell "Show Phonetic" attribute isn't required either, as it only informs the tooltip the user would see if this is present.

These three additional attributes are now ignored since they don't affect the rendered value.

I tested this using Elixir 1.9.4 and Erlang 22.0.3.

Without the changes, this is what Xlsxir would do when parsing the included fixtures ``` 1) test parses cells with cell metadata successfully (XlsxirTest) test/xlsxir_test.exs:129 ** (RuntimeError) Unknown cell attribute code: {:ok, pid} = multi_extract("./test/test_data/cell-metadata.xlsx", 0) stacktrace: (xlsxir) lib/xlsxir/parse_worksheet.ex:73: anonymous fn/2 in Xlsxir.ParseWorksheet.sax_event_hand ler/4 (elixir) lib/enum.ex:1336: Enum."-map/2-lists^map/1-0-"/2 (xlsxir) lib/xlsxir/parse_worksheet.ex:68: Xlsxir.ParseWorksheet.sax_event_handler/4 (erlsom) .../xlsxir/deps/erlsom/src/erlsom_sax_utf8.erl:1408: :erlsom_sax_utf8.wrap Callback/2 (erlsom) .../xlsxir/deps/erlsom/src/erlsom_sax_utf8.erl:936: :erlsom_sax_utf8.parse ContentLT/2 (erlsom) .../xlsxir/deps/erlsom/src/erlsom_sax_utf8.erl:196: :erlsom_sax_utf8.parse /2 (xlsxir) lib/xlsxir/sax_parser.ex:61: Xlsxir.SaxParser.parse/3 (xlsxir) lib/xlsxir/xlsx_file.ex:93: Xlsxir.XlsxFile.parse_to_ets/3 (xlsxir) lib/xlsxir.ex:89: Xlsxir.extract/4 test/xlsxir_test.exs:130: (test) ...... 2) test parses cells with value metadata successfully (XlsxirTest) test/xlsxir_test.exs:135 ** (RuntimeError) Unknown cell attribute code: {:ok, pid} = multi_extract("./test/test_data/value-metadata.xlsx", 0) stacktrace: (xlsxir) lib/xlsxir/parse_worksheet.ex:73: anonymous fn/2 in Xlsxir.ParseWorksheet.sax_event_hand ler/4 (elixir) lib/enum.ex:1336: Enum."-map/2-lists^map/1-0-"/2 (xlsxir) lib/xlsxir/parse_worksheet.ex:68: Xlsxir.ParseWorksheet.sax_event_handler/4 (erlsom) .../xlsxir/deps/erlsom/src/erlsom_sax_utf8.erl:1408: :erlsom_sax_utf8.wrap Callback/2 (erlsom) .../xlsxir/deps/erlsom/src/erlsom_sax_utf8.erl:936: :erlsom_sax_utf8.parse ContentLT/2 (erlsom) .../xlsxir/deps/erlsom/src/erlsom_sax_utf8.erl:196: :erlsom_sax_utf8.parse /2 (xlsxir) lib/xlsxir/sax_parser.ex:61: Xlsxir.SaxParser.parse/3 (xlsxir) lib/xlsxir/xlsx_file.ex:93: Xlsxir.XlsxFile.parse_to_ets/3 (xlsxir) lib/xlsxir.ex:89: Xlsxir.extract/4 test/xlsxir_test.exs:136: (test) ```
pierot commented 4 years ago

@jsonkenl any chance to get this merged?

jsonkenl commented 4 years ago

@pierot and @dbernheisel Sorry for the delay!

pierot commented 4 years ago

@jsonkenl thanks! I didn't want to pressure you, just reminding :)

deepfryed commented 5 months ago

@jsonkenl any chance you could publish a new version to hex.pm ?