summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2022-06-02 21:59:47 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2022-06-02 21:59:47 -0400
commitd58185d1e54f9b1d749ab9ee9380f2e870993c7c (patch)
tree2ad99bf8a1e25e1b88497d78506c97e5f2273957
parentb8bbfdc622841a3a0b8963ff500dde5bb87d9ae9 (diff)
downloadorcus-d58185d1e54f9b1d749ab9ee9380f2e870993c7c.tar.gz
Use import_number_format in xlsx
-rw-r--r--src/liborcus/xlsx_context.cpp48
-rw-r--r--src/liborcus/xlsx_context.hpp2
2 files changed, 29 insertions, 21 deletions
diff --git a/src/liborcus/xlsx_context.cpp b/src/liborcus/xlsx_context.cpp
index 723baf13..ccf6d49b 100644
--- a/src/liborcus/xlsx_context.cpp
+++ b/src/liborcus/xlsx_context.cpp
@@ -1016,31 +1016,36 @@ void xlsx_styles_context::characters(std::string_view /*str*/, bool /*transient*
void xlsx_styles_context::start_element_number_format(const xml_token_pair_t& parent, const xml_attrs_t& attrs)
{
- xml_elem_stack_t expected_elements;
- expected_elements.push_back(xml_token_pair_t(NS_ooxml_xlsx, XML_numFmts));
- expected_elements.push_back(xml_token_pair_t(NS_ooxml_xlsx, XML_dxf));
+ const xml_elem_set_t expected_elements = {
+ { NS_ooxml_xlsx, XML_numFmts },
+ { NS_ooxml_xlsx, XML_dxf },
+ };
+
xml_element_expected(parent, expected_elements);
- if (mp_styles)
+ if (!mp_styles)
+ return;
+
+ mp_numfmt = mp_styles->get_number_format();
+ ENSURE_INTERFACE(mp_numfmt, import_number_format);
+
+ for (const xml_token_attr_t& attr : attrs)
{
- for (const xml_token_attr_t& attr : attrs)
- {
- if (attr.ns && attr.ns != NS_ooxml_xlsx)
- continue;
+ if (attr.ns && attr.ns != NS_ooxml_xlsx)
+ continue;
- switch (attr.name)
+ switch (attr.name)
+ {
+ case XML_numFmtId:
{
- case XML_numFmtId:
- {
- long id = to_long(attr.value);
- mp_styles->set_number_format_identifier(id);
- break;
- }
- case XML_formatCode:
- {
- mp_styles->set_number_format_code(attr.value);
- break;
- }
+ long id = to_long(attr.value);
+ mp_numfmt->set_identifier(id);
+ break;
+ }
+ case XML_formatCode:
+ {
+ mp_numfmt->set_code(attr.value);
+ break;
}
}
}
@@ -1144,7 +1149,8 @@ void xlsx_styles_context::end_element_number_format()
if (!mp_styles)
return;
- mp_styles->commit_number_format();
+ assert(mp_numfmt);
+ mp_numfmt->commit();
}
}
diff --git a/src/liborcus/xlsx_context.hpp b/src/liborcus/xlsx_context.hpp
index ec830f75..30615d06 100644
--- a/src/liborcus/xlsx_context.hpp
+++ b/src/liborcus/xlsx_context.hpp
@@ -25,6 +25,7 @@ namespace spreadsheet { namespace iface {
class import_fill_style;
class import_border_style;
class import_cell_protection;
+ class import_number_format;
}}
/**
@@ -84,6 +85,7 @@ private:
spreadsheet::iface::import_fill_style* mp_fill = nullptr;
spreadsheet::iface::import_border_style* mp_border = nullptr;
spreadsheet::iface::import_cell_protection* mp_protection = nullptr;
+ spreadsheet::iface::import_number_format* mp_numfmt = nullptr;
string_pool m_pool;
bool m_diagonal_up;