diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-04-25 23:21:22 -0400 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2014-04-27 13:02:52 +0000 |
commit | da739f729223908516deb1c2564d0713231abb5b (patch) | |
tree | 0d75ab5ec93bc1e2216f107db56bace89db27ab4 /sc | |
parent | d1d25c8cbc2962ce2501b4ed6034d2e4e4ccba9a (diff) |
fdo#76611: Wrap reference addresses at max boundaries.
When importing shared formula tokens.
Change-Id: I7e1a05a78c3a93330476516e0459cffb668e3f66
(cherry picked from commit c6c286f14468d341f5fd88edc39a37175a1b6caa)
Reviewed-on: https://gerrit.libreoffice.org/9167
Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/tokenarray.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/tool/token.cxx | 46 | ||||
-rw-r--r-- | sc/source/filter/excel/excform.cxx | 4 | ||||
-rw-r--r-- | sc/source/filter/excel/impop.cxx | 1 |
4 files changed, 52 insertions, 1 deletions
diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx index bc63154bb263..3c7d7e879dbb 100644 --- a/sc/inc/tokenarray.hxx +++ b/sc/inc/tokenarray.hxx @@ -205,6 +205,8 @@ public: */ OUString CreateString( sc::TokenStringContext& rCxt, const ScAddress& rPos ) const; + void WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow ); + #if DEBUG_FORMULA_COMPILER void Dump() const; #endif diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index 320c42eabbc2..0e0f8fd2bff7 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -3752,6 +3752,52 @@ OUString ScTokenArray::CreateString( sc::TokenStringContext& rCxt, const ScAddre return aBuf.makeStringAndClear(); } +namespace { + +void wrapAddress( ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow ) +{ + if (rPos.Col() > nMaxCol) + rPos.SetCol(rPos.Col() - nMaxCol - 1); + if (rPos.Row() > nMaxRow) + rPos.SetRow(rPos.Row() - nMaxRow - 1); +} + +} + +void ScTokenArray::WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow ) +{ + FormulaToken** p = pCode; + FormulaToken** pEnd = p + static_cast<size_t>(nLen); + for (; p != pEnd; ++p) + { + switch ((*p)->GetType()) + { + case svSingleRef: + { + ScToken* pToken = static_cast<ScToken*>(*p); + ScSingleRefData& rRef = pToken->GetSingleRef(); + ScAddress aAbs = rRef.toAbs(rPos); + wrapAddress(aAbs, nMaxCol, nMaxRow); + rRef.SetAddress(aAbs, rPos); + } + break; + case svDoubleRef: + { + ScToken* pToken = static_cast<ScToken*>(*p); + ScComplexRefData& rRef = pToken->GetDoubleRef(); + ScRange aAbs = rRef.toAbs(rPos); + wrapAddress(aAbs.aStart, nMaxCol, nMaxRow); + wrapAddress(aAbs.aEnd, nMaxCol, nMaxRow); + aAbs.PutInOrder(); + rRef.SetRange(aAbs, rPos); + } + break; + default: + ; + } + } +} + #if DEBUG_FORMULA_COMPILER void ScTokenArray::Dump() const { diff --git a/sc/source/filter/excel/excform.cxx b/sc/source/filter/excel/excform.cxx index 1f1336e34036..b609e28cf191 100644 --- a/sc/source/filter/excel/excform.cxx +++ b/sc/source/filter/excel/excform.cxx @@ -128,7 +128,8 @@ void ImportExcel::Formula( const ScTokenArray* pSharedCode = pFormConv->GetSharedFormula(aRefPos); if (pSharedCode) { - ScFormulaCell* pCell = new ScFormulaCell(pD, aScPos, *pSharedCode); + ScFormulaCell* pCell = new ScFormulaCell(pD, aScPos, pSharedCode->Clone()); + pCell->GetCode()->WrapReference(aScPos, EXC_MAXCOL8, EXC_MAXROW8); rDoc.getDoc().EnsureTable(aScPos.Tab()); rDoc.setFormulaCell(aScPos, pCell); pCell->SetNeedNumberFormat(false); @@ -156,6 +157,7 @@ void ImportExcel::Formula( if (pResult) { pCell = new ScFormulaCell(&rDoc.getDoc(), aScPos, *pResult); + pCell->GetCode()->WrapReference(aScPos, EXC_MAXCOL8, EXC_MAXROW8); rDoc.getDoc().EnsureTable(aScPos.Tab()); rDoc.setFormulaCell(aScPos, pCell); SetLastFormula(aScPos.Col(), aScPos.Row(), fCurVal, nXF, pCell); diff --git a/sc/source/filter/excel/impop.cxx b/sc/source/filter/excel/impop.cxx index 913d1ba7bdfc..312da250e910 100644 --- a/sc/source/filter/excel/impop.cxx +++ b/sc/source/filter/excel/impop.cxx @@ -882,6 +882,7 @@ void ImportExcel::Shrfmla( void ) ScDocumentImport& rDoc = GetDocImport(); ScFormulaCell* pCell = new ScFormulaCell(pD, aPos, *pErgebnis); + pCell->GetCode()->WrapReference(aPos, EXC_MAXCOL8, EXC_MAXROW8); rDoc.getDoc().EnsureTable(aPos.Tab()); rDoc.setFormulaCell(aPos, pCell); pCell->SetNeedNumberFormat(false); |