Serialisation of sheetPr and printOptions elements

This commit is contained in:
Crzyrndm 2018-06-24 14:01:27 +12:00
parent 93323f334d
commit d2d0c2ab55
8 changed files with 342 additions and 141 deletions

View File

@ -149,28 +149,6 @@ public:
/// </summary> /// </summary>
void fit_to_width(bool fit_to_width); void fit_to_width(bool fit_to_width);
/// <summary>
/// Sets whether the worksheet should be centered horizontall on the page if it takes
/// up less than a full page.
/// </summary>
void horizontal_centered(bool horizontal_centered);
/// <summary>
/// Returns whether horizontal centering has been enabled.
/// </summary>
bool horizontal_centered() const;
/// <summary>
/// Sets whether the worksheet should be vertically centered on the page if it takes
/// up less than a full page.
/// </summary>
void vertical_centered(bool vertical_centered);
/// <summary>
/// Returns whether vertical centering has been enabled.
/// </summary>
bool vertical_centered() const;
/// <summary> /// <summary>
/// Sets the factor by which the page should be scaled during printing. /// Sets the factor by which the page should be scaled during printing.
/// </summary> /// </summary>
@ -225,16 +203,6 @@ private:
/// </summary> /// </summary>
bool fit_to_width_; bool fit_to_width_;
/// <summary>
/// Whether or not to center the content horizontally
/// </summary>
bool horizontal_centered_;
/// <summary>
/// Whether or not to center the conent vertically
/// </summary>
bool vertical_centered_;
/// <summary> /// <summary>
/// The amount to scale the worksheet /// The amount to scale the worksheet
/// </summary> /// </summary>

View File

@ -0,0 +1,58 @@
// Copyright (c) 2014-2018 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <xlnt/xlnt_config.hpp>
#include <xlnt/utils/optional.hpp>
namespace xlnt {
struct print_options
{
/// <summary>
/// if both grid_lines_set and this are true, grid lines are printed
/// </summary>
optional<bool> print_grid_lines;
/// <summary>
/// if both print grid lines and this are true, grid lines are printed
/// </summary>
optional<bool> grid_lines_set;
/// <summary>
/// print row and column headings
/// </summary>
optional<bool> print_headings;
/// <summary>
/// center on page horizontally
/// </summary>
optional<bool> horizontal_centered;
/// <summary>
/// center on page vertically
/// </summary>
optional<bool> vertical_centered;
};
} // namespace xlnt

View File

@ -0,0 +1,81 @@
// Copyright (c) 2014-2018 Thomas Fussell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <string>
#include <xlnt/xlnt_config.hpp>
#include <xlnt/utils/optional.hpp>
#include <xlnt/cell/cell_reference.hpp>
namespace xlnt {
struct sheet_pr
{
/// <summary>
/// is horizontally synced to the anchor point
/// </summary>
optional<bool> sync_horizontal_;
/// <summary>
/// is vertically synced to the anchor point
/// </summary>
optional<bool> sync_vertical_;
/// <summary>
/// Anchor point for worksheet's window
/// </summary>
optional<cell_reference> sync_ref_;
/// <summary>
/// Lotus compatibility option
/// </summary>
optional<bool> transition_evaluation_;
/// <summary>
/// Lotus compatibility option
/// </summary>
optional<bool> transition_entry_;
/// <summary>
/// worksheet is published
/// </summary>
optional<bool> published_;
/// <summary>
/// stable name of the sheet
/// </summary>
optional<std::string> code_name_;
/// <summary>
/// worksheet has one or more autofilters or advanced filters on
/// </summary>
optional<bool> filter_mode;
/// <summary>
/// whether the conditional formatting calculations shall be evaluated
/// </summary>
optional<bool> enable_format_condition_calculation_;
};
} // namespace xlnt

View File

