mirror of https://github.com/tfussell/xlnt
use the new faster serialisation everywhere in xlsx_producer
parent
ee593c2673
commit
39f498f401
|
@ -27,7 +27,7 @@
|
|||
namespace xlnt {
|
||||
namespace detail {
|
||||
|
||||
std::array<xlnt::optional<xlnt::rich_text>, 3> decode_header_footer(const std::string &hf_string)
|
||||
std::array<xlnt::optional<xlnt::rich_text>, 3> decode_header_footer(const std::string &hf_string, const number_serialiser &serialiser)
|
||||
{
|
||||
std::array<xlnt::optional<xlnt::rich_text>, 3> result;
|
||||
|
||||
|
@ -216,7 +216,7 @@ std::array<xlnt::optional<xlnt::rich_text>, 3> decode_header_footer(const std::s
|
|||
tokens.push_back(token);
|
||||
}
|
||||
|
||||
const auto parse_section = [&tokens, &result](hf_code code) {
|
||||
const auto parse_section = [&tokens, &result, &serialiser](hf_code code) {
|
||||
std::vector<hf_code> end_codes{hf_code::left_section, hf_code::center_section, hf_code::right_section};
|
||||
end_codes.erase(std::find(end_codes.begin(), end_codes.end(), code));
|
||||
|
||||
|
@ -297,7 +297,7 @@ std::array<xlnt::optional<xlnt::rich_text>, 3> decode_header_footer(const std::s
|
|||
current_run.second = xlnt::font();
|
||||
}
|
||||
|
||||
current_run.second.get().size(std::stod(current_token.value));
|
||||
current_run.second.get().size(serialiser.deserialise(current_token.value));
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -460,7 +460,7 @@ std::array<xlnt::optional<xlnt::rich_text>, 3> decode_header_footer(const std::s
|
|||
return result;
|
||||
}
|
||||
|
||||
std::string encode_header_footer(const rich_text &t, header_footer::location where)
|
||||
std::string encode_header_footer(const rich_text &t, header_footer::location where, const number_serialiser &serialiser)
|
||||
{
|
||||
const auto location_code_map =
|
||||
std::unordered_map<header_footer::location,
|
||||
|
@ -505,7 +505,7 @@ std::string encode_header_footer(const rich_text &t, header_footer::location whe
|
|||
if (run.second.get().has_size())
|
||||
{
|
||||
encoded.push_back('&');
|
||||
encoded.append(serialize_number_to_string(run.second.get().size()));
|
||||
encoded.append(serialiser.serialise(run.second.get().size()));
|
||||
}
|
||||
if (run.second.get().underlined())
|
||||
{
|
||||
|
|
|
@ -27,12 +27,13 @@
|
|||
#include <xlnt/cell/rich_text.hpp>
|
||||
#include <xlnt/utils/optional.hpp>
|
||||
#include <xlnt/worksheet/header_footer.hpp>
|
||||
#include <xlnt/utils/numeric.hpp>
|
||||
|
||||
namespace xlnt {
|
||||
namespace detail {
|
||||
|
||||
std::array<xlnt::optional<xlnt::rich_text>, 3> decode_header_footer(const std::string &hf_string);
|
||||
std::string encode_header_footer(const rich_text &t, header_footer::location where);
|
||||
std::array<xlnt::optional<xlnt::rich_text>, 3> decode_header_footer(const std::string &hf_string, const number_serialiser &serialiser);
|
||||
std::string encode_header_footer(const rich_text &t, header_footer::location where, const number_serialiser& serialiser);
|
||||
|
||||
} // namespace detail
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -307,14 +307,14 @@ Cell parse_cell(xlnt::row_t row_arg, xml::parser *parser)
|
|||
}
|
||||
|
||||
// <row> inside <sheetData> element
|
||||
std::pair<xlnt::row_properties, int> parse_row(xml::parser *parser, xlnt::detail::number_converter &converter, std::vector<Cell> &parsed_cells)
|
||||
std::pair<xlnt::row_properties, int> parse_row(xml::parser *parser, xlnt::detail::number_serialiser &converter, std::vector<Cell> &parsed_cells)
|
||||
{
|
||||
std::pair<xlnt::row_properties, int> props;
|
||||
for (auto &attr : parser->attribute_map())
|
||||
{
|
||||
if (string_equal(attr.first.name(), "dyDescent"))
|
||||
{
|
||||
props.first.dy_descent = converter.stold(attr.second.value);
|
||||
props.first.dy_descent = converter.deserialise(attr.second.value);
|
||||
}
|
||||
else if (string_equal(attr.first.name(), "spans"))
|
||||
{
|
||||
|
@ -322,7 +322,7 @@ std::pair<xlnt::row_properties, int> parse_row(xml::parser *parser, xlnt::detail
|
|||
}
|
||||
else if (string_equal(attr.first.name(), "ht"))
|
||||
{
|
||||
props.first.height = converter.stold(attr.second.value);
|
||||
props.first.height = converter.deserialise(attr.second.value);
|
||||
}
|
||||
else if (string_equal(attr.first.name(), "s"))
|
||||
{
|
||||
|
@ -382,7 +382,7 @@ std::pair<xlnt::row_properties, int> parse_row(xml::parser *parser, xlnt::detail
|
|||
}
|
||||
|
||||
// <sheetData> inside <worksheet> element
|
||||
Sheet_Data parse_sheet_data(xml::parser *parser, xlnt::detail::number_converter &converter)
|
||||
Sheet_Data parse_sheet_data(xml::parser *parser, xlnt::detail::number_serialiser &converter)
|
||||
{
|
||||
Sheet_Data sheet_data;
|
||||
int level = 1; // nesting level
|
||||
|
@ -480,7 +480,7 @@ cell xlsx_consumer::read_cell()
|
|||
|
||||
if (parser().attribute_present("ht"))
|
||||
{
|
||||
row_properties.height = converter_.stold(parser().attribute("ht"));
|
||||
row_properties.height = converter_.deserialise(parser().attribute("ht"));
|
||||
}
|
||||
|
||||
if (parser().attribute_present("customHeight"))
|
||||
|
@ -495,7 +495,7 @@ cell xlsx_consumer::read_cell()
|
|||
|
||||
if (parser().attribute_present(qn("x14ac", "dyDescent")))
|
||||
{
|
||||
row_properties.dy_descent = converter_.stold(parser().attribute(qn("x14ac", "dyDescent")));
|
||||
row_properties.dy_descent = converter_.deserialise(parser().attribute(qn("x14ac", "dyDescent")));
|
||||
}
|
||||
|
||||
if (parser().attribute_present("spans"))
|
||||
|
@ -602,7 +602,7 @@ cell xlsx_consumer::read_cell()
|
|||
}
|
||||
else if (type == "s")
|
||||
{
|
||||
cell.d_->value_numeric_ = converter_.stold(value_string);
|
||||
cell.d_->value_numeric_ = converter_.deserialise(value_string);
|
||||
cell.data_type(cell::type::shared_string);
|
||||
}
|
||||
else if (type == "b") // boolean
|
||||
|
@ -611,7 +611,7 @@ cell xlsx_consumer::read_cell()
|
|||
}
|
||||
else if (type == "n") // numeric
|
||||
{
|
||||
cell.value(converter_.stold(value_string));
|
||||
cell.value(converter_.deserialise(value_string));
|
||||
}
|
||||
else if (!value_string.empty() && value_string[0] == '#')
|
||||
{
|
||||
|
@ -863,23 +863,23 @@ std::string xlsx_consumer::read_worksheet_begin(const std::string &rel_id)
|
|||
if (parser().attribute_present("baseColWidth"))
|
||||
{
|
||||
ws.d_->format_properties_.base_col_width =
|
||||
converter_.stold(parser().attribute("baseColWidth"));
|
||||
converter_.deserialise(parser().attribute("baseColWidth"));
|
||||
}
|
||||
if (parser().attribute_present("defaultColWidth"))
|
||||
{
|
||||
ws.d_->format_properties_.default_column_width =
|
||||
converter_.stold(parser().attribute("defaultColWidth"));
|
||||
converter_.deserialise(parser().attribute("defaultColWidth"));
|
||||
}
|
||||
if (parser().attribute_present("defaultRowHeight"))
|
||||
{
|
||||
ws.d_->format_properties_.default_row_height =
|
||||
converter_.stold(parser().attribute("defaultRowHeight"));
|
||||
converter_.deserialise(parser().attribute("defaultRowHeight"));
|
||||
}
|
||||
|
||||
if (parser().attribute_present(qn("x14ac", "dyDescent")))
|
||||
{
|
||||
ws.d_->format_properties_.dy_descent =
|
||||
converter_.stold(parser().attribute(qn("x14ac", "dyDescent")));
|
||||
converter_.deserialise(parser().attribute(qn("x14ac", "dyDescent")));
|
||||
}
|
||||
|
||||
skip_attributes();
|
||||
|
@ -899,7 +899,7 @@ std::string xlsx_consumer::read_worksheet_begin(const std::string &rel_id)
|
|||
optional<double> width = [this](xml::parser &p) -> xlnt::optional<double> {
|
||||
if (p.attribute_present("width"))
|
||||
{
|
||||
return (converter_.stold(p.attribute("width")) * 7 - 5) / 7;
|
||||
return (converter_.deserialise(p.attribute("width")) * 7 - 5) / 7;
|
||||
}
|
||||
return xlnt::optional<double>();
|
||||
}(parser());
|
||||
|
@ -1000,7 +1000,7 @@ void xlsx_consumer::read_worksheet_sheetdata()
|
|||
case cell::type::empty:
|
||||
case cell::type::number:
|
||||
case cell::type::date: {
|
||||
ws_cell_impl->value_numeric_ = converter_.stold(cell.value);
|
||||
ws_cell_impl->value_numeric_ = converter_.deserialise(cell.value);
|
||||
break;
|
||||
}
|
||||
case cell::type::shared_string: {
|
||||
|
@ -1196,12 +1196,12 @@ worksheet xlsx_consumer::read_worksheet_end(const std::string &rel_id)
|
|||
{
|
||||
page_margins margins;
|
||||
|
||||
margins.top(converter_.stold(parser().attribute("top")));
|
||||
margins.bottom(converter_.stold(parser().attribute("bottom")));
|
||||
margins.left(converter_.stold(parser().attribute("left")));
|
||||
margins.right(converter_.stold(parser().attribute("right")));
|
||||
margins.header(converter_.stold(parser().attribute("header")));
|
||||
margins.footer(converter_.stold(parser().attribute("footer")));
|
||||
margins.top(converter_.deserialise(parser().attribute("top")));
|
||||
margins.bottom(converter_.deserialise(parser().attribute("bottom")));
|
||||
margins.left(converter_.deserialise(parser().attribute("left")));
|
||||
margins.right(converter_.deserialise(parser().attribute("right")));
|
||||
margins.header(converter_.deserialise(parser().attribute("header")));
|
||||
margins.footer(converter_.deserialise(parser().attribute("footer")));
|
||||
|
||||
ws.page_margins(margins);
|
||||
}
|
||||
|
@ -1251,27 +1251,27 @@ worksheet xlsx_consumer::read_worksheet_end(const std::string &rel_id)
|
|||
|
||||
if (current_hf_element == qn("spreadsheetml", "oddHeader"))
|
||||
{
|
||||
odd_header = decode_header_footer(read_text());
|
||||
odd_header = decode_header_footer(read_text(), converter_);
|
||||
}
|
||||
else if (current_hf_element == qn("spreadsheetml", "oddFooter"))
|
||||
{
|
||||
odd_footer = decode_header_footer(read_text());
|
||||
odd_footer = decode_header_footer(read_text(), converter_);
|
||||
}
|
||||
else if (current_hf_element == qn("spreadsheetml", "evenHeader"))
|
||||
{
|
||||
even_header = decode_header_footer(read_text());
|
||||
even_header = decode_header_footer(read_text(), converter_);
|
||||
}
|
||||
else if (current_hf_element == qn("spreadsheetml", "evenFooter"))
|
||||
{
|
||||
even_footer = decode_header_footer(read_text());
|
||||
even_footer = decode_header_footer(read_text(), converter_);
|
||||
}
|
||||
else if (current_hf_element == qn("spreadsheetml", "firstHeader"))
|
||||
{
|
||||
first_header = decode_header_footer(read_text());
|
||||
first_header = decode_header_footer(read_text(), converter_);
|
||||
}
|
||||
else if (current_hf_element == qn("spreadsheetml", "firstFooter"))
|
||||
{
|
||||
first_footer = decode_header_footer(read_text());
|
||||
first_footer = decode_header_footer(read_text(), converter_);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2308,7 +2308,7 @@ void xlsx_consumer::read_stylesheet()
|
|||
while (in_element(qn("spreadsheetml", "gradientFill")))
|
||||
{
|
||||
expect_start_element(qn("spreadsheetml", "stop"), xml::content::complex);
|
||||
auto position = converter_.stold(parser().attribute("position"));
|
||||
auto position = converter_.deserialise(parser().attribute("position"));
|
||||
expect_start_element(qn("spreadsheetml", "color"), xml::content::complex);
|
||||
auto color = read_color();
|
||||
expect_end_element(qn("spreadsheetml", "color"));
|
||||
|
@ -2356,7 +2356,7 @@ void xlsx_consumer::read_stylesheet()
|
|||
|
||||
if (font_property_element == qn("spreadsheetml", "sz"))
|
||||
{
|
||||
new_font.size(converter_.stold(parser().attribute("val")));
|
||||
new_font.size(converter_.deserialise(parser().attribute("val")));
|
||||
}
|
||||
else if (font_property_element == qn("spreadsheetml", "name"))
|
||||
{
|
||||
|
@ -3169,7 +3169,7 @@ rich_text xlsx_consumer::read_rich_text(const xml::qname &parent)
|
|||
|
||||
if (current_run_property_element == xml::qname(xmlns, "sz"))
|
||||
{
|
||||
run.second.get().size(converter_.stold(parser().attribute("val")));
|
||||
run.second.get().size(converter_.deserialise(parser().attribute("val")));
|
||||
}
|
||||
else if (current_run_property_element == xml::qname(xmlns, "rFont"))
|
||||
{
|
||||
|
@ -3307,7 +3307,7 @@ xlnt::color xlsx_consumer::read_color()
|
|||
|
||||
if (parser().attribute_present("tint"))
|
||||
{
|
||||
result.tint(converter_.stold(parser().attribute("tint")));
|
||||
result.tint(converter_.deserialise(parser().attribute("tint")));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -416,7 +416,7 @@ private:
|
|||
detail::cell_impl *current_cell_;
|
||||
|
||||
detail::worksheet_impl *current_worksheet_;
|
||||
number_converter converter_;
|
||||
number_serialiser converter_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
|
|
@ -2420,7 +2420,7 @@ void xlsx_producer::write_worksheet(const relationship &rel)
|
|||
if (props.width.is_set())
|
||||
{
|
||||
double width = (props.width.get() * 7 + 5) / 7;
|
||||
write_attribute("width", serialize_number_to_string(width));
|
||||
write_attribute("width", converter_.serialise(width));
|
||||
}
|
||||
|
||||
if (props.best_fit)
|
||||
|
@ -2522,7 +2522,7 @@ void xlsx_producer::write_worksheet(const relationship &rel)
|
|||
if (props.height.is_set())
|
||||
{
|
||||
auto height = props.height.get();
|
||||
write_attribute("ht", serialize_number_to_string(height));
|
||||
write_attribute("ht", converter_.serialise(height));
|
||||
}
|
||||
|
||||
if (props.hidden)
|
||||
|
@ -2649,7 +2649,7 @@ void xlsx_producer::write_worksheet(const relationship &rel)
|
|||
|
||||
case cell::type::number:
|
||||
write_start_element(xmlns, "v");
|
||||
write_characters(serialize_number_to_string(cell.value<double>()));
|
||||
write_characters(converter_.serialise(cell.value<double>()));
|
||||
write_end_element(xmlns, "v");
|
||||
break;
|
||||
|
||||
|
@ -2886,26 +2886,26 @@ void xlsx_producer::write_worksheet(const relationship &rel)
|
|||
{
|
||||
if (hf.has_odd_even_header(location))
|
||||
{
|
||||
odd_header.append(encode_header_footer(hf.odd_header(location), location));
|
||||
even_header.append(encode_header_footer(hf.even_header(location), location));
|
||||
odd_header.append(encode_header_footer(hf.odd_header(location), location, converter_));
|
||||
even_header.append(encode_header_footer(hf.even_header(location), location, converter_));
|
||||
}
|
||||
|
||||
if (hf.has_odd_even_footer(location))
|
||||
{
|
||||
odd_footer.append(encode_header_footer(hf.odd_footer(location), location));
|
||||
even_footer.append(encode_header_footer(hf.even_footer(location), location));
|
||||
odd_footer.append(encode_header_footer(hf.odd_footer(location), location, converter_));
|
||||
even_footer.append(encode_header_footer(hf.even_footer(location), location, converter_));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hf.has_header(location))
|
||||
{
|
||||
odd_header.append(encode_header_footer(hf.header(location), location));
|
||||
odd_header.append(encode_header_footer(hf.header(location), location, converter_));
|
||||
}
|
||||
|
||||
if (hf.has_footer(location))
|
||||
{
|
||||
odd_footer.append(encode_header_footer(hf.footer(location), location));
|
||||
odd_footer.append(encode_header_footer(hf.footer(location), location, converter_));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2913,12 +2913,12 @@ void xlsx_producer::write_worksheet(const relationship &rel)
|
|||
{
|
||||
if (hf.has_first_page_header(location))
|
||||
{
|
||||
first_header.append(encode_header_footer(hf.first_page_header(location), location));
|
||||
first_header.append(encode_header_footer(hf.first_page_header(location), location, converter_));
|
||||
}
|
||||
|
||||
if (hf.has_first_page_footer(location))
|
||||
{
|
||||
first_footer.append(encode_header_footer(hf.first_page_footer(location), location));
|
||||
first_footer.append(encode_header_footer(hf.first_page_footer(location), location, converter_));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3385,7 +3385,7 @@ void xlsx_producer::write_color(const xlnt::color &color)
|
|||
}
|
||||
if (color.has_tint())
|
||||
{
|
||||
write_attribute("tint", serialize_number_to_string(color.tint()));
|
||||
write_attribute("tint", converter_.serialise(color.tint()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include <detail/constants.hpp>
|
||||
#include <detail/external/include_libstudxml.hpp>
|
||||
#include <xlnt/utils/numeric.hpp>
|
||||
|
||||
namespace xml {
|
||||
class serializer;
|
||||
|
@ -208,6 +209,7 @@ private:
|
|||
detail::cell_impl *current_cell_;
|
||||
|
||||
detail::worksheet_impl *current_worksheet_;
|
||||
detail::number_serialiser converter_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
|
Loading…
Reference in New Issue