summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
Diffstat (limited to 'sc/source')
-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);
}