summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTünde Tóth <toth.tunde@nisz.hu>2021-03-24 14:07:15 +0100
committerGabor Kelemen <kelemen.gabor2@nisz.hu>2021-04-30 12:18:42 +0200
commitbbf341069078701abb22fa1598dbd186c1185e62 (patch)
tree348c1da583026e81e1a3ceea4595e98297dcc1ee
parenttdf#117212 sw mailmerge: merge only the selected range (diff)
downloadcore-bbf341069078701abb22fa1598dbd186c1185e62.tar.gz
core-bbf341069078701abb22fa1598dbd186c1185e62.zip
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@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113382 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org> (cherry picked from commit adef1cc017517882f4630e31fa643102c21faad0) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114914 Tested-by: Gabor Kelemen <kelemen.gabor2@nisz.hu> Reviewed-by: Gabor Kelemen <kelemen.gabor2@nisz.hu>
-rw-r--r--sc/inc/document.hxx2
-rw-r--r--sc/qa/unit/uicalc/data/tdf99913.xlsxbin0 -> 8829 bytes
-rw-r--r--sc/qa/unit/uicalc/uicalc.cxx9
-rw-r--r--sc/source/filter/oox/worksheethelper.cxx65
4 files changed, 66 insertions, 10 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index fa13d9bae60e..f3af1b1be236 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1943,7 +1943,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
--- /dev/null
+++ b/sc/qa/unit/uicalc/data/tdf99913.xlsx
Binary files differ
diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx
index d19103d0d261..6b774cfe988f 100644
--- a/sc/qa/unit/uicalc/uicalc.cxx
+++ b/sc/qa/unit/uicalc/uicalc.cxx
@@ -256,6 +256,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 5fc46ecbfd30..29c661537218 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