@ -37,6 +37,8 @@
#include <xlnt/worksheet/row_properties.hpp> #include <xlnt/worksheet/row_properties.hpp>
#include <xlnt/worksheet/sheet_format_properties.hpp> #include <xlnt/worksheet/sheet_format_properties.hpp>
#include <xlnt/worksheet/sheet_view.hpp> #include <xlnt/worksheet/sheet_view.hpp>
#include <xlnt/worksheet/print_options.hpp>
#include <xlnt/worksheet/sheet_pr.hpp>
#include <detail/implementations/cell_impl.hpp> #include <detail/implementations/cell_impl.hpp>
namespace xlnt { namespace xlnt {
@ -83,6 +85,8 @@ struct worksheet_impl
column_breaks_ = other.column_breaks_; column_breaks_ = other.column_breaks_;
row_breaks_ = other.row_breaks_; row_breaks_ = other.row_breaks_;
extension_list_ = other.extension_list_; extension_list_ = other.extension_list_;
sheet_properties_ = other.sheet_properties_;
print_options_ = other.print_options_;
for (auto &row : cell_map_) for (auto &row : cell_map_)
{ {
@ -125,6 +129,8 @@ struct worksheet_impl
std::vector<row_t> row_breaks_; std::vector<row_t> row_breaks_;
std::unordered_map<std::string, comment> comments_; std::unordered_map<std::string, comment> comments_;
optional<print_options> print_options_;
optional<sheet_pr> sheet_properties_;
optional<ext_list> extension_list_; optional<ext_list> extension_list_;
}; };

View File

@ -26,13 +26,6 @@
#include <sstream> #include <sstream>
#include <unordered_map> #include <unordered_map>
#include <detail/constants.hpp>
#include <detail/header_footer/header_footer_code.hpp>
#include <detail/implementations/workbook_impl.hpp>
#include <detail/serialization/custom_value_traits.hpp>
#include <detail/serialization/vector_streambuf.hpp>
#include <detail/serialization/xlsx_consumer.hpp>
#include <detail/serialization/zstream.hpp>
#include <xlnt/cell/cell.hpp> #include <xlnt/cell/cell.hpp>
#include <xlnt/cell/comment.hpp> #include <xlnt/cell/comment.hpp>
#include <xlnt/cell/hyperlink.hpp> #include <xlnt/cell/hyperlink.hpp>
@ -42,6 +35,13 @@
#include <xlnt/workbook/workbook.hpp> #include <xlnt/workbook/workbook.hpp>
#include <xlnt/worksheet/selection.hpp> #include <xlnt/worksheet/selection.hpp>
#include <xlnt/worksheet/worksheet.hpp> #include <xlnt/worksheet/worksheet.hpp>
#include <detail/constants.hpp>
#include <detail/header_footer/header_footer_code.hpp>
#include <detail/implementations/workbook_impl.hpp>
#include <detail/serialization/custom_value_traits.hpp>
#include <detail/serialization/vector_streambuf.hpp>
#include <detail/serialization/xlsx_consumer.hpp>
#include <detail/serialization/zstream.hpp>
namespace std { namespace std {
@ -221,9 +221,9 @@ cell xlsx_consumer::read_cell()
row_properties.dy_descent = parser().attribute<double>(qn("x14ac", "dyDescent")); row_properties.dy_descent = parser().attribute<double>(qn("x14ac", "dyDescent"));
} }
skip_attributes({ "customFormat", "s", "customFont", skip_attributes({"customFormat", "s", "customFont",
"outlineLevel", "collapsed", "thickTop", "thickBot", "outlineLevel", "collapsed", "thickTop", "thickBot",
"ph", "spans" }); "ph", "spans"});
} }
if (!in_element(qn("spreadsheetml", "row"))) if (!in_element(qn("spreadsheetml", "row")))
@ -274,8 +274,8 @@ cell xlsx_consumer::read_cell()
has_shared_formula = parser().attribute("t") == "shared"; has_shared_formula = parser().attribute("t") == "shared";
} }
skip_attributes({ "aca", "ref", "dt2D", "dtr", "del1", skip_attributes({"aca", "ref", "dt2D", "dtr", "del1",
"del2", "r1", "r2", "ca", "si", "bx" }); "del2", "r1", "r2", "ca", "si", "bx"});
formula_value_string = read_text(); formula_value_string = read_text();
} }
@ -367,13 +367,14 @@ std::string xlsx_consumer::read_worksheet_begin(const std::string &rel_id)
auto title = std::find_if(target_.d_->sheet_title_rel_id_map_.begin(), auto title = std::find_if(target_.d_->sheet_title_rel_id_map_.begin(),
target_.d_->sheet_title_rel_id_map_.end(), target_.d_->sheet_title_rel_id_map_.end(),
[&](const std::pair<std::string, std::string> &p) { [&](const std::pair<std::string, std::string> &p) {
return p.second == rel_id; return p.second == rel_id;
})->first; })
->first;
auto ws = worksheet(current_worksheet_); auto ws = worksheet(current_worksheet_);
expect_start_element(qn("spreadsheetml", "worksheet"), xml::content::complex); // CT_Worksheet expect_start_element(qn("spreadsheetml", "worksheet"), xml::content::complex); // CT_Worksheet
skip_attributes({ qn("mc", "Ignorable") }); skip_attributes({qn("mc", "Ignorable")});
while (in_element(qn("spreadsheetml", "worksheet"))) while (in_element(qn("spreadsheetml", "worksheet")))
{ {
@ -381,6 +382,44 @@ std::string xlsx_consumer::read_worksheet_begin(const std::string &rel_id)
if (current_worksheet_element == qn("spreadsheetml", "sheetPr")) // CT_SheetPr 0-1 if (current_worksheet_element == qn("spreadsheetml", "sheetPr")) // CT_SheetPr 0-1
{ {
sheet_pr props;
if (parser().attribute_present("syncHorizontal"))
{ // optional, boolean, false
props.sync_horizontal_.set(parser().attribute<bool>("syncHorizontal"));
}
if (parser().attribute_present("syncVertical"))
{// optional, boolean, false
props.sync_vertical_.set(parser().attribute<bool>("syncVertical"));
}
if (parser().attribute_present("syncRef"))
{ // optional, ST_Ref, false
props.sync_ref_.set(cell_reference(parser().attribute("syncRef")));
}
if (parser().attribute_present("transitionEvaluation"))
{ // optional, boolean, false
props.transition_evaluation_.set(parser().attribute<bool>("transitionEvaluation"));
}
if (parser().attribute_present("transitionEntry"))
{// optional, boolean, false
props.transition_entry_.set(parser().attribute<bool>("transitionEntry"));
}
if (parser().attribute_present("published"))
{// optional, boolean, true
props.published_.set(parser().attribute<bool>("published"));
}
if (parser().attribute_present("codeName"))
{ // optional, string
props.code_name_.set(parser().attribute<std::string>("codeName"));
}
if (parser().attribute_present("filterMode"))
{// optional, boolean, false
props.filter_mode.set(parser().attribute<bool>("filterMode"));
}
if (parser().attribute_present("enableFormatConditionsCalculation"))
{// optional, boolean, true
props.enable_format_condition_calculation_.set(parser().attribute<bool>("enableFormatConditionsCalculation"));
}
ws.d_->sheet_properties_.set(props);
while (in_element(current_worksheet_element)) while (in_element(current_worksheet_element))
{ {
auto sheet_pr_child_element = expect_start_element(xml::content::simple); auto sheet_pr_child_element = expect_start_element(xml::content::simple);
@ -408,16 +447,6 @@ std::string xlsx_consumer::read_worksheet_begin(const std::string &rel_id)
expect_end_element(sheet_pr_child_element); expect_end_element(sheet_pr_child_element);
} }
skip_attribute("syncHorizontal"); // optional, boolean, false
skip_attribute("syncVertical"); // optional, boolean, false
skip_attribute("syncRef"); // optional, ST_Ref, false
skip_attribute("transitionEvaluation"); // optional, boolean, false
skip_attribute("transitionEntry"); // optional, boolean, false
skip_attribute("published"); // optional, boolean, true
skip_attribute("codeName"); // optional, string
skip_attribute("filterMode"); // optional, boolean, false
skip_attribute("enableFormatConditionsCalculation"); // optional, boolean, true
} }
else if (current_worksheet_element == qn("spreadsheetml", "dimension")) // CT_SheetDimension 0-1 else if (current_worksheet_element == qn("spreadsheetml", "dimension")) // CT_SheetDimension 0-1
{ {
@ -446,8 +475,8 @@ std::string xlsx_consumer::read_worksheet_begin(const std::string &rel_id)
&& parser().attribute("view") != "normal") && parser().attribute("view") != "normal")
{ {
new_view.type(parser().attribute("view") == "pageBreakPreview" new_view.type(parser().attribute("view") == "pageBreakPreview"
? sheet_view_type::page_break_preview ? sheet_view_type::page_break_preview
: sheet_view_type::page_layout); : sheet_view_type::page_layout);
} }
if (parser().attribute_present("tabSelected") if (parser().attribute_present("tabSelected")
@ -456,9 +485,9 @@ std::string xlsx_consumer::read_worksheet_begin(const std::string &rel_id)
target_.d_->view_.get().active_tab = ws.id() - 1; target_.d_->view_.get().active_tab = ws.id() - 1;
} }
skip_attributes({ "windowProtection", "showFormulas", "showRowColHeaders", "showZeros", "rightToLeft", "showRuler", "showOutlineSymbols", "showWhiteSpace", skip_attributes({"windowProtection", "showFormulas", "showRowColHeaders", "showZeros", "rightToLeft", "showRuler", "showOutlineSymbols", "showWhiteSpace",
"view", "topLeftCell", "colorId", "zoomScale", "zoomScaleNormal", "zoomScaleSheetLayoutView", "view", "topLeftCell", "colorId", "zoomScale", "zoomScaleNormal", "zoomScaleSheetLayoutView",
"zoomScalePageLayoutView" }); "zoomScalePageLayoutView"});
while (in_element(qn("spreadsheetml", "sheetView"))) while (in_element(qn("spreadsheetml", "sheetView")))
{ {
@ -569,7 +598,7 @@ std::string xlsx_consumer::read_worksheet_begin(const std::string &rel_id)
{ {
expect_start_element(qn("spreadsheetml", "col"), xml::content::simple); expect_start_element(qn("spreadsheetml", "col"), xml::content::simple);
skip_attributes({ "bestFit", "collapsed", "outlineLevel" }); skip_attributes({"bestFit", "collapsed", "outlineLevel"});
auto min = static_cast<column_t::index_t>(std::stoull(parser().attribute("min"))); auto min = static_cast<column_t::index_t>(std::stoull(parser().attribute("min")));
auto max = static_cast<column_t::index_t>(std::stoull(parser().attribute("max"))); auto max = static_cast<column_t::index_t>(std::stoull(parser().attribute("max")));
@ -589,9 +618,11 @@ std::string xlsx_consumer::read_worksheet_begin(const std::string &rel_id)
} }
auto custom = parser().attribute_present("customWidth") auto custom = parser().attribute_present("customWidth")
? is_true(parser().attribute("customWidth")) : false; ? is_true(parser().attribute("customWidth"))
: false;
auto hidden = parser().attribute_present("hidden") auto hidden = parser().attribute_present("hidden")
? is_true(parser().attribute("hidden")) : false; ? is_true(parser().attribute("hidden"))
: false;
auto best_fit = parser().attribute_present("bestFit") auto best_fit = parser().attribute_present("bestFit")
? is_true(parser().attribute("bestFit")) ? is_true(parser().attribute("bestFit"))
: false; : false;
@ -676,9 +707,9 @@ void xlsx_consumer::read_worksheet_sheetdata()
row_properties.custom_format.set(parser().attribute<bool>("customFormat")); row_properties.custom_format.set(parser().attribute<bool>("customFormat"));
} }
skip_attributes({ "customFont", skip_attributes({"customFont",
"outlineLevel", "collapsed", "thickTop", "thickBot", "outlineLevel", "collapsed", "thickTop", "thickBot",
"ph", "spans" }); "ph", "spans"});
while (in_element(qn("spreadsheetml", "row"))) while (in_element(qn("spreadsheetml", "row")))
{ {
@ -719,7 +750,7 @@ void xlsx_consumer::read_worksheet_sheetdata()
} }
skip_attributes( skip_attributes(
{ "aca", "ref", "dt2D", "dtr", "del1", "del2", "r1", "r2", "ca", "si", "bx" }); {"aca", "ref", "dt2D", "dtr", "del1", "del2", "r1", "r2", "ca", "si", "bx"});
formula_value_string = read_text(); formula_value_string = read_text();
} }
@ -774,7 +805,6 @@ void xlsx_consumer::read_worksheet_sheetdata()
cell.error(value_string); cell.error(value_string);
} }
} }
} }
expect_end_element(qn("spreadsheetml", "row")); expect_end_element(qn("spreadsheetml", "row"));
@ -926,7 +956,28 @@ worksheet xlsx_consumer::read_worksheet_end(const std::string &rel_id)
} }
else if (current_worksheet_element == qn("spreadsheetml", "printOptions")) // CT_PrintOptions 0-1 else if (current_worksheet_element == qn("spreadsheetml", "printOptions")) // CT_PrintOptions 0-1
{ {
print_options opts;
if (parser().attribute_present("gridLines"))
{
opts.print_grid_lines.set(parser().attribute<bool>("gridLines"));
}
if (parser().attribute_present("gridLinesSet"))
{
opts.print_grid_lines.set(parser().attribute<bool>("gridLinesSet"));
}
if (parser().attribute_present("headings"))
{
opts.print_grid_lines.set(parser().attribute<bool>("headings"));
}
if (parser().attribute_present("horizontalCentered"))
{
opts.print_grid_lines.set(parser().attribute<bool>("horizontalCentered"));
}
if (parser().attribute_present("verticalCentered"))
{
opts.print_grid_lines.set(parser().attribute<bool>("verticalCentered"));
}
ws.d_->print_options_.set(opts);
skip_remaining_content(current_worksheet_element); skip_remaining_content(current_worksheet_element);
} }
else if (current_worksheet_element == qn("spreadsheetml", "pageMargins")) // CT_PageMargins 0-1 else if (current_worksheet_element == qn("spreadsheetml", "pageMargins")) // CT_PageMargins 0-1
@ -1021,7 +1072,7 @@ worksheet xlsx_consumer::read_worksheet_end(const std::string &rel_id)
for (std::size_t i = 0; i < 3; ++i) for (std::size_t i = 0; i < 3; ++i)
{ {
auto loc = i == 0 ? header_footer::location::left auto loc = i == 0 ? header_footer::location::left
: i == 1 ? header_footer::location::center : header_footer::location::right; : i == 1 ? header_footer::location::center : header_footer::location::right;
if (different_odd_even) if (different_odd_even)
{ {
@ -1061,7 +1112,8 @@ worksheet xlsx_consumer::read_worksheet_end(const std::string &rel_id)
{ {
auto count = parser().attribute_present("count") ? parser().attribute<std::size_t>("count") : 0; auto count = parser().attribute_present("count") ? parser().attribute<std::size_t>("count") : 0;
auto manual_break_count = parser().attribute_present("manualBreakCount") auto manual_break_count = parser().attribute_present("manualBreakCount")
? parser().attribute<std::size_t>("manualBreakCount") : 0; ? parser().attribute<std::size_t>("manualBreakCount")
: 0;
while (in_element(qn("spreadsheetml", "rowBreaks"))) while (in_element(qn("spreadsheetml", "rowBreaks")))
{ {
@ -1078,7 +1130,7 @@ worksheet xlsx_consumer::read_worksheet_end(const std::string &rel_id)
--manual_break_count; --manual_break_count;
} }
skip_attributes({ "min", "max", "pt" }); skip_attributes({"min", "max", "pt"});
expect_end_element(qn("spreadsheetml", "brk")); expect_end_element(qn("spreadsheetml", "brk"));
} }
} }
@ -1104,7 +1156,7 @@ worksheet xlsx_consumer::read_worksheet_end(const std::string &rel_id)
--manual_break_count; --manual_break_count;
} }
skip_attributes({ "min", "max", "pt" }); skip_attributes({"min", "max", "pt"});
expect_end_element(qn("spreadsheetml", "brk")); expect_end_element(qn("spreadsheetml", "brk"));
} }
} }
@ -1148,8 +1200,8 @@ worksheet xlsx_consumer::read_worksheet_end(const std::string &rel_id)
if (manifest.has_relationship(sheet_path, xlnt::relationship_type::comments)) if (manifest.has_relationship(sheet_path, xlnt::relationship_type::comments))
{ {
auto comments_part = manifest.canonicalize({ workbook_rel, sheet_rel, auto comments_part = manifest.canonicalize({workbook_rel, sheet_rel,
manifest.relationship(sheet_path, xlnt::relationship_type::comments) }); manifest.relationship(sheet_path, xlnt::relationship_type::comments)});
auto receive = xml::parser::receive_default; auto receive = xml::parser::receive_default;
auto comments_part_streambuf = archive_->open(comments_part); auto comments_part_streambuf = archive_->open(comments_part);
@ -1161,8 +1213,8 @@ worksheet xlsx_consumer::read_worksheet_end(const std::string &rel_id)
if (manifest.has_relationship(sheet_path, xlnt::relationship_type::vml_drawing)) if (manifest.has_relationship(sheet_path, xlnt::relationship_type::vml_drawing))
{ {
auto vml_drawings_part = manifest.canonicalize({ workbook_rel, sheet_rel, auto vml_drawings_part = manifest.canonicalize({workbook_rel, sheet_rel,
manifest.relationship(sheet_path, xlnt::relationship_type::vml_drawing) }); manifest.relationship(sheet_path, xlnt::relationship_type::vml_drawing)});
auto vml_drawings_part_streambuf = archive_->open(comments_part); auto vml_drawings_part_streambuf = archive_->open(comments_part);
std::istream vml_drawings_part_stream(comments_part_streambuf.get()); std::istream vml_drawings_part_stream(comments_part_streambuf.get());
@ -1189,8 +1241,7 @@ bool xlsx_consumer::has_cell()
std::vector<relationship> xlsx_consumer::read_relationships(const path &part) std::vector<relationship> xlsx_consumer::read_relationships(const path &part)
{ {
const auto part_rels_path = part.parent().append("_rels") const auto part_rels_path = part.parent().append("_rels").append(part.filename() + ".rels").relative_to(path("/"));
.append(part.filename() + ".rels").relative_to(path("/"));
std::vector<xlnt::relationship> relationships; std::vector<xlnt::relationship> relationships;
if (!archive_->has_file(part_rels_path)) return relationships; if (!archive_->has_file(part_rels_path)) return relationships;
@ -1398,8 +1449,8 @@ void xlsx_consumer::populate_workbook(bool streaming)
} }
} }
read_part({ manifest().relationship(root_path, read_part({manifest().relationship(root_path,
relationship_type::office_document) }); relationship_type::office_document)});
} }
// Package Parts // Package Parts
@ -1496,10 +1547,12 @@ void xlsx_consumer::read_custom_properties()
void xlsx_consumer::read_office_document(const std::string &content_type) // CT_Workbook void xlsx_consumer::read_office_document(const std::string &content_type) // CT_Workbook
{ {
if (content_type != "application/vnd." if (content_type !=
"openxmlformats-officedocument.spreadsheetml.sheet.main+xml" "application/vnd."
&& content_type != "application/vnd." "openxmlformats-officedocument.spreadsheetml.sheet.main+xml"
"openxmlformats-officedocument.spreadsheetml.template.main+xml") && content_type !=
"application/vnd."
"openxmlformats-officedocument.spreadsheetml.template.main+xml")
{ {
throw xlnt::invalid_file(content_type); throw xlnt::invalid_file(content_type);
} }
@ -1573,8 +1626,9 @@ void xlsx_consumer::read_office_document(const std::string &content_type) // CT_
else if (current_workbook_element == qn("workbook", "workbookPr")) // CT_WorkbookPr 0-1 else if (current_workbook_element == qn("workbook", "workbookPr")) // CT_WorkbookPr 0-1
{ {
target_.base_date(parser().attribute_present("date1904") // optional, bool=false target_.base_date(parser().attribute_present("date1904") // optional, bool=false
&& is_true(parser().attribute("date1904")) && is_true(parser().attribute("date1904"))
? calendar::mac_1904 : calendar::windows_1900); ? calendar::mac_1904
: calendar::windows_1900);
skip_attribute("showObjects"); // optional, ST_Objects="all" skip_attribute("showObjects"); // optional, ST_Objects="all"
skip_attribute("showBorderUnselectedTables"); // optional, bool=true skip_attribute("showBorderUnselectedTables"); // optional, bool=true
skip_attribute("filterPrivacy"); // optional, bool=false skip_attribute("filterPrivacy"); // optional, bool=false
@ -1785,7 +1839,8 @@ void xlsx_consumer::read_office_document(const std::string &content_type) // CT_
target_.d_->sheet_title_rel_id_map_.end(), target_.d_->sheet_title_rel_id_map_.end(),
[&](const std::pair<std::string, std::string> &p) { [&](const std::pair<std::string, std::string> &p) {
return p.second == worksheet_rel.id(); return p.second == worksheet_rel.id();
})->first; })
->first;
auto id = sheet_title_id_map_[title]; auto id = sheet_title_id_map_[title];
auto index = sheet_title_index_map_[title]; auto index = sheet_title_index_map_[title];
@ -1800,7 +1855,7 @@ void xlsx_consumer::read_office_document(const std::string &content_type) // CT_
if (!streaming_) if (!streaming_)
{ {
read_part({ workbook_rel, worksheet_rel }); read_part({workbook_rel, worksheet_rel});
} }
} }
} }
@ -2265,36 +2320,40 @@ void xlsx_consumer::read_stylesheet()
expect_start_element(qn("spreadsheetml", "xf"), xml::content::complex); expect_start_element(qn("spreadsheetml", "xf"), xml::content::complex);
auto &record = *(!in_style_records auto &record = *(!in_style_records
? format_records.emplace(format_records.end()) ? format_records.emplace(format_records.end())
: style_records.emplace(style_records.end())); : style_records.emplace(style_records.end()));
if (parser().attribute_present("applyBorder")) if (parser().attribute_present("applyBorder"))
{ {
record.first.border_applied = is_true(parser().attribute("applyBorder")); record.first.border_applied = is_true(parser().attribute("applyBorder"));
} }
record.first.border_id = parser().attribute_present("borderId") record.first.border_id = parser().attribute_present("borderId")
? parser().attribute<std::size_t>("borderId") : 0; ? parser().attribute<std::size_t>("borderId")
: 0;
if (parser().attribute_present("applyFill")) if (parser().attribute_present("applyFill"))
{ {
record.first.fill_applied = is_true(parser().attribute("applyFill")); record.first.fill_applied = is_true(parser().attribute("applyFill"));
} }
record.first.fill_id = parser().attribute_present("fillId") record.first.fill_id = parser().attribute_present("fillId")
? parser().attribute<std::size_t>("fillId") : 0; ? parser().attribute<std::size_t>("fillId")
: 0;
if (parser().attribute_present("applyFont")) if (parser().attribute_present("applyFont"))
{ {
record.first.font_applied = is_true(parser().attribute("applyFont")); record.first.font_applied = is_true(parser().attribute("applyFont"));
} }
record.first.font_id = parser().attribute_present("fontId") record.first.font_id = parser().attribute_present("fontId")
? parser().attribute<std::size_t>("fontId") : 0; ? parser().attribute<std::size_t>("fontId")
: 0;
if (parser().attribute_present("applyNumberFormat")) if (parser().attribute_present("applyNumberFormat"))
{ {
record.first.number_format_applied = is_true(parser().attribute("applyNumberFormat")); record.first.number_format_applied = is_true(parser().attribute("applyNumberFormat"));
} }
record.first.number_format_id = parser().attribute_present("numFmtId") record.first.number_format_id = parser().attribute_present("numFmtId")
? parser().attribute<std::size_t>("numFmtId") : 0; ? parser().attribute<std::size_t>("numFmtId")
: 0;
auto apply_alignment_present = parser().attribute_present("applyAlignment"); auto apply_alignment_present = parser().attribute_present("applyAlignment");
if (apply_alignment_present) if (apply_alignment_present)
@ -2585,7 +2644,7 @@ void xlsx_consumer::read_comments(worksheet ws)
expect_start_element(qn("spreadsheetml", "comments"), xml::content::complex); expect_start_element(qn("spreadsheetml", "comments"), xml::content::complex);
// name space can be ignored // name space can be ignored
skip_attribute(qn("mc","Ignorable")); skip_attribute(qn("mc", "Ignorable"));
expect_start_element(qn("spreadsheetml", "authors"), xml::content::complex); expect_start_element(qn("spreadsheetml", "authors"), xml::content::complex);
while (in_element(qn("spreadsheetml", "authors"))) while (in_element(qn("spreadsheetml", "authors")))
@ -2612,12 +2671,12 @@ void xlsx_consumer::read_comments(worksheet ws)
expect_end_element(qn("spreadsheetml", "text")); expect_end_element(qn("spreadsheetml", "text"));
if (in_element(xml::qname(qn("spreadsheetml", "comment")))) if (in_element(xml::qname(qn("spreadsheetml", "comment"))))
{ {
expect_start_element(qn("mc", "AlternateContent"), xml::content::complex); expect_start_element(qn("mc", "AlternateContent"), xml::content::complex);
skip_remaining_content(qn("mc", "AlternateContent")); skip_remaining_content(qn("mc", "AlternateContent"));
expect_end_element(qn("mc", "AlternateContent")); expect_end_element(qn("mc", "AlternateContent"));
} }
expect_end_element(qn("spreadsheetml", "comment")); expect_end_element(qn("spreadsheetml", "comment"));
} }
@ -2820,7 +2879,8 @@ rich_text xlsx_consumer::read_rich_text(const xml::qname &parent)
auto text_element = expect_start_element(xml::content::mixed); auto text_element = expect_start_element(xml::content::mixed);
const auto xml_space = qn("xml", "space"); const auto xml_space = qn("xml", "space");
const auto preserve_space = parser().attribute_present(xml_space) const auto preserve_space = parser().attribute_present(xml_space)
? parser().attribute(xml_space) == "preserve" : false; ? parser().attribute(xml_space) == "preserve"
: false;
skip_attributes(); skip_attributes();
auto text = read_text(); auto text = read_text();
@ -2872,12 +2932,14 @@ rich_text xlsx_consumer::read_rich_text(const xml::qname &parent)
else if (current_run_property_element == xml::qname(xmlns, "b")) else if (current_run_property_element == xml::qname(xmlns, "b"))
{ {
run.second.get().bold(parser().attribute_present("val") run.second.get().bold(parser().attribute_present("val")
? is_true(parser().attribute("val")) : true); ? is_true(parser().attribute("val"))
: true);
} }
else if (current_run_property_element == xml::qname(xmlns, "i")) else if (current_run_property_element == xml::qname(xmlns, "i"))
{ {
run.second.get().italic(parser().attribute_present("val") run.second.get().italic(parser().attribute_present("val")
? is_true(parser().attribute("val")) : true); ? is_true(parser().attribute("val"))
: true);
} }
else if (current_run_property_element == xml::qname(xmlns, "u")) else if (current_run_property_element == xml::qname(xmlns, "u"))
{ {
@ -2972,4 +3034,4 @@ manifest &xlsx_consumer::manifest()
} }
} // namespace detail } // namespace detail
} // namepsace xlnt } // namespace xlnt

