diff options
author | Balazs Varga <balazs.varga991@gmail.com> | 2021-05-06 18:47:30 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2021-05-10 12:39:38 +0200 |
commit | 3cd6402c5443c8069c07d9e420d5ef5b43af6bef (patch) | |
tree | a51e7afaa690b0044963653193a6d0a9fd986aef /sc | |
parent | a25c9a2925e64f3adb46a749ce18393aa01b1870 (diff) |
tdf#127301 XLSX import: hide hidden named range of autofilter
Create but not insert/add hidden FILTER_CRITERIA (_xlnm._FilterDatabase)
to ScRangeName, because no need for them, so avoid of creating
extra named ranges by autofilter re-range (shown in Sheet ->
Named Ranges and Expressions -> Manage...).
See also commit 3a2263a20629b0a3e9b4935dd43dc59817d0241c
"mib17: #163146# XLS import: do not skip hidden names[...]".
Change-Id: Ibfd86942a99b251a59394955bc890e6dbe0390f3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115189
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/unit/data/xlsx/autofilternamedrange.xlsx | bin | 0 -> 9685 bytes | |||
-rw-r--r-- | sc/qa/unit/subsequent_filters-test.cxx | 23 | ||||
-rw-r--r-- | sc/source/filter/inc/workbookhelper.hxx | 4 | ||||
-rw-r--r-- | sc/source/filter/oox/defnamesbuffer.cxx | 11 | ||||
-rw-r--r-- | sc/source/filter/oox/workbookhelper.cxx | 25 |
5 files changed, 45 insertions, 18 deletions
diff --git a/sc/qa/unit/data/xlsx/autofilternamedrange.xlsx b/sc/qa/unit/data/xlsx/autofilternamedrange.xlsx Binary files differnew file mode 100644 index 000000000000..51490d9229ea --- /dev/null +++ b/sc/qa/unit/data/xlsx/autofilternamedrange.xlsx diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx index 0d8e08fd1813..4529a123edb8 100644 --- a/sc/qa/unit/subsequent_filters-test.cxx +++ b/sc/qa/unit/subsequent_filters-test.cxx @@ -317,6 +317,7 @@ public: void testDeleteCirclesInRowAndCol(); void testTdf129940(); void testTdf139763ShapeAnchor(); + void testAutofilterNamedRangesXLSX(); CPPUNIT_TEST_SUITE(ScFiltersTest); CPPUNIT_TEST(testCondFormatOperatorsSameRangeXLSX); @@ -517,6 +518,7 @@ public: CPPUNIT_TEST(testDeleteCirclesInRowAndCol); CPPUNIT_TEST(testTdf129940); CPPUNIT_TEST(testTdf139763ShapeAnchor); + CPPUNIT_TEST(testAutofilterNamedRangesXLSX); CPPUNIT_TEST_SUITE_END(); @@ -5795,6 +5797,27 @@ void ScFiltersTest::testTdf139763ShapeAnchor() xDocSh->DoClose(); } +void ScFiltersTest::testAutofilterNamedRangesXLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"autofilternamedrange.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to load autofilternamedrange.xlsx", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + const ScDBData* pDBData = rDoc.GetDBCollection()->GetDBNearCursor(0, 0, 0); + CPPUNIT_ASSERT(pDBData); + ScRange aRange; + pDBData->GetArea(aRange); + CPPUNIT_ASSERT_EQUAL(ScRange(0, 0, 0, 0, 3, 0), aRange); + OUString aPosStr; + bool bSheetLocal = false; + // test there is no '_xlnm._FilterDatabase' named range on the filter area + const ScRangeData* pRData = rDoc.GetRangeAtBlock(aRange, aPosStr, &bSheetLocal); + CPPUNIT_ASSERT(!pRData); + CPPUNIT_ASSERT_EQUAL(OUString(), aPosStr); + + xDocSh->DoClose(); +} + ScFiltersTest::ScFiltersTest() : ScBootstrapFixture( "sc/qa/unit/data" ) { diff --git a/sc/source/filter/inc/workbookhelper.hxx b/sc/source/filter/inc/workbookhelper.hxx index 4491dcbb084f..e6633d15f4f9 100644 --- a/sc/source/filter/inc/workbookhelper.hxx +++ b/sc/source/filter/inc/workbookhelper.hxx @@ -167,7 +167,7 @@ public: OUString& orName, const css::uno::Sequence< css::sheet::FormulaToken>& rTokens, sal_Int32 nIndex, - sal_Int32 nNameFlags ) const; + sal_Int32 nNameFlags, bool bHidden ) const; /** Creates and returns a defined name on-the-fly in the sheet. The name will not be buffered in the global defined names buffer. @@ -176,7 +176,7 @@ public: OUString& orName, const css::uno::Sequence< css::sheet::FormulaToken>& rTokens, sal_Int32 nIndex, - sal_Int32 nNameFlags, sal_Int32 nTab ) const; + sal_Int32 nNameFlags, sal_Int32 nTab, bool bHidden ) const; /** Creates and returns a database range on-the-fly in the Calc document. The range will not be buffered in the global table buffer. diff --git a/sc/source/filter/oox/defnamesbuffer.cxx b/sc/source/filter/oox/defnamesbuffer.cxx index 733d4790f8ff..5f1bc1c01bf4 100644 --- a/sc/source/filter/oox/defnamesbuffer.cxx +++ b/sc/source/filter/oox/defnamesbuffer.cxx @@ -225,16 +225,17 @@ void DefinedName::createNameObject( sal_Int32 nIndex ) using namespace ::com::sun::star::sheet::NamedRangeFlag; if( !isGlobalName() ) switch( mcBuiltinId ) { - case BIFF_DEFNAME_CRITERIA: nNameFlags = FILTER_CRITERIA; break; - case BIFF_DEFNAME_PRINTAREA: nNameFlags = PRINT_AREA; break; - case BIFF_DEFNAME_PRINTTITLES: nNameFlags = COLUMN_HEADER | ROW_HEADER; break; + case BIFF_DEFNAME_CRITERIA: + case BIFF_DEFNAME_FILTERDATABASE: nNameFlags = FILTER_CRITERIA; break; + case BIFF_DEFNAME_PRINTAREA: nNameFlags = PRINT_AREA; break; + case BIFF_DEFNAME_PRINTTITLES: nNameFlags = COLUMN_HEADER | ROW_HEADER; break; } // create the name and insert it into the document, maCalcName will be changed to the resulting name if (maModel.mnSheet >= 0) - mpScRangeData = createLocalNamedRangeObject( maCalcName, ApiTokenSequence(), nIndex, nNameFlags, maModel.mnSheet ); + mpScRangeData = createLocalNamedRangeObject( maCalcName, ApiTokenSequence(), nIndex, nNameFlags, maModel.mnSheet, maModel.mbHidden ); else - mpScRangeData = createNamedRangeObject( maCalcName, ApiTokenSequence(), nIndex, nNameFlags ); + mpScRangeData = createNamedRangeObject( maCalcName, ApiTokenSequence(), nIndex, nNameFlags, maModel.mbHidden ); mnTokenIndex = nIndex; } diff --git a/sc/source/filter/oox/workbookhelper.cxx b/sc/source/filter/oox/workbookhelper.cxx index b15a94a40919..7adb76bcb7ef 100644 --- a/sc/source/filter/oox/workbookhelper.cxx +++ b/sc/source/filter/oox/workbookhelper.cxx @@ -149,9 +149,9 @@ public: /** Returns the specified cell or page style from the Calc document. */ Reference< XStyle > getStyleObject( const OUString& rStyleName, bool bPageStyle ) const; /** Creates and returns a defined name on-the-fly in the Calc document. */ - ScRangeData* createNamedRangeObject( OUString& orName, const Sequence< FormulaToken>& rTokens, sal_Int32 nIndex, sal_Int32 nNameFlags ); + ScRangeData* createNamedRangeObject( OUString& orName, const Sequence< FormulaToken>& rTokens, sal_Int32 nIndex, sal_Int32 nNameFlags, bool bHidden ); /** Creates and returns a defined name on the-fly in the correct Calc sheet. */ - ScRangeData* createLocalNamedRangeObject( OUString& orName, const Sequence< FormulaToken>& rTokens, sal_Int32 nIndex, sal_Int32 nNameFlags, sal_Int32 nTab ); + ScRangeData* createLocalNamedRangeObject( OUString& orName, const Sequence< FormulaToken>& rTokens, sal_Int32 nIndex, sal_Int32 nNameFlags, sal_Int32 nTab, bool bHidden ); /** Creates and returns a database range on-the-fly in the Calc document. */ Reference< XDatabaseRange > createDatabaseRangeObject( OUString& orName, const ScRange& rRangeAddr ); /** Creates and returns an unnamed database range on-the-fly in the Calc document. */ @@ -350,7 +350,7 @@ Reference< XStyle > WorkbookGlobals::getStyleObject( const OUString& rStyleName, namespace { -ScRangeData* lcl_addNewByNameAndTokens( ScDocument& rDoc, ScRangeName* pNames, const OUString& rName, const Sequence<FormulaToken>& rTokens, sal_Int16 nIndex, sal_Int32 nUnoType ) +ScRangeData* lcl_addNewByNameAndTokens( ScDocument& rDoc, ScRangeName* pNames, const OUString& rName, const Sequence<FormulaToken>& rTokens, sal_Int16 nIndex, sal_Int32 nUnoType, bool bHidden ) { bool bDone = false; ScRangeData::Type nNewType = ScRangeData::Type::Name; @@ -364,6 +364,9 @@ ScRangeData* lcl_addNewByNameAndTokens( ScDocument& rDoc, ScRangeName* pNames, c pNew->GuessPosition(); if ( nIndex ) pNew->SetIndex( nIndex ); + // create but not insert hidden FILTER_CRITERIA named ranges to ScRangeName + if ( bHidden && nNewType == ScRangeData::Type::Criteria ) + return pNew; if ( pNames->insert(pNew) ) bDone = true; if (!bDone) @@ -384,7 +387,7 @@ OUString findUnusedName( const ScRangeName* pRangeName, const OUString& rSuggest } ScRangeData* WorkbookGlobals::createNamedRangeObject( - OUString& orName, const Sequence< FormulaToken>& rTokens, sal_Int32 nIndex, sal_Int32 nNameFlags ) + OUString& orName, const Sequence< FormulaToken>& rTokens, sal_Int32 nIndex, sal_Int32 nNameFlags, bool bHidden ) { // create the name and insert it into the Calc document ScRangeData* pScRangeData = nullptr; @@ -395,13 +398,13 @@ ScRangeData* WorkbookGlobals::createNamedRangeObject( // find an unused name orName = findUnusedName( pNames, orName ); // create the named range - pScRangeData = lcl_addNewByNameAndTokens( rDoc, pNames, orName, rTokens, nIndex, nNameFlags ); + pScRangeData = lcl_addNewByNameAndTokens( rDoc, pNames, orName, rTokens, nIndex, nNameFlags, bHidden ); } return pScRangeData; } ScRangeData* WorkbookGlobals::createLocalNamedRangeObject( - OUString& orName, const Sequence< FormulaToken >& rTokens, sal_Int32 nIndex, sal_Int32 nNameFlags, sal_Int32 nTab ) + OUString& orName, const Sequence< FormulaToken >& rTokens, sal_Int32 nIndex, sal_Int32 nNameFlags, sal_Int32 nTab, bool bHidden ) { // create the name and insert it into the Calc document ScRangeData* pScRangeData = nullptr; @@ -414,7 +417,7 @@ ScRangeData* WorkbookGlobals::createLocalNamedRangeObject( // find an unused name orName = findUnusedName( pNames, orName ); // create the named range - pScRangeData = lcl_addNewByNameAndTokens( rDoc, pNames, orName, rTokens, nIndex, nNameFlags ); + pScRangeData = lcl_addNewByNameAndTokens( rDoc, pNames, orName, rTokens, nIndex, nNameFlags, bHidden ); } return pScRangeData; } @@ -859,14 +862,14 @@ Reference< XStyle > WorkbookHelper::getStyleObject( const OUString& rStyleName, return mrBookGlob.getStyleObject( rStyleName, bPageStyle ); } -ScRangeData* WorkbookHelper::createNamedRangeObject( OUString& orName, const Sequence< FormulaToken>& rTokens, sal_Int32 nIndex, sal_Int32 nNameFlags ) const +ScRangeData* WorkbookHelper::createNamedRangeObject( OUString& orName, const Sequence< FormulaToken>& rTokens, sal_Int32 nIndex, sal_Int32 nNameFlags, bool bHidden ) const { - return mrBookGlob.createNamedRangeObject( orName, rTokens, nIndex, nNameFlags ); + return mrBookGlob.createNamedRangeObject( orName, rTokens, nIndex, nNameFlags, bHidden ); } -ScRangeData* WorkbookHelper::createLocalNamedRangeObject( OUString& orName, const Sequence< FormulaToken>& rTokens, sal_Int32 nIndex, sal_Int32 nNameFlags, sal_Int32 nTab ) const +ScRangeData* WorkbookHelper::createLocalNamedRangeObject( OUString& orName, const Sequence< FormulaToken>& rTokens, sal_Int32 nIndex, sal_Int32 nNameFlags, sal_Int32 nTab, bool bHidden ) const { - return mrBookGlob.createLocalNamedRangeObject( orName, rTokens, nIndex, nNameFlags, nTab ); + return mrBookGlob.createLocalNamedRangeObject( orName, rTokens, nIndex, nNameFlags, nTab, bHidden ); } Reference< XDatabaseRange > WorkbookHelper::createDatabaseRangeObject( OUString& orName, const ScRange& rRangeAddr ) const |