Merge pull request #428 from Johann1994/master

sharedstring table #427
This commit is contained in:
Thomas Fussell 2021-01-02 14:46:16 -05:00 committed by GitHub
commit 51406e4755
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -2091,13 +2091,15 @@ void xlsx_consumer::read_shared_string_table()
{ {
expect_start_element(qn("spreadsheetml", "si"), xml::content::complex); expect_start_element(qn("spreadsheetml", "si"), xml::content::complex);
auto rt = read_rich_text(qn("spreadsheetml", "si")); 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", "si"));
} }
expect_end_element(qn("spreadsheetml", "sst")); 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"); throw invalid_file("sizes don't match");
} }

View File

@ -1390,9 +1390,18 @@ std::size_t workbook::add_shared_string(const rich_text &shared, bool allow_dupl
} }
} }
auto sz = d_->shared_strings_ids_.size(); //it can happen that similar strings are more then onetime in the shared stringtable (Excel bugfix?)
d_->shared_strings_ids_[shared] = sz; //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_values_[sz] = shared;
d_->shared_strings_ids_[shared] = sz;
return sz; return sz;
} }