summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sc/inc/tokenarray.hxx1
-rw-r--r--sc/source/core/tool/token.cxx34
-rw-r--r--sc/source/filter/excel/excform.cxx10
3 files changed, 43 insertions, 2 deletions
diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx
index ad61ef3cdc87..412ecfefe71d 100644
--- a/sc/inc/tokenarray.hxx
+++ b/sc/inc/tokenarray.hxx
@@ -239,6 +239,7 @@ public:
OUString CreateString( sc::TokenStringContext& rCxt, const ScAddress& rPos ) const;
void WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow );
+ bool NeedsWrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow ) const;
#if DEBUG_FORMULA_COMPILER
void Dump() const;
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index ee55b074bd59..43e1963ac1df 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -4035,6 +4035,40 @@ void ScTokenArray::WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nM
}
}
+bool ScTokenArray::NeedsWrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow ) const
+{
+ FormulaToken** p = pCode;
+ FormulaToken** pEnd = p + static_cast<size_t>(nLen);
+ for (; p != pEnd; ++p)
+ {
+ switch ((*p)->GetType())
+ {
+ case svSingleRef:
+ {
+ formula::FormulaToken* pToken = *p;
+ ScSingleRefData& rRef = *pToken->GetSingleRef();
+ ScAddress aAbs = rRef.toAbs(rPos);
+ if (aAbs.Col() > nMaxCol || aAbs.Row() > nMaxRow)
+ return true;
+ }
+ break;
+ case svDoubleRef:
+ {
+ formula::FormulaToken* pToken = *p;
+ ScComplexRefData& rRef = *pToken->GetDoubleRef();
+ ScRange aAbs = rRef.toAbs(rPos);
+ if (aAbs.aStart.Col() > nMaxCol || aAbs.aStart.Row() > nMaxRow ||
+ aAbs.aEnd.Col() > nMaxCol || aAbs.aEnd.Row() > nMaxRow)
+ return true;
+ }
+ break;
+ default:
+ ;
+ }
+ }
+ return false;
+}
+
#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 630997a7d06f..1df8fd980c21 100644
--- a/sc/source/filter/excel/excform.cxx
+++ b/sc/source/filter/excel/excform.cxx
@@ -124,8 +124,14 @@ void ImportExcel::Formula(
const ScTokenArray* pSharedCode = pFormConv->GetSharedFormula(aRefPos);
if (pSharedCode)
{
- ScFormulaCell* pCell = new ScFormulaCell(pD, aScPos, pSharedCode->Clone());
- pCell->GetCode()->WrapReference(aScPos, EXC_MAXCOL8, EXC_MAXROW8);
+ ScFormulaCell* pCell;
+ if (pSharedCode->NeedsWrapReference(aScPos, EXC_MAXCOL8, EXC_MAXROW8))
+ {
+ pCell = new ScFormulaCell(pD, aScPos, pSharedCode->Clone());
+ pCell->GetCode()->WrapReference(aScPos, EXC_MAXCOL8, EXC_MAXROW8);
+ }
+ else
+ pCell = new ScFormulaCell(pD, aScPos, *pSharedCode);
rDoc.getDoc().EnsureTable(aScPos.Tab());
rDoc.setFormulaCell(aScPos, pCell);
pCell->SetNeedNumberFormat(false);