[Libreoffice-commits] core.git: sc/qa sc/source

Tibor Nagy (via logerrit) logerrit at kemper.freedesktop.org
Wed Dec 16 19:53:28 UTC 2020


 sc/qa/unit/data/xlsx/tdf122102.xlsx    |binary
 sc/qa/unit/subsequent_filters-test.cxx |   38 +++++++++++++++++++++++++++++++++
 sc/source/filter/oox/extlstcontext.cxx |   13 ++++++++++-
 3 files changed, 50 insertions(+), 1 deletion(-)

New commits:
commit 0101975f8eac650bb87c4af81157cb33a6309e0e
Author:     Tibor Nagy <nagy.tibor2 at nisz.hu>
AuthorDate: Tue Dec 15 18:58:33 2020 +0100
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Wed Dec 16 20:52:45 2020 +0100

    tdf#122102 XLSX import: fix "contains" conditional formatting
    
    when using "Given text" type and cell reference
    with "contains text" or "not contains text" conditions.
    
    Co-authored-by: Attila Szűcs (NISZ)
    
    Change-Id: Ifbd34ef9f7ee948b6ac42a890bd52f3fb8486aec
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107791
    Tested-by: László Németh <nemeth at numbertext.org>
    Reviewed-by: László Németh <nemeth at numbertext.org>

diff --git a/sc/qa/unit/data/xlsx/tdf122102.xlsx b/sc/qa/unit/data/xlsx/tdf122102.xlsx
new file mode 100644
index 000000000000..bc1db82d78a7
Binary files /dev/null and b/sc/qa/unit/data/xlsx/tdf122102.xlsx differ
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 593c12c3e27a..b2b6247a7b3c 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -104,6 +104,7 @@ public:
     virtual void tearDown() override;
 
     //ods, xls, xlsx filter tests
+    void testExtCondFormatXLSX();
     void testUpdateCircleInMergedCellODS();
     void testDeleteCircleInMergedCellODS();
     void testBooleanFormatXLSX();
@@ -295,6 +296,7 @@ public:
     void testDeleteCirclesInRowAndCol();
 
     CPPUNIT_TEST_SUITE(ScFiltersTest);
+    CPPUNIT_TEST(testExtCondFormatXLSX);
     CPPUNIT_TEST(testUpdateCircleInMergedCellODS);
     CPPUNIT_TEST(testDeleteCircleInMergedCellODS);
     CPPUNIT_TEST(testBooleanFormatXLSX);
@@ -530,6 +532,42 @@ void testRangeNameImpl(const ScDocument& rDoc)
 
 }
 
+void ScFiltersTest::testExtCondFormatXLSX()
+{
+    ScDocShellRef xDocSh = loadDoc("tdf122102.", FORMAT_XLSX);
+    CPPUNIT_ASSERT_MESSAGE("Failed to load tdf122102.xlsx", xDocSh.is());
+
+    ScDocument& rDoc = xDocSh->GetDocument();
+
+    // contains text and not contains text conditions
+    ScConditionalFormat* pFormatA1 = rDoc.GetCondFormat(0, 0, 0);
+    CPPUNIT_ASSERT(pFormatA1);
+    ScConditionalFormat* pFormatA2 = rDoc.GetCondFormat(0, 1, 0);
+    CPPUNIT_ASSERT(pFormatA2);
+    ScConditionalFormat* pFormatA3 = rDoc.GetCondFormat(0, 2, 0);
+    CPPUNIT_ASSERT(pFormatA3);
+    ScConditionalFormat* pFormatA4 = rDoc.GetCondFormat(0, 3, 0);
+    CPPUNIT_ASSERT(pFormatA4);
+
+    ScRefCellValue aCellA1(rDoc, ScAddress(0, 0, 0));
+    OUString aCellStyleA1 = pFormatA1->GetCellStyle(aCellA1, ScAddress(0, 0, 0));
+    CPPUNIT_ASSERT(!aCellStyleA1.isEmpty());
+
+    ScRefCellValue aCellA2(rDoc, ScAddress(0, 1, 0));
+    OUString aCellStyleA2 = pFormatA2->GetCellStyle(aCellA2, ScAddress(0, 1, 0));
+    CPPUNIT_ASSERT(!aCellStyleA2.isEmpty());
+
+    ScRefCellValue aCellA3(rDoc, ScAddress(0, 2, 0));
+    OUString aCellStyleA3 = pFormatA3->GetCellStyle(aCellA3, ScAddress(0, 2, 0));
+    CPPUNIT_ASSERT(!aCellStyleA3.isEmpty());
+
+    ScRefCellValue aCellA4(rDoc, ScAddress(0, 3, 0));
+    OUString aCellStyleA4 = pFormatA4->GetCellStyle(aCellA4, ScAddress(0, 3, 0));
+    CPPUNIT_ASSERT(!aCellStyleA4.isEmpty());
+
+    xDocSh->DoClose();
+}
+
 void ScFiltersTest::testUpdateCircleInMergedCellODS()
 {
     ScDocShellRef xDocSh = loadDoc("updateCircleInMergedCell.", FORMAT_ODS);
diff --git a/sc/source/filter/oox/extlstcontext.cxx b/sc/source/filter/oox/extlstcontext.cxx
index fadb4365265b..b413e9e58029 100644
--- a/sc/source/filter/oox/extlstcontext.cxx
+++ b/sc/source/filter/oox/extlstcontext.cxx
@@ -135,6 +135,16 @@ ContextHandlerRef ExtConditionalFormattingContext::onCreateContext(sal_Int32 nEl
             eOperator =  CondFormatBuffer::convertToInternalOperator(aToken);
             return this;
         }
+        else if(aType == "containsText")
+        {
+            eOperator = ScConditionMode::ContainsText;
+            return this;
+        }
+        else if(aType == "notContainsText")
+        {
+            eOperator = ScConditionMode::NotContainsText;
+            return this;
+        }
         else
         {
             SAL_WARN("sc", "unhandled XLS14_TOKEN(cfRule) with type: " << aType);
@@ -181,7 +191,8 @@ void ExtConditionalFormattingContext::onEndElement()
     {
         case XM_TOKEN(f):
         {
-            rFormulas.push_back(aChars);
+            if(!aChars.startsWith("ISERROR(SEARCH(") && !aChars.startsWith("NOT(ISERROR(SEARCH("))
+               rFormulas.push_back(aChars);
         }
         break;
         case XLS14_TOKEN( cfRule ):


More information about the Libreoffice-commits mailing list