View File

@ -2224,9 +2224,46 @@ void xlsx_producer::write_worksheet(const relationship &rel)
write_attribute(xml::qname(xmlns_mc, "Ignorable"), "x14ac"); write_attribute(xml::qname(xmlns_mc, "Ignorable"), "x14ac");
} }
if (ws.has_page_setup()) if (ws.d_->sheet_properties_.is_set())
{ {
write_start_element(xmlns, "sheetPr"); write_start_element(xmlns, "sheetPr");
auto &props = ws.d_->sheet_properties_.get();
if (props.sync_horizontal_.is_set())
{
write_attribute("syncHorizontal", props.sync_horizontal_.get());
}
if (props.sync_vertical_.is_set())
{
write_attribute("syncVertical", props.sync_vertical_.get());
}
if (props.sync_ref_.is_set())
{
write_attribute("syncRef", props.sync_ref_.get().to_string());
}
if (props.transition_evaluation_.is_set())
{
write_attribute("transitionEvaluation", props.transition_evaluation_.get());
}
if (props.transition_entry_.is_set())
{
write_attribute("transitionEntry", props.transition_entry_.get());
}
if (props.published_.is_set())
{
write_attribute("published", props.published_.get());
}
if (props.code_name_.is_set())
{
write_attribute("codeName", props.code_name_.get());
}
if (props.filter_mode.is_set())
{
write_attribute("filterMode", props.filter_mode.get());
}
if (props.enable_format_condition_calculation_.is_set())
{
write_attribute("enableFormatConditionsCalculation", props.enable_format_condition_calculation_.get());
}
write_start_element(xmlns, "outlinePr"); write_start_element(xmlns, "outlinePr");
write_attribute("summaryBelow", "1"); write_attribute("summaryBelow", "1");
@ -2706,11 +2743,30 @@ void xlsx_producer::write_worksheet(const relationship &rel)
write_end_element(xmlns, "hyperlinks"); write_end_element(xmlns, "hyperlinks");
} }
if (ws.has_page_setup()) if (ws.d_->print_options_.is_set())
{ {
auto &opts = ws.d_->print_options_.get();
write_start_element(xmlns, "printOptions"); write_start_element(xmlns, "printOptions");
write_attribute("horizontalCentered", write_bool(ws.page_setup().horizontal_centered())); if (opts.print_grid_lines.is_set())
write_attribute("verticalCentered", write_bool(ws.page_setup().vertical_centered())); {
write_attribute("gridLines", write_bool(opts.print_grid_lines.get()));
}
if (opts.grid_lines_set.is_set())
{
write_attribute("gridLineSet", write_bool(opts.grid_lines_set.get()));
}
if (opts.print_headings.is_set())
{
write_attribute("headings", write_bool(opts.print_headings.get()));
}
if (opts.horizontal_centered.is_set())
{
write_attribute("horizontalCentered", write_bool(opts.horizontal_centered.get()));
}
if (opts.vertical_centered.is_set())
{
write_attribute("verticalCentered", write_bool(opts.vertical_centered.get()));
}
write_end_element(xmlns, "printOptions"); write_end_element(xmlns, "printOptions");
} }

