From a3fc7f20089062afa4f778e70ba8be84032a30a7 Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Sun, 27 Jul 2014 14:35:37 -0400 Subject: fdo#81617: Split formula groups at sort range boundaries. Otherwise, partially sorting a range may crash, or at best incorrectly update formula references. Change-Id: Iefcb86d205d83ccc5b684048bfd9aadabf6e13eb --- sc/inc/table.hxx | 1 + sc/source/core/data/table3.cxx | 8 ++++++++ sc/source/core/data/table7.cxx | 8 ++++++++ 3 files changed, 17 insertions(+) (limited to 'sc') diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 44c4951b62fd..9701463d52fe 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -884,6 +884,7 @@ public: formula::FormulaTokenRef ResolveStaticReference( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 ); formula::VectorRefArray FetchVectorRefArray( SCCOL nCol, SCROW nRow1, SCROW nRow2 ); + void SplitFormulaGroups( SCCOL nCol, std::vector& rRows ); void UnshareFormulaCells( SCCOL nCol, std::vector& rRows ); void RegroupFormulaCells( SCCOL nCol ); diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx index a842d829592d..25e088fcc231 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -751,6 +751,14 @@ void ScTable::SortReorderByRow( ScSortInfoArray::RowsType* pRows = pArray->GetDataRows(); assert(pRows); // In sort-by-row mode we must have data rows already populated. + // Split formula groups at the sort range boundaries (if applicable). + std::vector aRowBounds; + aRowBounds.reserve(2); + aRowBounds.push_back(nRow1); + aRowBounds.push_back(nRow2+1); + for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol) + SplitFormulaGroups(nCol, aRowBounds); + // Cells in the data rows only reference values in the document. Make // a copy before updating the document. diff --git a/sc/source/core/data/table7.cxx b/sc/source/core/data/table7.cxx index f39e529c164d..6ff53de80739 100644 --- a/sc/source/core/data/table7.cxx +++ b/sc/source/core/data/table7.cxx @@ -118,6 +118,14 @@ bool ScTable::HasUniformRowHeight( SCROW nRow1, SCROW nRow2 ) const return nRow2 <= aData.mnRow2; } +void ScTable::SplitFormulaGroups( SCCOL nCol, std::vector& rRows ) +{ + if (!ValidCol(nCol)) + return; + + sc::SharedFormulaUtil::splitFormulaCellGroups(aCol[nCol].maCells, rRows); +} + void ScTable::UnshareFormulaCells( SCCOL nCol, std::vector& rRows ) { if (!ValidCol(nCol)) -- cgit