tfussell / xlnt

:bar_chart: Cross-platform user-friendly xlsx library for C++11+
Other
1.49k stars 418 forks source link

error: unexpected attribute 'aca' #473

Closed fcojavmc closed 2 years ago

fcojavmc commented 4 years ago

I have found this error when loading Excel file (xlsx):

<f aca="false">SUM(G12:G212)</f>

terminate called after throwing an instance of 'xml::parsing' what(): xl/worksheets/sheet2.xml:2:4178: error: unexpected attribute 'aca'

linville commented 4 years ago

I believe this is related to #436. I had a similar error on a cell: <f ca="1">"5 Jun 2020"</f>. Using the workaround described in one of the comments of #436 worked for me.

tfussell commented 4 years ago

I will fix this soon. It looks like it's aca (Always Calculate Array) attribute on formula elements.

nschlia commented 3 years ago

As a work around, I changed xlsx_consumer.cpp at line 226 to call parser->attribute("aca") so that the attribute is marked handled. I guess the correct handling of the attribute needs to be added, but at least the file is opened and read:

index 62d9c418..e3e27ae7 100644
--- a/source/detail/serialization/xlsx_consumer.cpp
+++ b/source/detail/serialization/xlsx_consumer.cpp
@@ -222,6 +222,8 @@ xlnt::detail::Cell parse_cell(xlnt::row_t row_arg, xml::parser *parser)
             else if (string_equal(parser->name(), "f"))
             {
                 c.formula_string += std::move(parser->value());
+
+                    parser->attribute("aca");   // ignore attribute, see https://github.com/tfussell/xlnt/issues/473
             }
         }
         else if (level == 3)
nschlia commented 3 years ago

I have cloned the project and added a workaround, i.e, the offending attributes (and only those) are simply ignored. Probably these need no further handling and that could remain the final solution. Thats up to @tfussell. Maybe he wants to take my code as a starter to fix this issue. Anyway, the problem files can be loaded with these additions.

doomlaur commented 2 years ago

I can confirm that this issue is present in xlnt v1.5.0 (latest stable release). The fix from @nschlia worked very well, thank you! However, compiling xlnt from the latest commit (currently 3a279fc from 2021-08-22) fixed this issue, so it seems that no fix is needed anymore.

nschlia commented 2 years ago

Confirmed. Fixed with current version. Can be closed.