diff --git a/include/xlnt/worksheet/page_setup.hpp b/include/xlnt/worksheet/page_setup.hpp index 6fc1761e..7b57297f 100644 --- a/include/xlnt/worksheet/page_setup.hpp +++ b/include/xlnt/worksheet/page_setup.hpp @@ -119,6 +119,11 @@ public: /// void paper_size(xlnt::paper_size paper_size); + /// + /// Check if current paper setting has paper size setting + /// + bool has_paper_size() const; + /// /// Returns true if this worksheet should be scaled to fit on a single page during printing. /// @@ -159,6 +164,26 @@ public: /// double scale() const; + /// + /// Check if current paper setting has scale setting + /// + bool has_scale() const; + + /// + /// Gets reference relationship Id + /// + const std::string& rel_id() const; + + /// + /// Sets reference relationship Id + /// + void rel_id(const std::string& val); + + /// + /// Check if current paper setting has a reference relationship + /// + bool has_rel_id() const; + /// /// The orientation /// @@ -175,6 +200,11 @@ public: bool operator==(const page_setup &rhs) const; private: + /// + /// Relationship Id + /// + std::string rel_id_; + /// /// The break /// @@ -188,7 +218,7 @@ private: /// /// The paper size /// - xlnt::paper_size paper_size_; + xlnt::optional paper_size_; /// /// Whether or not to fit to page @@ -208,7 +238,7 @@ private: /// /// The amount to scale the worksheet /// - double scale_; + xlnt::optional scale_; }; } // namespace xlnt diff --git a/source/detail/serialization/xlsx_consumer.cpp b/source/detail/serialization/xlsx_consumer.cpp index b3fe56c2..99249114 100644 --- a/source/detail/serialization/xlsx_consumer.cpp +++ b/source/detail/serialization/xlsx_consumer.cpp @@ -955,19 +955,19 @@ worksheet xlsx_consumer::read_worksheet_end(const std::string &rel_id) } if (parser().attribute_present("gridLinesSet")) { - opts.print_grid_lines.set(parser().attribute("gridLinesSet")); + opts.grid_lines_set.set(parser().attribute("gridLinesSet")); } if (parser().attribute_present("headings")) { - opts.print_grid_lines.set(parser().attribute("headings")); + opts.print_headings.set(parser().attribute("headings")); } if (parser().attribute_present("horizontalCentered")) { - opts.print_grid_lines.set(parser().attribute("horizontalCentered")); + opts.horizontal_centered.set(parser().attribute("horizontalCentered")); } if (parser().attribute_present("verticalCentered")) { - opts.print_grid_lines.set(parser().attribute("verticalCentered")); + opts.vertical_centered.set(parser().attribute("verticalCentered")); } ws.d_->print_options_.set(opts); skip_remaining_content(current_worksheet_element); @@ -1000,6 +1000,18 @@ worksheet xlsx_consumer::read_worksheet_end(const std::string &rel_id) { setup.vertical_dpi_.set(parser().attribute("verticalDpi")); } + if (parser().attribute_present("paperSize")) + { + setup.paper_size(static_cast(parser().attribute("paperSize"))); + } + if (parser().attribute_present("scale")) + { + setup.scale(parser().attribute("scale")); + } + if (parser().attribute_present(qn("r", "id"))) + { + setup.rel_id(parser().attribute(qn("r", "id"))); + } ws.page_setup(setup); skip_remaining_content(current_worksheet_element); } diff --git a/source/detail/serialization/xlsx_producer.cpp b/source/detail/serialization/xlsx_producer.cpp index 12b363ed..c96c5817 100644 --- a/source/detail/serialization/xlsx_producer.cpp +++ b/source/detail/serialization/xlsx_producer.cpp @@ -2782,6 +2782,22 @@ void xlsx_producer::write_worksheet(const relationship &rel) write_end_element(xmlns, "hyperlinks"); } + if (ws.has_phonetic_properties()) + { + write_start_element(xmlns, phonetic_pr::Serialised_ID()); + const auto &ph_props = ws.phonetic_properties(); + write_attribute("fontId", ph_props.font_id()); + if (ph_props.has_type()) + { + write_attribute("type", phonetic_pr::type_as_string(ph_props.type())); + } + if (ph_props.has_alignment()) + { + write_attribute("alignment", phonetic_pr::alignment_as_string(ph_props.alignment())); + } + write_end_element(xmlns, phonetic_pr::Serialised_ID()); + } + if (ws.d_->print_options_.is_set()) { auto &opts = ws.d_->print_options_.get(); @@ -2809,22 +2825,6 @@ void xlsx_producer::write_worksheet(const relationship &rel) write_end_element(xmlns, "printOptions"); } - if (ws.has_phonetic_properties()) - { - write_start_element(xmlns, phonetic_pr::Serialised_ID()); - const auto &ph_props = ws.phonetic_properties(); - write_attribute("fontId", ph_props.font_id()); - if (ph_props.has_type()) - { - write_attribute("type", phonetic_pr::type_as_string(ph_props.type())); - } - if (ph_props.has_alignment()) - { - write_attribute("alignment", phonetic_pr::alignment_as_string(ph_props.alignment())); - } - write_end_element(xmlns, phonetic_pr::Serialised_ID()); - } - if (ws.has_page_margins()) { write_start_element(xmlns, "pageMargins"); @@ -2841,6 +2841,7 @@ void xlsx_producer::write_worksheet(const relationship &rel) if (ws.has_page_setup()) { + const xlnt::page_setup &ps = ws.page_setup(); write_start_element(xmlns, "pageSetup"); if (ws.page_setup().orientation_.is_set()) { @@ -2854,8 +2855,22 @@ void xlsx_producer::write_worksheet(const relationship &rel) { write_attribute("verticalDpi", ws.page_setup().vertical_dpi_.get()); } - /*write_attribute("paperSize", static_cast(ws.page_setup().paper_size())); - write_attribute("fitToHeight", write_bool(ws.page_setup().fit_to_height())); + + if (ps.has_paper_size()) + { + write_attribute("paperSize", static_cast(ps.paper_size())); + } + + if (ps.has_scale()) + { + write_attribute("scale", ps.scale()); + } + + if (ps.has_rel_id()) + { + write_attribute(xml::qname(xmlns_r, "id"), ps.rel_id()); + } + /*write_attribute("fitToHeight", write_bool(ws.page_setup().fit_to_height())); write_attribute("fitToWidth", write_bool(ws.page_setup().fit_to_width()));*/ write_end_element(xmlns, "pageSetup"); } diff --git a/source/worksheet/page_setup.cpp b/source/worksheet/page_setup.cpp index 19767e2f..747abf5e 100644 --- a/source/worksheet/page_setup.cpp +++ b/source/worksheet/page_setup.cpp @@ -59,7 +59,7 @@ void page_setup::sheet_state(xlnt::sheet_state sheet_state) paper_size page_setup::paper_size() const { - return paper_size_; + return paper_size_.get(); } void page_setup::paper_size(xlnt::paper_size paper_size) @@ -67,6 +67,11 @@ void page_setup::paper_size(xlnt::paper_size paper_size) paper_size_ = paper_size; } +bool page_setup::has_paper_size() const +{ + return this->paper_size_.is_set(); +} + bool page_setup::fit_to_page() const { return fit_to_page_; @@ -104,7 +109,27 @@ void page_setup::scale(double scale) double page_setup::scale() const { - return scale_; + return scale_.get(); +} + +bool page_setup::has_scale() const +{ + return this->scale_.is_set(); +} + +const std::string& page_setup::rel_id() const +{ + return this->rel_id_; +} + +void page_setup::rel_id(const std::string& val) +{ + this->rel_id_ = val; +} + +bool page_setup::has_rel_id() const +{ + return !rel_id_.empty(); } bool page_setup::operator==(const page_setup &rhs) const @@ -115,7 +140,9 @@ bool page_setup::operator==(const page_setup &rhs) const && fit_to_page_ == rhs.fit_to_page_ && fit_to_height_ == rhs.fit_to_height_ && fit_to_width_ == rhs.fit_to_width_ - && detail::float_equals(scale_, rhs.scale_); + && scale_ == rhs.scale_ + && paper_size_ == rhs.paper_size_ + && rel_id_ == rhs.rel_id_; } } // namespace xlnt