From 49663bc483f424f26ffa18f8bfb2dba86395c699 Mon Sep 17 00:00:00 2001 From: Johann1994 <37308757+Johann1994@users.noreply.github.com> Date: Wed, 18 Dec 2019 13:50:34 +0100 Subject: [PATCH 1/2] Sharedstringtable Same strings in shared stringtable makes it not possible to open a xlsx file. --- source/workbook/workbook.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/source/workbook/workbook.cpp b/source/workbook/workbook.cpp index fcea0b12..59f9a8af 100644 --- a/source/workbook/workbook.cpp +++ b/source/workbook/workbook.cpp @@ -1374,9 +1374,18 @@ std::size_t workbook::add_shared_string(const rich_text &shared, bool allow_dupl } } - auto sz = d_->shared_strings_ids_.size(); - d_->shared_strings_ids_[shared] = sz; + //it can happen that similar strings are more then onetime in the shared stringtable (Excel bugfix?) + //shared_strings_values map should start on position 0 + auto sz = d_->shared_strings_values_.size(); + if (d_->shared_strings_values_.count(sz) > 0) + { + // something went wrong! + throw invalid_file("Error in shared string table!"); + } + d_->shared_strings_values_[sz] = shared; + d_->shared_strings_ids_[shared] = sz; + return sz; } From d6262df55583bd88f7bb402a01685a6dd5b1744e Mon Sep 17 00:00:00 2001 From: Johann1994 <37308757+Johann1994@users.noreply.github.com> Date: Wed, 18 Dec 2019 13:53:23 +0100 Subject: [PATCH 2/2] Shared strings It can happen that some strings are not unique in sharedstring table --- source/detail/serialization/xlsx_consumer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/detail/serialization/xlsx_consumer.cpp b/source/detail/serialization/xlsx_consumer.cpp index 2f29e19f..3fdbad1b 100644 --- a/source/detail/serialization/xlsx_consumer.cpp +++ b/source/detail/serialization/xlsx_consumer.cpp @@ -1923,13 +1923,15 @@ void xlsx_consumer::read_shared_string_table() { expect_start_element(qn("spreadsheetml", "si"), xml::content::complex); auto rt = read_rich_text(qn("spreadsheetml", "si")); - target_.add_shared_string(rt); + //by reading in it can happen we have similar strings from modified excel worksheets... + //so allow to add duplicates + target_.add_shared_string(rt, true); expect_end_element(qn("spreadsheetml", "si")); } expect_end_element(qn("spreadsheetml", "sst")); - if (has_unique_count && unique_count != target_.shared_strings().size()) + if (has_unique_count && unique_count != target_.shared_strings_by_id().size()) { throw invalid_file("sizes don't match"); }