From 00fd83297256ccb29c08827c593c17416faf499f Mon Sep 17 00:00:00 2001 From: guoxuan Date: Mon, 20 Mar 2023 17:05:42 +0800 Subject: [PATCH] =?UTF-8?q?fix=20exception=20"sizes=20don=E2=80=99t=20matc?= =?UTF-8?q?h"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit for more detail https://blog.csdn.net/baidu_30570701/article/details/89437242 --- include/xlnt/cell/rich_text.hpp | 3 +++ source/cell/rich_text.cpp | 4 +++- source/detail/serialization/xlsx_consumer.cpp | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/xlnt/cell/rich_text.hpp b/include/xlnt/cell/rich_text.hpp index 1634ce12..37f17025 100644 --- a/include/xlnt/cell/rich_text.hpp +++ b/include/xlnt/cell/rich_text.hpp @@ -151,6 +151,8 @@ public: /// bool operator!=(const std::string &rhs) const; + std::size_t unique_index{0}; + private: /// /// The runs that make up this rich text. @@ -171,6 +173,7 @@ public: { res ^= std::hash()(r.first); } + res ^= std::hash()(std::to_string(k.unique_index)); return res; } diff --git a/source/cell/rich_text.cpp b/source/cell/rich_text.cpp index 1db754de..952bb68c 100644 --- a/source/cell/rich_text.cpp +++ b/source/cell/rich_text.cpp @@ -56,6 +56,7 @@ rich_text &rich_text::operator=(const rich_text &rhs) runs_ = rhs.runs_; phonetic_runs_ = rhs.phonetic_runs_; phonetic_properties_ = rhs.phonetic_properties_; + unique_index = rhs.unique_index; return *this; } @@ -69,6 +70,7 @@ void rich_text::clear() runs_.clear(); phonetic_runs_.clear(); phonetic_properties_.clear(); + unique_index = 0; } void rich_text::plain_text(const std::string &s, bool preserve_space = false) @@ -151,7 +153,7 @@ bool rich_text::operator==(const rich_text &rhs) const if (phonetic_properties_ != rhs.phonetic_properties_) return false; - return true; + return unique_index == rhs.unique_index; } bool rich_text::operator==(const std::string &rhs) const diff --git a/source/detail/serialization/xlsx_consumer.cpp b/source/detail/serialization/xlsx_consumer.cpp index dc50106c..2d41a90b 100644 --- a/source/detail/serialization/xlsx_consumer.cpp +++ b/source/detail/serialization/xlsx_consumer.cpp @@ -2270,10 +2270,12 @@ void xlsx_consumer::read_shared_string_table() unique_count = parser().attribute("uniqueCount"); } + size_t unique_index = 0; while (in_element(qn("spreadsheetml", "sst"))) { expect_start_element(qn("spreadsheetml", "si"), xml::content::complex); auto rt = read_rich_text(qn("spreadsheetml", "si")); + rt.unique_index = unique_index++; target_.add_shared_string(rt, true); expect_end_element(qn("spreadsheetml", "si")); }