summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-04-25 23:21:22 -0400
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-04-25 23:43:02 -0400
commitc6c286f14468d341f5fd88edc39a37175a1b6caa (patch)
treeb7f15c9980239014ea7fc01779d3ac2b9c9f5e00
parent1f70bfcd415cde8d0e0423525b3bdc1f471f1894 (diff)
fdo#76611: Wrap reference addresses at max boundaries.
When importing shared formula tokens. Change-Id: I7e1a05a78c3a93330476516e0459cffb668e3f66
-rw-r--r--sc/inc/tokenarray.hxx2
-rw-r--r--sc/source/core/tool/token.cxx46
-rw-r--r--sc/source/filter/excel/excform.cxx4
-rw-r--r--sc/source/filter/excel/impop.cxx1
4 files changed, 52 insertions, 1 deletions
diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx
index c7f2242caa23..72447904cf89 100644
--- a/sc/inc/tokenarray.hxx
+++ b/sc/inc/tokenarray.hxx
@@ -204,6 +204,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 58f64cc9dc1f..8bb53c310dea 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -3737,6 +3737,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 cc85f4f92fe4..07174ea8fecb 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 bf553117a014..27cf7de4dbef 100644
--- a/sc/source/filter/excel/impop.cxx
+++ b/sc/source/filter/excel/impop.cxx
@@ -877,6 +877,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);