summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2022-05-30 21:38:41 +0200
committerLuboš Luňák <l.lunak@collabora.com>2022-06-27 13:30:24 +0200
commitc9ffec6cdf1af4c9c1e8c6317a59ad5d63093ac7 (patch)
treefb6eddfbab0ecfb7805dc95d79f2fb0bc84249f2
parentcd76005592cf330dc450f48df31d11f8f9f3993c (diff)
InsertMatrixFormula: correct references for across sheets array formulas
Inserting an array/matrix formula across two or more selected/marked sheets generated wrong matrix offset references starting with the second sheet, pointing to the top left of the first array formula. Only the top left cell of the inserted formula on each sheet displayed the correct value. Deleting the array formula on the first sheet then left all matrix offset references on the remaining sheets with #REF! errors and those cells could not be deleted anymore because their original parent cell was gone. Change-Id: If5d53311f9aabdcd7432ff26ab555bb91b0b121d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135147 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Jenkins (cherry picked from commit dfd5081ff3973d5d0f216b06dda6360fa490cc9c) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135154 Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sc/source/core/data/documen4.cxx23
1 files changed, 8 insertions, 15 deletions
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index cf9a2fbd0a83..e893c84acaed 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -306,13 +306,11 @@ void ScDocument::InsertMatrixFormula(SCCOL nCol1, SCROW nRow1,
*pCell, *this, ScAddress(nCol1, nRow1, rTab), ScCloneFlags::StartListening));
}
- ScAddress aBasePos(nCol1, nRow1, nTab1);
ScSingleRefData aRefData;
aRefData.InitFlags();
- aRefData.SetColRel( true );
- aRefData.SetRowRel( true );
- aRefData.SetTabRel( true );
- aRefData.SetAddress(GetSheetLimits(), aBasePos, aBasePos);
+ aRefData.SetRelCol(0);
+ aRefData.SetRelRow(0);
+ aRefData.SetRelTab(0); // 2D matrix, always same sheet
ScTokenArray aArr(*this); // consists only of one single reference token.
formula::FormulaToken* t = aArr.AddMatrixSingleReference(aRefData);
@@ -326,26 +324,21 @@ void ScDocument::InsertMatrixFormula(SCCOL nCol1, SCROW nRow1,
if (!pTab)
continue;
- if (nTab != nTab1)
- {
- aRefData.SetRelTab(nTab - aBasePos.Tab());
- *t->GetSingleRef() = aRefData;
- }
-
- for (SCCOL nCol : GetWritableColumnsRange(nTab1, nCol1, nCol2))
+ for (SCCOL nCol : GetWritableColumnsRange(nTab, nCol1, nCol2))
{
+ aRefData.SetRelCol(nCol1 - nCol);
for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow)
{
if (nCol == nCol1 && nRow == nRow1)
// Skip the base position.
continue;
- // Token array must be cloned so that each formula cell receives its own copy.
- aPos = ScAddress(nCol, nRow, nTab);
// Reference in each cell must point to the origin cell relative to the current cell.
- aRefData.SetAddress(GetSheetLimits(), aBasePos, aPos);
+ aRefData.SetRelRow(nRow1 - nRow);
*t->GetSingleRef() = aRefData;
+ // Token array must be cloned so that each formula cell receives its own copy.
std::unique_ptr<ScTokenArray> pTokArr(aArr.Clone());
+ aPos = ScAddress(nCol, nRow, nTab);
pCell = new ScFormulaCell(*this, aPos, *pTokArr, eGram, ScMatrixMode::Reference);
pTab->SetFormulaCell(nCol, nRow, pCell);
}