//This is what you asked for
xlnt::rgb_color get_cell_color(const xlnt::cell &cell) {
if (cell.fill().type() == xlnt::fill_type::pattern) {
xlnt::pattern_fill pattern = cell.fill().pattern_fill();
if (pattern.foreground().type() == xlnt::color_type::rgb) {
return pattern.foreground().rgb();
}
}
return xlnt::rgb_color(0, 0, 0); // Default to black if no color is found
}
//I took the function you used to fill, and I made it fit in a little bit better
void color_fill_cell(xlnt::cell &cell, const xlnt::rgb_color &rgb) {
cell.fill(xlnt::fill::solid(rgb));
}
字符串 现在我们有了这些函数,我们可以很容易地实现它们:
xlnt::worksheet ws = ; // Just plop your worksheet here
xlnt::cell source_cell = ws.cell("A1"); //Obv A1 is a placeholder
xlnt::rgb_color rgb = get_cell_color(source_cell);
xlnt::cell target_cell = ws.cell("B1"); //placeholder again
color_fill_cell(target_cell, rgb);
1条答案
按热度按时间yx2lnoni1#
最终,答案就在于使用
cell.fill().pattern_fill().foreground().rgb()
。这是检索颜色的最简单方法。然而,我也创建了您所描述的实现,只是作为示例。字符串
现在我们有了这些函数,我们可以很容易地实现它们:
型