From 4a3e711a1bca7d1c5067d57768f1897b83386b60 Mon Sep 17 00:00:00 2001 From: sukoi26 Date: Sat, 4 Nov 2017 18:12:38 +0100 Subject: [PATCH 1/3] bug introduce by the commit continue work on #230, improves style/xf handling as the style exist it is rewritten in cellStyleXfs and cellXfs, with the fillId test for format and style. remove the test and use only the format. --- source/detail/serialization/xlsx_producer.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/source/detail/serialization/xlsx_producer.cpp b/source/detail/serialization/xlsx_producer.cpp index 5491ccb6..5bfa6aa1 100644 --- a/source/detail/serialization/xlsx_producer.cpp +++ b/source/detail/serialization/xlsx_producer.cpp @@ -1321,14 +1321,7 @@ void xlsx_producer::write_styles(const relationship & /*rel*/) write_attribute("numFmtId", current_format_impl.number_format_id.get()); write_attribute("fontId", current_format_impl.font_id.get()); - if (current_format_impl.style.is_set()) - { - write_attribute("fillId", stylesheet.style_impls.at(current_format_impl.style.get()).fill_id.get()); - } - else - { - write_attribute("fillId", current_format_impl.fill_id.get()); - } + write_attribute("fillId", current_format_impl.fill_id.get()); write_attribute("borderId", current_format_impl.border_id.get()); From caeadfc83c3af2017b076ea21e410d00c32f11dc Mon Sep 17 00:00:00 2001 From: sukoi26 Date: Sat, 4 Nov 2017 23:41:48 +0100 Subject: [PATCH 2/3] optimize code empty row cell --- source/detail/serialization/xlsx_producer.cpp | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/source/detail/serialization/xlsx_producer.cpp b/source/detail/serialization/xlsx_producer.cpp index 5bfa6aa1..4404435e 100644 --- a/source/detail/serialization/xlsx_producer.cpp +++ b/source/detail/serialization/xlsx_producer.cpp @@ -2000,7 +2000,7 @@ void xlsx_producer::write_worksheet(const relationship &rel) })->first; auto ws = source_.sheet_by_title(title); - + write_start_element(xmlns, "worksheet"); write_namespace(xmlns, ""); write_namespace(xmlns_r, "r"); @@ -2103,24 +2103,19 @@ void xlsx_producer::write_worksheet(const relationship &rel) write_end_element(xmlns, "sheetFormatPr"); bool has_column_properties = false; + // + auto wslowestcp = ws.lowest_column_or_props(); + auto wshighestcp = ws.highest_column_or_props(); - for (auto column = ws.lowest_column(); column <= ws.highest_column(); column++) - { - if (ws.has_column_properties(column)) - { - has_column_properties = true; - break; - } - } - - if (has_column_properties) - { - write_start_element(xmlns, "cols"); - - for (auto column = ws.lowest_column_or_props(); column <= ws.highest_column_or_props(); column++) + for (auto column = wslowestcp; column <= wshighestcp; column++) { if (!ws.has_column_properties(column)) continue; - + + if(!has_column_properties) + { + write_start_element(xmlns, "cols"); + has_column_properties = true; + } const auto &props = ws.column_properties(column); write_start_element(xmlns, "col"); @@ -2151,7 +2146,6 @@ void xlsx_producer::write_worksheet(const relationship &rel) } write_end_element(xmlns, "cols"); - } const auto hyperlink_rels = source_.manifest().relationships(worksheet_part, relationship_type::hyperlink); std::unordered_map reverse_hyperlink_references; @@ -2165,8 +2159,11 @@ void xlsx_producer::write_worksheet(const relationship &rel) std::vector cells_with_comments; write_start_element(xmlns, "sheetData"); + // optimize + auto wslowestrp = ws.lowest_row_or_props(); + auto wshighestrp = ws.highest_row_or_props(); - for (auto row = ws.lowest_row_or_props(); row <= ws.highest_row_or_props(); ++row) + for (auto row = wslowestrp; row <= wshighestrp; ++row) { auto first_column = constants::max_column(); auto last_column = constants::min_column(); From 4f07495abb121e7d26c196d861ae341505404637 Mon Sep 17 00:00:00 2001 From: sukoi26 Date: Mon, 6 Nov 2017 14:12:08 +0100 Subject: [PATCH 3/3] optimize latest commit missing a test --- source/detail/serialization/xlsx_producer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/detail/serialization/xlsx_producer.cpp b/source/detail/serialization/xlsx_producer.cpp index 4404435e..ba7018e7 100644 --- a/source/detail/serialization/xlsx_producer.cpp +++ b/source/detail/serialization/xlsx_producer.cpp @@ -2145,7 +2145,7 @@ void xlsx_producer::write_worksheet(const relationship &rel) write_end_element(xmlns, "col"); } - write_end_element(xmlns, "cols"); + if(has_column_properties) write_end_element(xmlns, "cols"); const auto hyperlink_rels = source_.manifest().relationships(worksheet_part, relationship_type::hyperlink); std::unordered_map reverse_hyperlink_references;