diff --git a/source/detail/style_serializer.cpp b/source/detail/style_serializer.cpp index fd2ae676..88446058 100644 --- a/source/detail/style_serializer.cpp +++ b/source/detail/style_serializer.cpp @@ -633,7 +633,7 @@ xlnt::fill read_fill(const pugi::xml_node &fill_node) else if (fill_node.child("gradientFill")) { auto gradient_fill_node = fill_node.child("gradientFill"); - std::string gradient_fill_type_string = gradient_fill_node.attribute("gradientType").value(); + std::string gradient_fill_type_string = gradient_fill_node.attribute("type").value(); if (!gradient_fill_type_string.empty()) { @@ -643,6 +643,14 @@ xlnt::fill read_fill(const pugi::xml_node &fill_node) { new_fill = xlnt::fill::gradient(xlnt::gradient_fill::type::linear); } + + for (auto stop_node : gradient_fill_node.children("stop")) + { + auto position = stop_node.attribute("position").as_double(); + auto color = read_color(stop_node.child("color")); + + new_fill.get_gradient_fill().add_stop(position, color); + } } return new_fill; diff --git a/source/workbook/tests/test_style_reader.hpp b/source/workbook/tests/test_style_reader.hpp index 21ff2c34..e14f45df 100644 --- a/source/workbook/tests/test_style_reader.hpp +++ b/source/workbook/tests/test_style_reader.hpp @@ -17,11 +17,22 @@ public: wb.load(path_helper::get_data_directory("/reader/formatting.xlsx")); // border_style - TS_ASSERT_EQUALS(wb.get_active_sheet().get_cell("E30").get_border().get_top()->get_color(), xlnt::color(xlnt::color::type::indexed, 10)); - TS_ASSERT_EQUALS(wb.get_active_sheet().get_cell("E30").get_border().get_top()->get_border_style(), xlnt::border_style::thin); + auto ws = wb.get_active_sheet(); + auto e30 = ws.get_cell("E30"); + TS_ASSERT_EQUALS(e30.get_border().get_top()->get_color(), xlnt::color(xlnt::color::type::indexed, 10)); + TS_ASSERT_EQUALS(e30.get_border().get_top()->get_border_style(), xlnt::border_style::thin); // underline_style - TS_ASSERT_EQUALS(wb.get_active_sheet().get_cell("E30").get_font().get_underline(), xlnt::font::underline_style::none); - TS_ASSERT_EQUALS(wb.get_active_sheet().get_cell("F30").get_font().get_underline(), xlnt::font::underline_style::single); + auto f30 = ws.get_cell("F30"); + TS_ASSERT_EQUALS(e30.get_font().get_underline(), xlnt::font::underline_style::none); + TS_ASSERT_EQUALS(f30.get_font().get_underline(), xlnt::font::underline_style::single); + + // gradient fill + auto e21 = ws.get_cell("E21"); + TS_ASSERT_EQUALS(e21.get_fill().get_type(), xlnt::fill::type::gradient); + TS_ASSERT_EQUALS(e21.get_fill().get_gradient_fill().get_type(), xlnt::gradient_fill::type::linear); + TS_ASSERT_EQUALS(e21.get_fill().get_gradient_fill().get_stops().size(), 2); + TS_ASSERT_EQUALS(e21.get_fill().get_gradient_fill().get_stops().at(0), xlnt::color(xlnt::color::type::rgb, "FFFF0000")); + TS_ASSERT_EQUALS(e21.get_fill().get_gradient_fill().get_stops().at(1), xlnt::color(xlnt::color::type::rgb, "FF0000FF")); } }; diff --git a/source/workbook/tests/test_workbook.hpp b/source/workbook/tests/test_workbook.hpp index 05058316..752dcf91 100644 --- a/source/workbook/tests/test_workbook.hpp +++ b/source/workbook/tests/test_workbook.hpp @@ -104,6 +104,8 @@ public: auto found_sheet = wb.get_sheet_by_name(title); TS_ASSERT_EQUALS(new_sheet, found_sheet); TS_ASSERT_THROWS(wb.get_sheet_by_name("error"), xlnt::key_error); + const auto &wb_const = wb; + TS_ASSERT_THROWS(wb_const.get_sheet_by_name("error"), xlnt::key_error); } void test_get_sheet_by_name_const() diff --git a/tests/data/reader/formatting.xlsx b/tests/data/reader/formatting.xlsx index e6acaef7..25a41c57 100644 Binary files a/tests/data/reader/formatting.xlsx and b/tests/data/reader/formatting.xlsx differ