create a static method in xlnt::fill to create a solid fill with a particular color to be the cell's background color

This commit is contained in:
Thomas Fussell 2016-10-29 12:17:22 -04:00
parent 3b17675bd1
commit 0f7dc72070
2 changed files with 16 additions and 0 deletions

View File

@ -163,6 +163,14 @@ enum class XLNT_API fill_type
class XLNT_API fill : public hashable
{
public:
/// <summary>
/// Helper method for the most common use case, setting the fill color of a cell to a single solid color.
/// The foreground and background colors of a fill are not the same as the foreground and background colors
/// of a cell. When setting a fill color in Excel, a new fill is created with the given color as the fill's
/// fgColor and index color number 64 as the bgColor. This method creates a fill in the same way.
/// </summary>
static fill solid(const color &fill_color);
/// <summary>
/// Constructs a fill initialized as a none-type pattern fill with no
/// foreground or background colors.

View File

@ -194,6 +194,14 @@ std::unordered_map<double, color> gradient_fill::stops() const
// fill
fill fill::solid(const color &fill_color)
{
return fill(xlnt::pattern_fill()
.type(xlnt::pattern_fill_type::solid)
.foreground(fill_color)
.background(indexed_color(64)));
}
fill::fill() : type_(fill_type::pattern)
{
}