mirror of
https://github.com/troldal/OpenXLSX.git
synced 2025-05-09 02:11:09 +08:00
2024-12-18 XLStyles XLDataBarColor::setTheme now supports value XLDeleteProperty to clear a theme
This commit is contained in:
parent
bf5fe8a27e
commit
53419c7dcc
@ -222,8 +222,9 @@ int main( int argc, char *argv[] )
|
||||
// ===== BEGIN cell borders demo
|
||||
{
|
||||
// create a new cell format based on the current C3 format & assign it back to C3
|
||||
XLStyleIndex borderedCellFormat = cellFormats.create( cellFormats[ wks.cell("C3").cellFormat() ] );
|
||||
wks.cell("C3").setCellFormat( borderedCellFormat );
|
||||
XLStyleIndex borderedCellFormat = cellFormats.create( cellFormats[ wks.cell("C7").cellFormat() ] );
|
||||
wks.cell("C7").setCellFormat( borderedCellFormat );
|
||||
wks.cell("C7") = "borders demo";
|
||||
|
||||
// create a new border format style & assign it to the new cell format
|
||||
XLStyleIndex borderFormat = borders.create( borders[ cellFormats[ borderedCellFormat ].borderIndex() ] );
|
||||
@ -239,6 +240,35 @@ int main( int argc, char *argv[] )
|
||||
borders[ borderFormat ].setDiagonal ( XLLineStyleThick, XLColor( "ff332222" ), -0.25 );
|
||||
borders[ borderFormat ].setVertical ( XLLineStyleDouble, XLColor( "ff443322" ) );
|
||||
borders[ borderFormat ].setHorizontal( XLLineStyleHair, XLColor( "ff446688" ) );
|
||||
std::cout << "#1 borders[ " << borderFormat << " ] summary: " << borders[ borderFormat ].summary() << std::endl;
|
||||
|
||||
// test additional line styles with setter function:
|
||||
borders[ borderFormat ].setLine ( XLLineLeft, XLLineStyleMediumDashed, XLColor( XLDefaultFontColor ) );
|
||||
borders[ borderFormat ].setLine ( XLLineRight, XLLineStyleDashDot, XLColor( XLDefaultFontColor ), 1.0 );
|
||||
borders[ borderFormat ].setLine ( XLLineTop, XLLineStyleMediumDashDot, green );
|
||||
borders[ borderFormat ].setLine ( XLLineBottom, XLLineStyleDashDotDot, XLColor( XLDefaultFontColor ), -0.1 );
|
||||
borders[ borderFormat ].setLine ( XLLineDiagonal, XLLineStyleMediumDashDotDot, XLColor( XLDefaultFontColor ), -1.0 );
|
||||
borders[ borderFormat ].setLine ( XLLineVertical, XLLineStyleSlantDashDot, XLColor( XLDefaultFontColor ) );
|
||||
std::cout << "#2 borders[ " << borderFormat << " ] summary: " << borders[ borderFormat ].summary() << std::endl;
|
||||
|
||||
// test direct access to line properties (read: the XLDataBarColor)
|
||||
XLLine leftLine = borders[ borderFormat ].left();
|
||||
XLDataBarColor leftLineColor = leftLine.color();
|
||||
leftLineColor.setRgb( blue );
|
||||
leftLineColor.setTint( -0.2 );
|
||||
leftLineColor.setAutomatic();
|
||||
leftLineColor.setIndexed( 606 );
|
||||
leftLineColor.setTheme( 707 );
|
||||
std::cout << "#2 borders, leftLine summary: " << leftLine.summary() << std::endl;
|
||||
// unset some properties
|
||||
leftLineColor.setTint( -0.1 );
|
||||
leftLineColor.setAutomatic( false );
|
||||
leftLineColor.setIndexed( 0 );
|
||||
leftLineColor.setTheme( XLDeleteProperty );
|
||||
// NOTE: XLDeleteProperty can be used to remove a property from XML where a value of 0 would not accomplish the same
|
||||
// formatting. Currently, only XLDataBarColor::setTheme supports this functionality. More can be added as properties
|
||||
// are discovered that have the same problem (theme="" still overrides e.g. the line color)
|
||||
std::cout << "#2 borders, leftLineColor summary: " << leftLineColor.summary() << std::endl;
|
||||
}
|
||||
// ===== END cell borders demo ===== //
|
||||
|
||||
@ -309,43 +339,6 @@ int main( int argc, char *argv[] )
|
||||
// output summary of newly created style
|
||||
std::cout << "fills[ " << nodeIndex << " ] summary: " << fills[ nodeIndex ].summary() << std::endl;
|
||||
|
||||
nodeIndex = ( createAll ? borders.create() : borders.count() - 1 );
|
||||
borders[ nodeIndex ].setDiagonalUp( false );
|
||||
borders[ nodeIndex ].setDiagonalDown( true );
|
||||
borders[ nodeIndex ].setOutline( true );
|
||||
borders[ nodeIndex ].setLeft ( XLLineStyleThin, XLColor( "ff112222" ) );
|
||||
borders[ nodeIndex ].setRight ( XLLineStyleMedium, XLColor( "ff113333" ) );
|
||||
borders[ nodeIndex ].setTop ( XLLineStyleDashed, XLColor( "ff114444" ) );
|
||||
borders[ nodeIndex ].setBottom ( XLLineStyleDotted, XLColor( "ff222222" ), 0.25 );
|
||||
borders[ nodeIndex ].setDiagonal ( XLLineStyleThick, XLColor( "ff332222" ), -0.25 );
|
||||
borders[ nodeIndex ].setVertical ( XLLineStyleDouble, XLColor( "ff443322" ) );
|
||||
borders[ nodeIndex ].setHorizontal( XLLineStyleHair, XLColor( "ff446688" ) );
|
||||
std::cout << "#1 borders[ " << nodeIndex << " ] summary: " << borders[ nodeIndex ].summary() << std::endl;
|
||||
|
||||
// test additional line styles with setter function:
|
||||
borders[ nodeIndex ].setLine ( XLLineLeft, XLLineStyleMediumDashed, XLColor( XLDefaultFontColor ) );
|
||||
borders[ nodeIndex ].setLine ( XLLineRight, XLLineStyleDashDot, XLColor( XLDefaultFontColor ), 1.0 );
|
||||
borders[ nodeIndex ].setLine ( XLLineTop, XLLineStyleMediumDashDot, XLColor( XLDefaultFontColor ) );
|
||||
borders[ nodeIndex ].setLine ( XLLineBottom, XLLineStyleDashDotDot, XLColor( XLDefaultFontColor ), -0.1 );
|
||||
borders[ nodeIndex ].setLine ( XLLineDiagonal, XLLineStyleMediumDashDotDot, XLColor( XLDefaultFontColor ), -1.0 );
|
||||
borders[ nodeIndex ].setLine ( XLLineVertical, XLLineStyleSlantDashDot, XLColor( XLDefaultFontColor ) );
|
||||
std::cout << "#2 borders[ " << nodeIndex << " ] summary: " << borders[ nodeIndex ].summary() << std::endl;
|
||||
|
||||
// test direct access to line properties (read: the XLDataBarColor)
|
||||
XLLine leftLine = borders[ nodeIndex ].left();
|
||||
XLDataBarColor leftLineColor = leftLine.color();
|
||||
leftLineColor.setRgb( blue );
|
||||
leftLineColor.setTint( -0.2 );
|
||||
leftLineColor.setAutomatic();
|
||||
leftLineColor.setIndexed( 606 );
|
||||
leftLineColor.setTheme( 707 );
|
||||
std::cout << "#2 borders, leftLine summary: " << leftLine.summary() << std::endl;
|
||||
// unset some properties
|
||||
leftLineColor.setTint( 0 );
|
||||
leftLineColor.setAutomatic( false );
|
||||
leftLineColor.setIndexed( 0 );
|
||||
leftLineColor.setTheme( 0 );
|
||||
std::cout << "#2 borders, leftLineColor summary: " << leftLineColor.summary() << std::endl;
|
||||
|
||||
nodeIndex = ( createAll ? cellStyleFormats.create() : cellStyleFormats.count() - 1 );
|
||||
cellStyleFormats[ nodeIndex ].setNumberFormatId( 5 );
|
||||
|
@ -69,6 +69,9 @@ namespace OpenXLSX
|
||||
|
||||
constexpr const uint32_t XLInvalidUInt16 = 0xffff; // used to signal "value not defined" for uint16_t return types
|
||||
constexpr const uint32_t XLInvalidUInt32 = 0xffffffff; // used to signal "value not defined" for uint32_t return types
|
||||
constexpr const uint32_t XLDeleteProperty = XLInvalidUInt32; // when 0 or "" is not the same as "property does not exist", this value
|
||||
// // can be passed to setter functions to delete the property from XML
|
||||
// // currently supported in: XLDataBarColor::setTheme
|
||||
|
||||
constexpr const bool XLPermitXfID = true; // use with XLCellFormat constructor to enable xfId() getter and setXfId() setter
|
||||
|
||||
|
@ -402,7 +402,7 @@ namespace // anonymous namespace for module local functions
|
||||
{
|
||||
if (node.empty()) return XMLAttribute{};
|
||||
XMLAttribute attr = node.attribute(attrName.c_str());
|
||||
if (attr.empty() && not node.empty()) {
|
||||
if (attr.empty()) {
|
||||
attr = node.append_attribute(attrName.c_str());
|
||||
attr.set_value(attrDefaultVal.c_str());
|
||||
}
|
||||
@ -413,7 +413,7 @@ namespace // anonymous namespace for module local functions
|
||||
{
|
||||
if (node.empty()) return XMLAttribute{};
|
||||
XMLAttribute attr = node.attribute(attrName.c_str());
|
||||
if (attr.empty() && not node.empty())
|
||||
if (attr.empty())
|
||||
attr = node.append_attribute(attrName.c_str());
|
||||
attr.set_value(attrVal.c_str()); // silently fails on empty attribute, which is intended here
|
||||
return attr;
|
||||
@ -978,7 +978,10 @@ bool XLDataBarColor::setTint(double newTint)
|
||||
}
|
||||
bool XLDataBarColor::setAutomatic(bool set) { return appendAndSetAttribute(*m_colorNode, "auto", (set ? "true" : "false") ).empty() == false; }
|
||||
bool XLDataBarColor::setIndexed(uint32_t newIndex) { return appendAndSetAttribute(*m_colorNode, "indexed", std::to_string(newIndex) ).empty() == false; }
|
||||
bool XLDataBarColor::setTheme(uint32_t newTheme) { return appendAndSetAttribute(*m_colorNode, "theme", std::to_string(newTheme) ).empty() == false; }
|
||||
bool XLDataBarColor::setTheme(uint32_t newTheme) {
|
||||
if( newTheme == XLDeleteProperty ) return m_colorNode->remove_attribute("theme");
|
||||
return appendAndSetAttribute(*m_colorNode, "theme", std::to_string(newTheme) ).empty() == false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @details assemble a string summary about the color
|
||||
|
@ -10,6 +10,9 @@ As the heading says - the latest "Release" that is shown on https://github.com/t
|
||||
## (aral-matrix) 18 December 2024 - Bugfix for Issue #283 - shared strings cache was not cleared upon XLDocument::Close
|
||||
* BUGFIX XLDocument::close: shared strings cache is now being cleared on doc close, this addresses issue #283
|
||||
* zippy.hpp minor bugfix in ZipArchive::Close: m_IsOpen was not set to false
|
||||
* Demo10: improved borders demo
|
||||
* XLStyles: XLDataBarColor::setTheme now supports parameter ```XLDeleteProperty == XLInvalidUInt32 == 0xffffffff``` to delete the theme attribute from XML. This was necessary because even an empty ```theme=""``` attribute affects formatting.
|
||||
* XLStyles appendAndGetAttribute / appendAndSetAttribute: removed a redundant check for ```not node.empty()```
|
||||
|
||||
## (aral-matrix) 17 December 2024 - Added exemplary use of XLBorder to Examples/Demo10.cpp
|
||||
* in response to #309, added use of XLBorder to Demo10
|
||||
|
Loading…
x
Reference in New Issue
Block a user