From d81555dbaed3836e9e88147f5e16fadbf8504c56 Mon Sep 17 00:00:00 2001 From: Crzyrndm Date: Sun, 24 Jun 2018 10:13:27 +1200 Subject: [PATCH] Add "bestFit" column attribute serialisation --- include/xlnt/worksheet/column_properties.hpp | 6 ++++++ source/detail/serialization/xlsx_consumer.cpp | 4 ++++ source/detail/serialization/xlsx_producer.cpp | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/include/xlnt/worksheet/column_properties.hpp b/include/xlnt/worksheet/column_properties.hpp index 28ed1150..36a8d386 100644 --- a/include/xlnt/worksheet/column_properties.hpp +++ b/include/xlnt/worksheet/column_properties.hpp @@ -51,6 +51,12 @@ public: /// optional style; + /// + /// Is this column sized to fit its content as best it can + /// serialise if true + /// + bool best_fit = false; + /// /// If true, this column will be hidden /// diff --git a/source/detail/serialization/xlsx_consumer.cpp b/source/detail/serialization/xlsx_consumer.cpp index 3a7f5600..6ee209ac 100644 --- a/source/detail/serialization/xlsx_consumer.cpp +++ b/source/detail/serialization/xlsx_consumer.cpp @@ -588,6 +588,9 @@ std::string xlsx_consumer::read_worksheet_begin(const std::string &rel_id) ? is_true(parser().attribute("customWidth")) : false; auto hidden = parser().attribute_present("hidden") ? is_true(parser().attribute("hidden")) : false; + auto best_fit = parser().attribute_present("bestFit") + ? is_true(parser().attribute("bestFit")) + : false; expect_end_element(qn("spreadsheetml", "col")); @@ -607,6 +610,7 @@ std::string xlsx_consumer::read_worksheet_begin(const std::string &rel_id) props.hidden = hidden; props.custom_width = custom; + props.best_fit = best_fit; ws.add_column_properties(column, props); } } diff --git a/source/detail/serialization/xlsx_producer.cpp b/source/detail/serialization/xlsx_producer.cpp index a11ba74f..4333e9de 100644 --- a/source/detail/serialization/xlsx_producer.cpp +++ b/source/detail/serialization/xlsx_producer.cpp @@ -2362,6 +2362,11 @@ void xlsx_producer::write_worksheet(const relationship &rel) write_attribute("width", (props.width.get() * 7 + 5) / 7); } + if (props.best_fit) + { + write_attribute("bestFit", write_bool(true)); + } + if (props.style.is_set()) { write_attribute("style", props.style.get());