[Libreoffice-commits] core.git: Branch 'libreoffice-7-1' - sc/inc sc/qa sc/source

Tünde Tóth (via logerrit) logerrit at kemper.freedesktop.org
Tue Apr 6 10:42:31 UTC 2021


 sc/inc/document.hxx                      |    2 
 sc/qa/unit/uicalc/data/tdf99913.xlsx     |binary
 sc/qa/unit/uicalc/uicalc.cxx             |    9 ++++
 sc/source/filter/oox/worksheethelper.cxx |   65 ++++++++++++++++++++++++++-----
 4 files changed, 66 insertions(+), 10 deletions(-)

New commits:
commit adef1cc017517882f4630e31fa643102c21faad0
Author:     Tünde Tóth <toth.tunde at nisz.hu>
AuthorDate: Wed Mar 24 14:07:15 2021 +0100
Commit:     Xisco Fauli <xiscofauli at libreoffice.org>
CommitDate: Tue Apr 6 12:41:56 2021 +0200

    tdf#99913 XLSX import: set filtered flag for rows
    
    hidden by AutoFilter to support copying the
    result of filtering. Unlike ODS and XLS,
    XLSX doesn't differentiates filtered and
    manually hidden rows, and without this fix,
    copy of the unupdated data of the loaded
    filtering contained the hidden rows, too.
    
    Change-Id: I390d1a84b9bf275f3d3782756553b2f236487758
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113040
    Tested-by: László Németh <nemeth at numbertext.org>
    Reviewed-by: László Németh <nemeth at numbertext.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113382
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofauli at libreoffice.org>

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 46f3e51d1a99..832a02410eed 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1947,7 +1947,7 @@ public:
     SC_DLLPUBLIC SCROW          LastVisibleRow(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) const;
     SCROW                       CountVisibleRows(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) const;
 
-    bool                        RowFiltered(SCROW nRow, SCTAB nTab, SCROW* pFirstRow = nullptr, SCROW* pLastRow = nullptr) const;
+    SC_DLLPUBLIC bool           RowFiltered(SCROW nRow, SCTAB nTab, SCROW* pFirstRow = nullptr, SCROW* pLastRow = nullptr) const;
     bool                        HasFilteredRows(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) const;
     bool                        ColFiltered(SCCOL nCol, SCTAB nTab) const;
     SC_DLLPUBLIC void           SetRowFiltered(SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bFiltered);
diff --git a/sc/qa/unit/uicalc/data/tdf99913.xlsx b/sc/qa/unit/uicalc/data/tdf99913.xlsx
new file mode 100644
index 000000000000..3fd18a12984a
Binary files /dev/null and b/sc/qa/unit/uicalc/data/tdf99913.xlsx differ
diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx
index c744528b8e0e..59edd0527c4e 100644
--- a/sc/qa/unit/uicalc/uicalc.cxx
+++ b/sc/qa/unit/uicalc/uicalc.cxx
@@ -364,6 +364,15 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf123202)
     CPPUNIT_ASSERT(pDoc->RowHidden(2, 0));
 }
 
+CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf99913)
+{
+    ScModelObj* pModelObj = createDoc("tdf99913.xlsx");
+    ScDocument* pDoc = pModelObj->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+
+    CPPUNIT_ASSERT(pDoc->RowFiltered(2, 0));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx
index 110ce64ba79c..93b6fe88f429 100644
--- a/sc/source/filter/oox/worksheethelper.cxx
+++ b/sc/source/filter/oox/worksheethelper.cxx
@@ -68,6 +68,8 @@
 #include <stlsheet.hxx>
 #include <stlpool.hxx>
 #include <cellvalue.hxx>
+#include <columnspanset.hxx>
+#include <dbdata.hxx>
 
 #include <svl/stritem.hxx>
 #include <editeng/eeitem.hxx>
@@ -340,9 +342,12 @@ private:
     void                convertColumns( OutlineLevelVec& orColLevels, const ValueRange& rColRange, const ColumnModel& rModel );
 
     /** Converts row properties for all rows in the sheet. */
-    void                convertRows();
+    void                convertRows(const std::vector<sc::ColRowSpan>& rSpans);
     /** Converts row properties. */
-    void                convertRows( OutlineLevelVec& orRowLevels, const ValueRange& rRowRange, const RowModel& rModel, double fDefHeight = -1.0 );
+    void                convertRows(OutlineLevelVec& orRowLevels, const ValueRange& rRowRange,
+                                    const RowModel& rModel,
+                                    const std::vector<sc::ColRowSpan>& rSpans,
+                                    double fDefHeight = -1.0);
 
     /** Converts outline grouping for the passed column or row. */
     void                convertOutlines( OutlineLevelVec& orLevels, sal_Int32 nColRow, sal_Int32 nLevel, bool bCollapsed, bool bRows );
@@ -946,7 +951,37 @@ void WorksheetGlobals::finalizeWorksheetImport()
 
     lclUpdateProgressBar( mxFinalProgress, 0.5 );
     convertColumns();
-    convertRows();
+
+    // tdf#99913 rows hidden by filter need extra flag
+    ScDocument& rDoc = getScDocument();
+    std::vector<sc::ColRowSpan> aSpans;
+    SCTAB nTab = getSheetIndex();
+    ScDBData* pDBData = rDoc.GetAnonymousDBData(nTab);
+    if (pDBData && pDBData->HasAutoFilter())
+    {
+        ScRange aRange;
+        pDBData->GetArea(aRange);
+        SCCOLROW nStartRow = static_cast<SCCOLROW>(aRange.aStart.Row());
+        SCCOLROW nEndRow = static_cast<SCCOLROW>(aRange.aEnd.Row());
+        aSpans.push_back(sc::ColRowSpan(nStartRow, nEndRow));
+    }
+    ScDBCollection* pDocColl = rDoc.GetDBCollection();
+    if (!pDocColl->empty())
+    {
+        ScDBCollection::NamedDBs& rDBs = pDocColl->getNamedDBs();
+        for (const auto& rxDB : rDBs)
+        {
+            if (rxDB->GetTab() == nTab && rxDB->HasAutoFilter())
+            {
+                ScRange aRange;
+                rxDB->GetArea(aRange);
+                SCCOLROW nStartRow = static_cast<SCCOLROW>(aRange.aStart.Row());
+                SCCOLROW nEndRow = static_cast<SCCOLROW>(aRange.aEnd.Row());
+                aSpans.push_back(sc::ColRowSpan(nStartRow, nEndRow));
+            }
+        }
+    }
+    convertRows(aSpans);
     lclUpdateProgressBar( mxFinalProgress, 1.0 );
 }
 
