sc/source/filter/inc/condformatbuffer.hxx |    1 +
 sc/source/filter/oox/condformatbuffer.cxx |   18 +++++++++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)

New commits:
commit b62e9fbf1ab54c9859852052aa94b332cd708ecd
Author:     Henry Castro <hcas...@collabora.com>
AuthorDate: Tue Mar 28 17:55:17 2023 -0400
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Wed Apr 12 18:55:34 2023 +0200

    sc: filter: oox: only insert conditional format if has items
    
    Otherwise, the empty conditional format will exists.
    
    Signed-off-by: Henry Castro <hcas...@collabora.com>
    Change-Id: I99d83bd50ce4c12ef9be6924cba31b8847c0ad07
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149720
    Reviewed-by: Andras Timar <andras.ti...@collabora.com>
    Tested-by: Andras Timar <andras.ti...@collabora.com>

diff --git a/sc/source/filter/inc/condformatbuffer.hxx 
b/sc/source/filter/inc/condformatbuffer.hxx
index 0ff7006ee439..3af8f6f3e474 100644
--- a/sc/source/filter/inc/condformatbuffer.hxx
+++ b/sc/source/filter/inc/condformatbuffer.hxx
@@ -201,6 +201,7 @@ class CondFormat final : public WorksheetHelper
 friend class CondFormatBuffer;
 public:
     explicit            CondFormat( const WorksheetHelper& rHelper );
+    ~CondFormat();
 
     /** Imports settings from the conditionalFormatting element. */
     void                importConditionalFormatting( const AttributeList& 
rAttribs );
diff --git a/sc/source/filter/oox/condformatbuffer.cxx 
b/sc/source/filter/oox/condformatbuffer.cxx
index 6a9b80482f3a..1b0cb2e5405e 100644
--- a/sc/source/filter/oox/condformatbuffer.cxx
+++ b/sc/source/filter/oox/condformatbuffer.cxx
@@ -1097,6 +1097,12 @@ CondFormat::CondFormat( const WorksheetHelper& rHelper ) 
:
 {
 }
 
+CondFormat::~CondFormat()
+{
+    if (!mbReadyForFinalize && mpFormat)
+        delete mpFormat;
+}
+
 void CondFormat::importConditionalFormatting( const AttributeList& rAttribs )
 {
     getAddressConverter().convertToCellRangeList( maModel.maRanges, 
rAttribs.getString( XML_sqref, OUString() ), getSheetIndex(), true );
@@ -1135,10 +1141,16 @@ void CondFormat::finalizeImport()
     ScDocument& rDoc = getScDocument();
     mpFormat->SetRange(maModel.maRanges);
     maRules.forEachMem( &CondFormatRule::finalizeImport );
-    SCTAB nTab = maModel.maRanges.GetTopLeftCorner().Tab();
-    sal_Int32 nIndex = 
getScDocument().AddCondFormat(std::unique_ptr<ScConditionalFormat>(mpFormat), 
nTab);
 
-    rDoc.AddCondFormatData( maModel.maRanges, nTab, nIndex );
+    if (mpFormat->size() > 0)
+    {
+        SCTAB nTab = maModel.maRanges.GetTopLeftCorner().Tab();
+        sal_Int32 nIndex = 
getScDocument().AddCondFormat(std::unique_ptr<ScConditionalFormat>(mpFormat), 
nTab);
+
+        rDoc.AddCondFormatData( maModel.maRanges, nTab, nIndex );
+    }
+    else
+        mbReadyForFinalize = false;
 }
 
 CondFormatRuleRef CondFormat::createRule()

Reply via email to