View File

@ -32,8 +32,6 @@ page_setup::page_setup()
fit_to_page_(false), fit_to_page_(false),
fit_to_height_(false), fit_to_height_(false),
fit_to_width_(false), fit_to_width_(false),
horizontal_centered_(false),
vertical_centered_(false),
scale_(1) scale_(1)
{ {
} }
@ -98,26 +96,6 @@ void page_setup::fit_to_width(bool fit_to_width)
fit_to_width_ = fit_to_width; fit_to_width_ = fit_to_width;
} }
void page_setup::horizontal_centered(bool horizontal_centered)
{
horizontal_centered_ = horizontal_centered;
}
bool page_setup::horizontal_centered() const
{
return horizontal_centered_;
}
void page_setup::vertical_centered(bool vertical_centered)
{
vertical_centered_ = vertical_centered;
}
bool page_setup::vertical_centered() const
{
return vertical_centered_;
}
void page_setup::scale(double scale) void page_setup::scale(double scale)
{ {
scale_ = scale; scale_ = scale;

View File

@ -59,13 +59,5 @@ public:
xlnt_assert(!ps.fit_to_width()); xlnt_assert(!ps.fit_to_width());
ps.fit_to_width(true); ps.fit_to_width(true);
xlnt_assert(ps.fit_to_width()); xlnt_assert(ps.fit_to_width());
xlnt_assert(!ps.horizontal_centered());
ps.horizontal_centered(true);
xlnt_assert(ps.horizontal_centered());
xlnt_assert(!ps.vertical_centered());
ps.vertical_centered(true);
xlnt_assert(ps.vertical_centered());
} }
}; };