@@ -1200,7 +1235,7 @@ void WorksheetGlobals::convertColumns( OutlineLevelVec& orColLevels,
     convertOutlines( orColLevels, rColRange.mnFirst, rModel.mnLevel, rModel.mbCollapsed, false );
 }
 
-void WorksheetGlobals::convertRows()
+void WorksheetGlobals::convertRows(const std::vector<sc::ColRowSpan>& rSpans)
 {
     sal_Int32 nNextRow = 0;
     sal_Int32 nMaxRow = mrMaxApiPos.Row();
@@ -1213,21 +1248,23 @@ void WorksheetGlobals::convertRows()
         ValueRange aRowRange( ::std::max( rowModel.first, nNextRow ), ::std::min( rowModel.second.second, nMaxRow ) );
         // process gap between two row models, use default row model
         if( nNextRow < aRowRange.mnFirst )
-            convertRows( aRowLevels, ValueRange( nNextRow, aRowRange.mnFirst - 1 ), maDefRowModel );
+            convertRows(aRowLevels, ValueRange(nNextRow, aRowRange.mnFirst - 1), maDefRowModel,
+                        rSpans);
         // process the row model
-        convertRows( aRowLevels, aRowRange, rowModel.second.first, maDefRowModel.mfHeight );
+        convertRows(aRowLevels, aRowRange, rowModel.second.first, rSpans, maDefRowModel.mfHeight);
         // cache next row to be processed
         nNextRow = aRowRange.mnLast + 1;
     }
 
     // remaining default rows to end of sheet
-    convertRows( aRowLevels, ValueRange( nNextRow, nMaxRow ), maDefRowModel );
+    convertRows(aRowLevels, ValueRange(nNextRow, nMaxRow), maDefRowModel, rSpans);
     // close remaining row outlines spanning to end of sheet
     convertOutlines( aRowLevels, nMaxRow + 1, 0, false, true );
 }
 
-void WorksheetGlobals::convertRows( OutlineLevelVec& orRowLevels,
-        const ValueRange& rRowRange, const RowModel& rModel, double fDefHeight )
+void WorksheetGlobals::convertRows(OutlineLevelVec& orRowLevels, const ValueRange& rRowRange,
+                                   const RowModel& rModel,
+                                   const std::vector<sc::ColRowSpan>& rSpans, double fDefHeight)
 {
     // row height: convert points to row height in 1/100 mm
     double fHeight = (rModel.mfHeight >= 0.0) ? rModel.mfHeight : fDefHeight;
@@ -1249,6 +1286,16 @@ void WorksheetGlobals::convertRows( OutlineLevelVec& orRowLevels,
     {
         ScDocument& rDoc = getScDocument();
         rDoc.SetRowHidden( nStartRow, nEndRow, nTab, true );
+        for (const auto& rSpan : rSpans)
+        {
+            // tdf#99913 rows hidden by filter need extra flag
+            if (rSpan.mnStart <= nStartRow && nStartRow <= rSpan.mnEnd)
+            {
+                SCROW nLast = ::std::min(nEndRow, rSpan.mnEnd);
+                rDoc.SetRowFiltered(nStartRow, nLast, nTab, true);
+                break;
+            }
+        }
     }
 
     // outline settings for this row range


More information about the Libreoffice-commits mailing list