Skip to content

Commit

Permalink
Parse inlineStr values
Browse files Browse the repository at this point in the history
inlineStr XML structure is <c><is><t>. This was being parsed incorrectly
when streaming (because has_value wasn't being set to true) and when
reading the whole file (because the <t> was ignored).

[closes #445]
  • Loading branch information
adamhooper committed Feb 25, 2020
1 parent 0d1d85f commit ac18fc6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
13 changes: 11 additions & 2 deletions source/detail/serialization/xlsx_consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ Cell parse_cell(xlnt::row_t row_arg, xml::parser *parser)
if (level == 2)
{
// <v> -> numeric values
// <is> -> inline string
if (string_equal(parser->name(), "v") || string_equal(parser->name(), "is"))
// <is><t> -> inline string
if (string_equal(parser->name(), "v"))
{
c.value += std::move(parser->value());
}
Expand All @@ -283,6 +283,14 @@ Cell parse_cell(xlnt::row_t row_arg, xml::parser *parser)
c.formula_string += std::move(parser->value());
}
}
else if (level == 3)
{
// <is><t> -> inline string
if (string_equal(parser->name(), "t"))
{
c.value += std::move(parser->value());
}
}
break;
}
case xml::parser::start_namespace_decl:
Expand Down Expand Up @@ -561,6 +569,7 @@ cell xlsx_consumer::read_cell()
else if (current_element == qn("spreadsheetml", "is")) // CT_Rst
{
expect_start_element(qn("spreadsheetml", "t"), xml::content::simple);
has_value = true;
value_string = read_text();
expect_end_element(qn("spreadsheetml", "t"));
}
Expand Down
Binary file added tests/data/Issue445_inline_str.xlsx
Binary file not shown.
20 changes: 20 additions & 0 deletions tests/workbook/serialization_test_suite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class serialization_test_suite : public test_suite
register_test(test_streaming_read);
register_test(test_streaming_write);
register_test(test_load_save_german_locale);
register_test(test_Issue445_inline_str_load);
register_test(test_Issue445_inline_str_streaming_read);
}

bool workbook_matches_file(xlnt::workbook &wb, const xlnt::path &file)
Expand Down Expand Up @@ -716,5 +718,23 @@ class serialization_test_suite : public test_suite
test_round_trip_rw_custom_heights_widths();
std::locale::global(current);*/
}

void test_Issue445_inline_str_load()
{
xlnt::workbook wb;
wb.load(path_helper::test_file("Issue445_inline_str.xlsx"));
auto ws = wb.active_sheet();
auto cell = ws.cell("A1");
xlnt_assert_equals(cell.value<std::string>(), std::string("a"));
}

void test_Issue445_inline_str_streaming_read()
{
xlnt::streaming_workbook_reader wbr;
wbr.open(path_helper::test_file("Issue445_inline_str.xlsx"));
wbr.begin_worksheet("Sheet");
auto cell = wbr.read_cell();
xlnt_assert_equals(cell.value<std::string>(), std::string("a"));
}
};
static serialization_test_suite x;

0 comments on commit ac18fc6

Please sign in to comment.