[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sc/source

Markus Mohrhard (via logerrit) logerrit at kemper.freedesktop.org
Fri May 10 06:25:56 UTC 2019


 sc/source/filter/excel/xecontent.cxx |   64 ++++++++++++++++++++++++++++-------
 1 file changed, 53 insertions(+), 11 deletions(-)

New commits:
commit 0420bf0da699493c91164cdd8b9f8fe488f0fb67
Author:     Markus Mohrhard <markus.mohrhard at googlemail.com>
AuthorDate: Sat Jul 14 23:56:44 2018 +0200
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Fri May 10 08:25:23 2019 +0200

    related tdf#117816, add more work arounds for MS Excel bugs
    
    Another set of cases where MS Excel needs the formula.
    
    Change-Id: I58344a540ad69ff9b8c56aa817730079bd011acd
    Reviewed-on: https://gerrit.libreoffice.org/57443
    Tested-by: Jenkins
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
    (cherry picked from commit 6df45ae3a85b21d984605a6656282e5feaf8dea9)
    Reviewed-on: https://gerrit.libreoffice.org/72006
    Reviewed-by: Andras Timar <andras.timar at collabora.com>
    Tested-by: Andras Timar <andras.timar at collabora.com>

diff --git a/sc/source/filter/excel/xecontent.cxx b/sc/source/filter/excel/xecontent.cxx
index eda436ad1b84..9c90d2d1c1bb 100644
--- a/sc/source/filter/excel/xecontent.cxx
+++ b/sc/source/filter/excel/xecontent.cxx
@@ -939,6 +939,50 @@ bool IsTextRule(ScConditionMode eMode)
     return false;
 }
 
+bool RequiresFixedFormula(ScConditionMode eMode)
+{
+    switch(eMode)
+    {
+        case ScConditionMode::NoError:
+        case ScConditionMode::Error:
+        case ScConditionMode::BeginsWith:
+        case ScConditionMode::EndsWith:
+        case ScConditionMode::ContainsText:
+        case ScConditionMode::NotContainsText:
+            return true;
+        default:
+        break;
+    }
+
+    return false;
+}
+
+OString GetFixedFormula(ScConditionMode eMode, const ScAddress& rAddress, const OString& rText)
+{
+    OStringBuffer aBuffer;
+    OStringBuffer aPosBuffer = XclXmlUtils::ToOString(aBuffer, rAddress);
+    OString aPos = aPosBuffer.makeStringAndClear();
+    switch (eMode)
+    {
+        case ScConditionMode::Error:
+            return "";
+        case ScConditionMode::NoError:
+            return "";
+        case ScConditionMode::BeginsWith:
+            return OString("LEFT(" + aPos + ",LEN(\"" + rText + "\"))=\"" + rText + "\"");
+        case ScConditionMode::EndsWith:
+            return OString("RIGHT(" + aPos +",LEN(\"" + rText + "\"))=\"" + rText + "\"");
+        case ScConditionMode::ContainsText:
+            return OString("NOT(ISERROR(SEARCH(\"" + rText + "\"," + aPos + ")))");
+        case ScConditionMode::NotContainsText:
+            return OString("ISERROR(SEARCH(\"" +  rText + "\"," + aPos + "))");
+        default:
+        break;
+    }
+
+    return OString("");
+}
+
 }
 
 void XclExpCFImpl::SaveXml( XclExpXmlStream& rStrm )
@@ -984,7 +1028,15 @@ void XclExpCFImpl::SaveXml( XclExpXmlStream& rStrm )
             XML_text, aText.getStr(),
             XML_dxfId, OString::number( GetDxfs().GetDxfId( mrFormatEntry.GetStyle() ) ).getStr(),
             FSEND );
-    if(!IsTextRule(eOperation) && !IsTopBottomRule(eOperation))
+
+    if (RequiresFixedFormula(eOperation))
+    {
+        rWorksheet->startElement( XML_formula, FSEND );
+        OString aFormula = GetFixedFormula(eOperation, mrFormatEntry.GetValidSrcPos(), aText);
+        rWorksheet->writeEscaped(aFormula.getStr());
+        rWorksheet->endElement( XML_formula );
+    }
+    else if(!IsTextRule(eOperation) && !IsTopBottomRule(eOperation))
     {
         rWorksheet->startElement( XML_formula, FSEND );
         std::unique_ptr<ScTokenArray> pTokenArray(mrFormatEntry.CreateFlatCopiedTokenArray(0));
@@ -1000,16 +1052,6 @@ void XclExpCFImpl::SaveXml( XclExpXmlStream& rStrm )
             rWorksheet->endElement( XML_formula );
         }
     }
-    else if (IsTextRule(eOperation))
-    {
-        OStringBuffer aBufferOld;
-        OStringBuffer aBuffer = XclXmlUtils::ToOString(aBufferOld, mrFormatEntry.GetValidSrcPos());
-        OString aTextTopCell = aBuffer.makeStringAndClear();
-        OString aFormula = "NOT(ISERROR(SEARCH(\"" + aText + "\"," + aTextTopCell + ")))";
-        rWorksheet->startElement( XML_formula, FSEND );
-        rWorksheet->writeEscaped(aFormula.getStr());
-        rWorksheet->endElement( XML_formula );
-    }
     // OOXTODO: XML_extLst
     rWorksheet->endElement( XML_cfRule );
 }


More information about the Libreoffice-commits mailing list