tfussell / xlnt

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

error: attribute 'builtinId' expected #82

Closed adam-nielsen closed 8 years ago

adam-nielsen commented 8 years ago

Just found this error using the latest xlnt code. Not sure whether the XML parser is being overly strict or what. The .xlsx file in question was produced with Excel.

terminate called after throwing an instance of 'xml::parsing'
  what():  xl/styles.xml:2:1909: error: attribute 'builtinId' expected

#5  0x00007ffff3b174d8 in __cxxabiv1::__cxa_throw (obj=0x866930, tinfo=0x7ffff41d11d8 <typeinfo for xml::parsing>, dest=0x7ffff3eefc70 <xml::parsing::~parsing()>) at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_throw.cc:87
#6  0x00007ffff3f2f60c in xml::parser::attribute[abi:cxx11](xml::qname const&) const () from /usr/lib/libxlnt.so.0.9
#7  0x00007ffff3ef379e in unsigned long xml::parser::attribute<unsigned long>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const () from /usr/lib/libxlnt.so.0.9
#8  0x00007ffff3ee0cba in xlnt::detail::xlsx_consumer::read_stylesheet() () from /usr/lib/libxlnt.so.0.9
#9  0x00007ffff3eeebea in xlnt::detail::xlsx_consumer::populate_workbook() () from /usr/lib/libxlnt.so.0.9
#10 0x00007ffff3ea7ef2 in xlnt::workbook::load(std::istream&) () from /usr/lib/libxlnt.so.0.9
#11 0x00007ffff3ea82c4 in xlnt::workbook::load(xlnt::path const&) () from /usr/lib/libxlnt.so.0.9
#12 0x00007ffff3ea843f in xlnt::workbook::load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /usr/lib/libxlnt.so.0.9
#13 0x0000000000432dca in main (iArgC=9, cArgV=0x7fffffffe2a8) at main.cpp:170

Any ideas what the issue is and whether it can be fixed? Thanks as usual!

tfussell commented 8 years ago

I just checked the ECMA 376 standard and builtinId is optional for styles. I was assuming that every style would have one. I'll make a quick fix for that. Here's the relevant part of the standard by the way:

<xsd:complexType name="CT_CellStyle">
    <xsd:sequence>
        <xsd:element name="extLst" type="CT_ExtensionList" minOccurs="0" maxOccurs="1"/>
    </xsd:sequence>
    <xsd:attribute name="name" type="s:ST_Xstring" use="optional"/>
    <xsd:attribute name="xfId" type="ST_CellStyleXfId" use="required"/>
    <xsd:attribute name="builtinId" type="xsd:unsignedInt" use="optional"/>
    <xsd:attribute name="iLevel" type="xsd:unsignedInt" use="optional"/>
    <xsd:attribute name="hidden" type="xsd:boolean" use="optional"/>
    <xsd:attribute name="customBuiltin" type="xsd:boolean" use="optional"/>
</xsd:complexType>
adam-nielsen commented 8 years ago

Many thanks! That fixed the issue.