From 720edc143fb80484928883ed475bdf403d5a2621 Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Tue, 26 Apr 2016 13:09:17 -0400 Subject: [PATCH] allow duplicate shared strings (why excel?). eventually we should do a garbage collection step that deduplicates shared strings after the workbook is loaded --- include/xlnt/workbook/workbook.hpp | 2 +- source/serialization/excel_serializer.cpp | 2 +- source/workbook/workbook.cpp | 15 +++++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/xlnt/workbook/workbook.hpp b/include/xlnt/workbook/workbook.hpp index 857ebe68..c8d05119 100644 --- a/include/xlnt/workbook/workbook.hpp +++ b/include/xlnt/workbook/workbook.hpp @@ -233,7 +233,7 @@ public: const std::vector &get_root_relationships() const; - void add_shared_string(const std::string &shared); + void add_shared_string(const std::string &shared, bool allow_duplicates=false); std::vector &get_shared_strings(); const std::vector &get_shared_strings() const; diff --git a/source/serialization/excel_serializer.cpp b/source/serialization/excel_serializer.cpp index 8f669299..694bc121 100644 --- a/source/serialization/excel_serializer.cpp +++ b/source/serialization/excel_serializer.cpp @@ -130,7 +130,7 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl for (auto shared_string : shared_strings) { - wb.add_shared_string(shared_string); + wb.add_shared_string(shared_string, true); } } diff --git a/source/workbook/workbook.cpp b/source/workbook/workbook.cpp index 6b1e3359..61fbfe1d 100644 --- a/source/workbook/workbook.cpp +++ b/source/workbook/workbook.cpp @@ -1184,13 +1184,16 @@ const std::vector &workbook::get_shared_strings() const return d_->shared_strings_; } -void workbook::add_shared_string(const std::string &shared) +void workbook::add_shared_string(const std::string &shared, bool allow_duplicates) { - //TODO: inefficient, use a set or something? - for(auto &s : d_->shared_strings_) - { - if(s == shared) return; - } + if (!allow_duplicates) + { + //TODO: inefficient, use a set or something? + for (auto &s : d_->shared_strings_) + { + if (s == shared) return; + } + } d_->shared_strings_.push_back(shared); }