test and implement reading gradient fill

This commit is contained in:
Thomas Fussell 2016-07-23 20:41:55 -04:00
parent 51db47e2a8
commit 8ef1fe1a28
4 changed files with 26 additions and 5 deletions

View File

@ -633,7 +633,7 @@ xlnt::fill read_fill(const pugi::xml_node &fill_node)
else if (fill_node.child("gradientFill")) else if (fill_node.child("gradientFill"))
{ {
auto gradient_fill_node = 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()) 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); 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; return new_fill;

View File

@ -17,11 +17,22 @@ public:
wb.load(path_helper::get_data_directory("/reader/formatting.xlsx")); wb.load(path_helper::get_data_directory("/reader/formatting.xlsx"));
// border_style // 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)); auto ws = wb.get_active_sheet();
TS_ASSERT_EQUALS(wb.get_active_sheet().get_cell("E30").get_border().get_top()->get_border_style(), xlnt::border_style::thin); 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 // underline_style
TS_ASSERT_EQUALS(wb.get_active_sheet().get_cell("E30").get_font().get_underline(), xlnt::font::underline_style::none); auto f30 = ws.get_cell("F30");
TS_ASSERT_EQUALS(wb.get_active_sheet().get_cell("F30").get_font().get_underline(), xlnt::font::underline_style::single); 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"));
} }
}; };

View File

@ -104,6 +104,8 @@ public:
auto found_sheet = wb.get_sheet_by_name(title); auto found_sheet = wb.get_sheet_by_name(title);
TS_ASSERT_EQUALS(new_sheet, found_sheet); TS_ASSERT_EQUALS(new_sheet, found_sheet);
TS_ASSERT_THROWS(wb.get_sheet_by_name("error"), xlnt::key_error); 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() void test_get_sheet_by_name_const()

Binary file not shown.