summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2022-06-08 20:59:45 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2022-06-08 20:59:45 -0400
commitc7cec298f498e286220d74eb2364ce2a95cc6e35 (patch)
tree7dc995c35f2b493a9f974459a4228b1adf44ab82
parent80dafcf91af103adb8e7c3ce0eee987399e389ca (diff)
downloadorcus-c7cec298f498e286220d74eb2364ce2a95cc6e35.tar.gz
Use import_cell_style in xlsx
-rw-r--r--include/orcus/spreadsheet/import_interface_styles.hpp6
-rw-r--r--src/liborcus/xlsx_context.cpp63
-rw-r--r--src/liborcus/xlsx_context.hpp2
3 files changed, 37 insertions, 34 deletions
diff --git a/include/orcus/spreadsheet/import_interface_styles.hpp b/include/orcus/spreadsheet/import_interface_styles.hpp
index e44c5df2..c25149b9 100644
--- a/include/orcus/spreadsheet/import_interface_styles.hpp
+++ b/include/orcus/spreadsheet/import_interface_styles.hpp
@@ -341,10 +341,12 @@ public:
virtual void set_xf(size_t index) = 0;
/**
- * Set the index into the built-in style record.
+ * Set the index into the built-in cell style record.
*
* @note This is Excel-specific, and unclear whether it's useful outside of
- * Excel's implementation. Built-in styles are not stored in file.
+ * Excel's implementation. Built-in styles are not stored in file, and
+ * Excel likely has its own internal styles stored in the application
+ * itself.
*
* @param index index into the built-in cell style record.
*/
diff --git a/src/liborcus/xlsx_context.cpp b/src/liborcus/xlsx_context.cpp
index 137ae62d..72435ef9 100644
--- a/src/liborcus/xlsx_context.cpp
+++ b/src/liborcus/xlsx_context.cpp
@@ -370,36 +370,6 @@ public:
}
};
-class cell_style_attr_parser
-{
- spreadsheet::iface::import_styles& m_styles;
-public:
- cell_style_attr_parser(spreadsheet::iface::import_styles& styles) :
- m_styles(styles) {}
-
- void operator() (const xml_token_attr_t& attr)
- {
- switch (attr.name)
- {
- case XML_name:
- m_styles.set_cell_style_name(attr.value);
- break;
- case XML_xfId:
- {
- size_t n = to_long(attr.value);
- m_styles.set_cell_style_xf(n);
- }
- break;
- case XML_builtinId:
- {
- size_t n = to_long(attr.value);
- m_styles.set_cell_style_builtin(n);
- }
- break;
- }
- }
-};
-
class cell_alignment_attr_parser
{
spreadsheet::hor_alignment_t m_hor_align;
@@ -811,13 +781,37 @@ void xlsx_styles_context::start_element(xmlns_id_t ns, xml_token_t name, const x
size_t n = strtoul(ps.data(), nullptr, 10);
mp_styles->set_cell_style_count(n);
}
+ mp_cell_style = mp_styles->get_cell_style();
+ ENSURE_INTERFACE(mp_cell_style, import_cell_style);
break;
}
case XML_cellStyle:
{
// named cell style, some of which are built-in such as 'Normal'.
+ assert(mp_cell_style);
xml_element_expected(parent, NS_ooxml_xlsx, XML_cellStyles);
- for_each(attrs.begin(), attrs.end(), cell_style_attr_parser(*mp_styles));
+
+ for (const xml_token_attr_t& attr : attrs)
+ {
+ switch (attr.name)
+ {
+ case XML_name:
+ mp_cell_style->set_name(attr.value);
+ break;
+ case XML_xfId:
+ {
+ size_t n = to_long(attr.value);
+ mp_cell_style->set_xf(n);
+ break;
+ }
+ case XML_builtinId:
+ {
+ size_t n = to_long(attr.value);
+ mp_cell_style->set_builtin(n);
+ }
+ break;
+ }
+ }
break;
}
case XML_xf:
@@ -1025,7 +1019,12 @@ bool xlsx_styles_context::end_element(xmlns_id_t ns, xml_token_t name)
mp_border = nullptr;
break;
case XML_cellStyle:
- mp_styles->commit_cell_style();
+ assert(mp_cell_style);
+ mp_cell_style->commit();
+ break;
+ case XML_cellStyles:
+ assert(mp_cell_style);
+ mp_cell_style = nullptr;
break;
case XML_cellStyleXfs:
case XML_cellXfs:
diff --git a/src/liborcus/xlsx_context.hpp b/src/liborcus/xlsx_context.hpp
index 75c56a4b..fb796aea 100644
--- a/src/liborcus/xlsx_context.hpp
+++ b/src/liborcus/xlsx_context.hpp
@@ -27,6 +27,7 @@ namespace spreadsheet { namespace iface {
class import_cell_protection;
class import_number_format;
class import_xf;
+ class import_cell_style;
}}
/**
@@ -88,6 +89,7 @@ private:
spreadsheet::iface::import_cell_protection* mp_protection = nullptr;
spreadsheet::iface::import_number_format* mp_numfmt = nullptr;
spreadsheet::iface::import_xf* mp_xf = nullptr;
+ spreadsheet::iface::import_cell_style* mp_cell_style = nullptr;
string_pool m_pool;
bool m_diagonal_up;