sc/qa/unit/data/xlsx/sortconditionref.xlsx |binary sc/qa/unit/subsequent_export_test2.cxx | 17 +++++++++++++++++ sc/source/filter/oox/autofilterbuffer.cxx | 10 ++++------ 3 files changed, 21 insertions(+), 6 deletions(-)
New commits: commit 4bada025882b8fd7a3286988300711b3a3a7425e Author: Gülşah Köse <gulsah.k...@collabora.com> AuthorDate: Fri Nov 22 14:38:40 2024 +0300 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Thu Nov 28 22:55:53 2024 +0100 tdf#163842 Fix autofilter ascending sort condition reference import if (rSorConditionLoaded.mbDescending) condition ignores the ascending sort. So when we import a document that uses ascending sort then export it, we don't know which column is sorted. With the following patch we fix this case. Signed-off-by: Gülşah Köse <gulsah.k...@collabora.com> Change-Id: I561146517959a87eb0fb6cec419d68299bcb7eee Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177016 Reviewed-by: Szymon Kłos <szymon.k...@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> (cherry picked from commit 532db8ff714363f549eb567a4a7a9c5ce2a9f668) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177507 Tested-by: Andras Timar <andras.ti...@collabora.com> Reviewed-by: Andras Timar <andras.ti...@collabora.com> diff --git a/sc/qa/unit/data/xlsx/sortconditionref.xlsx b/sc/qa/unit/data/xlsx/sortconditionref.xlsx new file mode 100644 index 000000000000..7aaebcc20471 Binary files /dev/null and b/sc/qa/unit/data/xlsx/sortconditionref.xlsx differ diff --git a/sc/qa/unit/subsequent_export_test2.cxx b/sc/qa/unit/subsequent_export_test2.cxx index a423711d91fa..b0d4b16b41a7 100644 --- a/sc/qa/unit/subsequent_export_test2.cxx +++ b/sc/qa/unit/subsequent_export_test2.cxx @@ -403,6 +403,23 @@ CPPUNIT_TEST_FIXTURE(ScExportTest2, testTdf95640_xlsx_to_xlsx) "customList"_ostr, "Low,Medium,High"); } +CPPUNIT_TEST_FIXTURE(ScExportTest2, testSortConditionRef) +{ + // Ascending sortCondition reference detected wrong without fix. + // - Expected: B3:B2 + // - Actual : A3:A2 + // - In <>, attribute 'ref' of '//x:worksheet/x:autoFilter/x:sortState/x:sortCondition' incorrect value. + createScDoc("xlsx/sortconditionref.xlsx"); + + save("Calc Office Open XML"); + xmlDocUniquePtr pDoc = parseExport("xl/worksheets/sheet1.xml"); + + assertXPath(pDoc, "//x:worksheet/x:autoFilter"_ostr, "ref"_ostr, "B2"); + + assertXPath(pDoc, "//x:worksheet/x:autoFilter/x:sortState/x:sortCondition"_ostr, "ref"_ostr, + "B3:B2"); +} + CPPUNIT_TEST_FIXTURE(ScExportTest2, testDateAutofilterXLSX) { // XLSX Roundtripping autofilter with date list diff --git a/sc/source/filter/oox/autofilterbuffer.cxx b/sc/source/filter/oox/autofilterbuffer.cxx index 9c9328176095..efe85ff4096c 100644 --- a/sc/source/filter/oox/autofilterbuffer.cxx +++ b/sc/source/filter/oox/autofilterbuffer.cxx @@ -847,15 +847,13 @@ void AutoFilter::finalizeImport( const Reference< XDatabaseRange >& rxDatabaseRa return; SCCOLROW nStartPos = aParam.bByRow ? maRange.aStart.Col() : maRange.aStart.Row(); + // descending sort - need to enable 1st SortParam slot if (rSorConditionLoaded.mbDescending) - { - // descending sort - need to enable 1st SortParam slot assert(aParam.GetSortKeyCount() == DEFSORT); - aParam.maKeyState[0].bDoSort = true; - aParam.maKeyState[0].bAscending = false; - aParam.maKeyState[0].nField += nStartPos; - } + aParam.maKeyState[0].bDoSort = true; + aParam.maKeyState[0].bAscending = !rSorConditionLoaded.mbDescending; + aParam.maKeyState[0].nField += nStartPos; ScDBData* pDBData = rDoc.GetDBAtArea( nSheet,