sc/qa/unit/data/xls/tdf168589.xls |binary sc/qa/unit/subsequent_filters_test5.cxx | 9 +++++++++ sc/source/core/tool/compiler.cxx | 14 +++++++++----- 3 files changed, 18 insertions(+), 5 deletions(-)
New commits: commit fdf6777e02f4897bdb798457d3e6b8fbd343f8ab Author: Balazs Varga <[email protected]> AuthorDate: Tue Sep 30 19:05:23 2025 +0200 Commit: Balazs Varga <[email protected]> CommitDate: Wed Oct 1 23:34:05 2025 +0200 tdf#168589 - sc fix xls import with subtotal function Check if the trimmed data range of Subtotal double references is valid otherwise do not trim. regression after: b89047a0f0100fb30121084cf42815aa792c1f88 (tdf#164843 - sc optimize "SubTotal" function's reference ranges) Change-Id: I5f1fa4f67a685deb4a391e19e3acd9849b03c1b4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191691 Tested-by: Jenkins Reviewed-by: Balazs Varga <[email protected]> diff --git a/sc/qa/unit/data/xls/tdf168589.xls b/sc/qa/unit/data/xls/tdf168589.xls new file mode 100644 index 000000000000..103b35f64f6c Binary files /dev/null and b/sc/qa/unit/data/xls/tdf168589.xls differ diff --git a/sc/qa/unit/subsequent_filters_test5.cxx b/sc/qa/unit/subsequent_filters_test5.cxx index 5c9d74205171..7bcb4e9bc32a 100644 --- a/sc/qa/unit/subsequent_filters_test5.cxx +++ b/sc/qa/unit/subsequent_filters_test5.cxx @@ -276,6 +276,15 @@ CPPUNIT_TEST_FIXTURE(ScFiltersTest5, testTdf161948_NaturalSortSaveLoad) CPPUNIT_ASSERT(!aSortParam.bNaturalSort); } +CPPUNIT_TEST_FIXTURE(ScFiltersTest5, testTdf168589) +{ + // Open xls document with Subtotal function + createScDoc("xls/tdf168589.xls"); + ScDocument* pDoc = getScDoc(); + CPPUNIT_ASSERT(pDoc); + ASSERT_DOUBLES_EQUAL(6.0, pDoc->GetValue(4, 5, 0)); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index cbf61eb55d5c..e3b9fadf79f5 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -6879,17 +6879,21 @@ void ScCompiler::AnnotateTrimOnDoubleRefs() if (pTok->GetType() == svDoubleRef) { ScComplexRefData* pRefData = pTok->GetDoubleRef(); - // no need to set pRefData->SetTrimToData(true); because we already trim here + // do no set pRefData->SetTrimToData(true); because we need to trim here if possible ScRange rRange = pRefData->toAbs(rDoc, aPos); SCCOL nTempStartCol = rRange.aStart.Col(); SCROW nTempStartRow = rRange.aStart.Row(); SCCOL nTempEndCol = rRange.aEnd.Col(); SCROW nTempEndRow = rRange.aEnd.Row(); rDoc.ShrinkToDataArea(rRange.aStart.Tab(), nTempStartCol, nTempStartRow, nTempEndCol, nTempEndRow); - rRange.aStart.Set(nTempStartCol, nTempStartRow, rRange.aStart.Tab()); - rRange.aEnd.Set(nTempEndCol, nTempEndRow, rRange.aEnd.Tab()); - rRange.PutInOrder(); - pRefData->SetRange(rDoc.GetSheetLimits(), rRange, aPos); + // check if range is still valid + if (nTempStartRow <= nTempEndRow && nTempStartCol <= nTempEndCol) + { + rRange.aStart.Set(nTempStartCol, nTempStartRow, rRange.aStart.Tab()); + rRange.aEnd.Set(nTempEndCol, nTempEndRow, rRange.aEnd.Tab()); + if (rRange.IsValid()) + pRefData->SetRange(rDoc.GetSheetLimits(), rRange, aPos); + } } --ppTok; }
