From 26eacce2480a3d8085ec0fead0ea425b3ac78b7c Mon Sep 17 00:00:00 2001 From: sukoi26 Date: Mon, 6 Feb 2017 22:54:09 +0100 Subject: [PATCH 1/5] font change for charset, outline shadow --- include/xlnt/styles/font.hpp | 51 ++++++++++++++++++++++++++++++++++++ source/styles/font.cpp | 35 +++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/include/xlnt/styles/font.hpp b/include/xlnt/styles/font.hpp index 5705caf8..195ebcbe 100644 --- a/include/xlnt/styles/font.hpp +++ b/include/xlnt/styles/font.hpp @@ -97,6 +97,26 @@ public: /// bool strikethrough() const; + /// + /// + /// + font &outlinethrough(bool outlinethrough); + + /// + /// + /// + bool outlinethrough() const; + + /// + /// + /// + font &shadowthrough(bool shadowthrough); + + /// + /// + /// + bool shadowthrough() const; + /// /// /// @@ -172,6 +192,21 @@ public: /// std::size_t family() const; + /// + /// + /// + bool has_charset() const; + + /// + /// + /// + font &charset(std::size_t charset); + + /// + /// + /// + std::size_t charset() const; + /// /// /// @@ -238,6 +273,16 @@ private: /// bool strikethrough_ = false; + /// + /// + /// + bool outlinethrough_ = false; + + /// + /// + /// + bool shadowthrough_ = false; + /// /// /// @@ -253,6 +298,12 @@ private: /// optional family_; + /// + /// + /// + optional charset_; + + /// /// /// diff --git a/source/styles/font.cpp b/source/styles/font.cpp index 02a96253..ff118bdd 100644 --- a/source/styles/font.cpp +++ b/source/styles/font.cpp @@ -36,6 +36,8 @@ font::font() superscript_(false), subscript_(false), strikethrough_(false), + outlinethrough_(false), + shadowthrough_(false), underline_(underline_style::none) { } @@ -84,6 +86,28 @@ bool font::strikethrough() const return strikethrough_; } +font &font::outlinethrough(bool outlinethrough) +{ + outlinethrough_ = outlinethrough; + return *this; +} + +bool font::outlinethrough() const +{ + return outlinethrough_; +} + +font &font::shadowthrough(bool shadowthrough) +{ + shadowthrough_ = shadowthrough; + return *this; +} + +bool font::shadowthrough() const +{ + return shadowthrough_; +} + font &font::underline(underline_style new_underline) { underline_ = new_underline; @@ -154,6 +178,17 @@ font &font::family(std::size_t family) return *this; } +bool font::has_charset() const +{ + return charset_.is_set(); +} + +font &font::charset(std::size_t charset) +{ + charset_ = charset; + return *this; +} + bool font::has_scheme() const { return scheme_.is_set(); From d7486830a6f2e37b0767a85115d42f5a3a0cdb40 Mon Sep 17 00:00:00 2001 From: sukoi26 Date: Mon, 6 Feb 2017 23:00:45 +0100 Subject: [PATCH 2/5] comment changes anchor() , in element() --- source/cell/cell.cpp | 6 ++--- source/detail/xlsx_consumer.cpp | 47 +++++++++++++++++++++++++++------ 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/source/cell/cell.cpp b/source/cell/cell.cpp index 0a3a8f80..7e218587 100644 --- a/source/cell/cell.cpp +++ b/source/cell/cell.cpp @@ -528,15 +528,15 @@ std::pair cell::anchor() const for (column_t column_index = 1; column_index <= d_->column_ - 1; column_index++) { - left += worksheet().cell(column_index, row()).width(); + left += worksheet().column_width(column_index); } double top = 0; for (row_t row_index = 1; row_index <= d_->row_ - 1; row_index++) { - top += worksheet().cell(column(), row_index).height(); - } + top += worksheet().row_height(row_index); + } return {static_cast(left), static_cast(top)}; } diff --git a/source/detail/xlsx_consumer.cpp b/source/detail/xlsx_consumer.cpp index be401923..97308157 100755 --- a/source/detail/xlsx_consumer.cpp +++ b/source/detail/xlsx_consumer.cpp @@ -1345,6 +1345,28 @@ void xlsx_consumer::read_stylesheet() new_font.strikethrough(true); } } + else if (font_property_element == qn("spreadsheetml", "outline")) + { + if (parser().attribute_present("val")) + { + new_font.outlinethrough(is_true(parser().attribute("val"))); + } + else + { + new_font.outlinethrough(true); + } + } + else if (font_property_element == qn("spreadsheetml", "shadow")) + { + if (parser().attribute_present("val")) + { + new_font.shadowthrough(is_true(parser().attribute("val"))); + } + else + { + new_font.shadowthrough(true); + } + } else if (font_property_element == qn("spreadsheetml", "i")) { if (parser().attribute_present("val")) @@ -1575,11 +1597,11 @@ void xlsx_consumer::read_stylesheet() auto count = parser().attribute("count"); std::size_t processed = 0; - while (in_element(qn("spreadsheetml", "dxfs"))) + while (in_element(current_style_element)) { - auto current_element = expect_start_element(xml::content::complex); + auto current_element = expect_start_element(xml::content::mixed); skip_remaining_content(current_element); - + expect_end_element(current_element); ++processed; } @@ -1600,7 +1622,7 @@ void xlsx_consumer::read_stylesheet() { auto current_element = expect_start_element(xml::content::complex); skip_remaining_content(current_element); - + expect_end_element(current_element); ++processed; } @@ -1674,7 +1696,7 @@ void xlsx_consumer::read_stylesheet() */ /* std::size_t xf_id = 0; - + for (const auto &record : style_records) { auto style_iter = std::find_if(styles.begin(), styles.end(), @@ -2510,7 +2532,7 @@ variant xlsx_consumer::read_variant() // bool could be "0" or "false" bool bvalue; if (text[0] == '0' or text[0] == 'f' or text[0]=='F') bvalue = false; - else bvalue = true; + else bvalue = true; value = variant(bvalue); } else if (element == qn("vt", "vector")) @@ -2627,11 +2649,11 @@ std::vector xlsx_consumer::read_namespaces() bool xlsx_consumer::in_element(const xml::qname &name) { - if (parser().peek() == xml::parser::event_type::end_element || stack_.back() != name) + + if ((parser().peek() == xml::parser::event_type::end_element ) && (stack_.back() == name )) { return false; } - return true; } @@ -2717,6 +2739,10 @@ rich_text xlsx_consumer::read_rich_text(const xml::qname &parent) { run.second.get().family(parser().attribute("val")); } + else if (current_run_property_element == xml::qname(xmlns, "charset")) + { + run.second.get().charset(parser().attribute("val")); + } else if (current_run_property_element == xml::qname(xmlns, "scheme")) { run.second.get().scheme(parser().attribute("val")); @@ -2726,6 +2752,11 @@ rich_text xlsx_consumer::read_rich_text(const xml::qname &parent) run.second.get().bold( parser().attribute_present("val") ? is_true(parser().attribute("val")) : true); } + else if (current_run_property_element == xml::qname(xmlns, "i")) + { + run.second.get().bold( + parser().attribute_present("val") ? is_true(parser().attribute("val")) : true); + } else if (current_run_property_element == xml::qname(xmlns, "u")) { if (parser().attribute_present("val")) From 3fee3f0eb52b402eb12e0553b5815f4251fe42e3 Mon Sep 17 00:00:00 2001 From: sukoi26 Date: Tue, 7 Feb 2017 15:13:34 +0100 Subject: [PATCH 3/5] skip comment "shapeId" --- source/detail/xlsx_consumer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/detail/xlsx_consumer.cpp b/source/detail/xlsx_consumer.cpp index 97308157..2a6145cc 100755 --- a/source/detail/xlsx_consumer.cpp +++ b/source/detail/xlsx_consumer.cpp @@ -2460,7 +2460,8 @@ void xlsx_consumer::read_comments(worksheet ws) { expect_start_element(qn("spreadsheetml", "comment"), xml::content::complex); - auto cell_ref = parser().attribute("ref"); + skip_attribute("shapeId"); + auto cell_ref = parser().attribute("ref"); auto author_id = parser().attribute("authorId"); expect_start_element(qn("spreadsheetml", "text"), xml::content::complex); From 4678048c2144b48284a500ec0dc30aa5b1d928f3 Mon Sep 17 00:00:00 2001 From: sukoi26 Date: Tue, 7 Feb 2017 22:49:02 +0100 Subject: [PATCH 4/5] check file extension workbook .xlsx --- source/workbook/workbook.cpp | 48 ++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/source/workbook/workbook.cpp b/source/workbook/workbook.cpp index 9bb0f559..a7fb27ce 100644 --- a/source/workbook/workbook.cpp +++ b/source/workbook/workbook.cpp @@ -474,7 +474,7 @@ void workbook::register_package_part(relationship_type type) { manifest().register_override_type(default_path(type), content_type(type)); manifest().register_relationship(uri("/"), type, - uri(default_path(type).relative_to(path("/")).string()), + uri(default_path(type).relative_to(path("/")).string()), target_mode::internal); } } @@ -700,7 +700,7 @@ worksheet workbook::copy_sheet(worksheet to_copy) auto new_sheet = create_sheet(); impl.title_ = new_sheet.title(); *new_sheet.d_ = impl; - + return new_sheet; } @@ -719,7 +719,7 @@ worksheet workbook::copy_sheet(worksheet to_copy, std::size_t index) d_->worksheets_.insert(iter, d_->worksheets_.back()); d_->worksheets_.pop_back(); } - + return sheet_by_index(index); } @@ -793,6 +793,25 @@ void workbook::load(const std::vector &data) void workbook::load(const std::string &filename) { + if (filename.find_last_of(".") != std::string::npos) // check extension + { + std::string file_format = filename.substr(filename.find_last_of(".")+1); + + if (file_format == "xls") { + throw xlnt::exception(" xlnt does not support the old .xls file format"); + } + else if (file_format == "xlsb") { + throw xlnt::exception(" xlnt does not support the .xlsb file format"); + } + else if (file_format != "xlsx") { + throw xlnt::exception(" xlnt does not support the ."+file_format+ " file format"); + } + } + else + { + throw xlnt::exception("file has no extension .xlsx"); + } + return load(path(filename)); } @@ -811,6 +830,25 @@ void workbook::load(const path &filename) void workbook::load(const std::string &filename, const std::string &password) { + if (filename.find_last_of(".") != std::string::npos) // check extension + { + std::string file_format = filename.substr(filename.find_last_of(".")+1); + + if (file_format == "xls") { + throw xlnt::exception(" xlnt does not support the old .xls file format"); + } + else if (file_format == "xlsb") { + throw xlnt::exception(" xlnt does not support the .xlsb file format"); + } + else if (file_format != "xlsx") { + throw xlnt::exception(" xlnt does not support the ."+file_format+ " file format"); + } + } + else + { + throw xlnt::exception("file has no extension .xlsx"); + } + return load(path(filename), password); } @@ -1229,13 +1267,13 @@ bool workbook::contains(const std::string &sheet_title) const return false; } -void workbook::thumbnail(const std::vector &thumbnail, +void workbook::thumbnail(const std::vector &thumbnail, const std::string &extension, const std::string &content_type) { if (!d_->manifest_.has_relationship(path("/"), relationship_type::thumbnail)) { d_->manifest_.register_default_type(extension, content_type); - d_->manifest_.register_relationship(uri("/"), relationship_type::thumbnail, + d_->manifest_.register_relationship(uri("/"), relationship_type::thumbnail, uri("docProps/thumbnail.jpeg"), target_mode::internal); } From b0664ded17b1cce9ce01d96a78eccf434dfe6773 Mon Sep 17 00:00:00 2001 From: sukoi26 Date: Thu, 9 Feb 2017 13:33:23 +0100 Subject: [PATCH 5/5] update check extension with xlnt function --- source/workbook/workbook.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/workbook/workbook.cpp b/source/workbook/workbook.cpp index a7fb27ce..56f7bbc7 100644 --- a/source/workbook/workbook.cpp +++ b/source/workbook/workbook.cpp @@ -795,7 +795,7 @@ void workbook::load(const std::string &filename) { if (filename.find_last_of(".") != std::string::npos) // check extension { - std::string file_format = filename.substr(filename.find_last_of(".")+1); + std::string file_format = path(filename).extension(); if (file_format == "xls") { throw xlnt::exception(" xlnt does not support the old .xls file format"); @@ -832,7 +832,7 @@ void workbook::load(const std::string &filename, const std::string &password) { if (filename.find_last_of(".") != std::string::npos) // check extension { - std::string file_format = filename.substr(filename.find_last_of(".")+1); + std::string file_format = path(filename).extension(); if (file_format == "xls") { throw xlnt::exception(" xlnt does not support the old .xls file format");