fix using attribute<double> (causes bugs when '.' is not the decimal separator

This commit is contained in:
JCrawfy 2019-11-18 20:46:34 +13:00
parent 7621b2807a
commit a25187f788
2 changed files with 12 additions and 13 deletions

View File

@ -598,8 +598,6 @@ cell xlsx_consumer::read_cell()
cell.formula(formula_value_string); cell.formula(formula_value_string);
} }
number_converter converter;
if (has_value) if (has_value)
{ {
if (type == "str") if (type == "str")
@ -614,7 +612,7 @@ cell xlsx_consumer::read_cell()
} }
else if (type == "s") else if (type == "s")
{ {
cell.d_->value_numeric_ = converter.stold(value_string); cell.d_->value_numeric_ = converter_.stold(value_string);
cell.data_type(cell::type::shared_string); cell.data_type(cell::type::shared_string);
} }
else if (type == "b") // boolean else if (type == "b") // boolean
@ -623,7 +621,7 @@ cell xlsx_consumer::read_cell()
} }
else if (type == "n") // numeric else if (type == "n") // numeric
{ {
cell.value(converter.stold(value_string)); cell.value(converter_.stold(value_string));
} }
else if (!value_string.empty() && value_string[0] == '#') else if (!value_string.empty() && value_string[0] == '#')
{ {
@ -974,8 +972,7 @@ void xlsx_consumer::read_worksheet_sheetdata()
{ {
return; return;
} }
number_converter converter; Sheet_Data ws_data = parse_sheet_data(parser_, converter_);
Sheet_Data ws_data = parse_sheet_data(parser_, converter);
// NOTE: parse->construct are seperated here and could easily be threaded // NOTE: parse->construct are seperated here and could easily be threaded
// with a SPSC queue for what is likely to be an easy performance win // with a SPSC queue for what is likely to be an easy performance win
for (auto &row : ws_data.parsed_rows) for (auto &row : ws_data.parsed_rows)
@ -1013,7 +1010,7 @@ void xlsx_consumer::read_worksheet_sheetdata()
} }
case cell::type::number: case cell::type::number:
{ {
ws_cell_impl->value_numeric_ = converter.stold(cell.value); ws_cell_impl->value_numeric_ = converter_.stold(cell.value);
break; break;
} }
case cell::type::shared_string: case cell::type::shared_string:
@ -1213,12 +1210,12 @@ worksheet xlsx_consumer::read_worksheet_end(const std::string &rel_id)
{ {
page_margins margins; page_margins margins;
margins.top(parser().attribute<double>("top")); margins.top(converter_.stold(parser().attribute("top")));
margins.bottom(parser().attribute<double>("bottom")); margins.bottom(converter_.stold(parser().attribute("bottom")));
margins.left(parser().attribute<double>("left")); margins.left(converter_.stold(parser().attribute("left")));
margins.right(parser().attribute<double>("right")); margins.right(converter_.stold(parser().attribute("right")));
margins.header(parser().attribute<double>("header")); margins.header(converter_.stold(parser().attribute("header")));
margins.footer(parser().attribute<double>("footer")); margins.footer(converter_.stold(parser().attribute("footer")));
ws.page_margins(margins); ws.page_margins(margins);
} }

View File

@ -34,6 +34,7 @@
#include <detail/external/include_libstudxml.hpp> #include <detail/external/include_libstudxml.hpp>
#include <detail/serialization/zstream.hpp> #include <detail/serialization/zstream.hpp>
#include <xlnt/utils/numeric.hpp>
namespace xlnt { namespace xlnt {
@ -409,6 +410,7 @@ private:
detail::cell_impl *current_cell_; detail::cell_impl *current_cell_;
detail::worksheet_impl *current_worksheet_; detail::worksheet_impl *current_worksheet_;
number_converter converter_;
}; };
} // namespace detail } // namespace detail