Kaydet (Commit) c6c286f1 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

fdo#76611: Wrap reference addresses at max boundaries.

When importing shared formula tokens.

Change-Id: I7e1a05a78c3a93330476516e0459cffb668e3f66
üst 1f70bfcd
...@@ -204,6 +204,8 @@ public: ...@@ -204,6 +204,8 @@ public:
*/ */
OUString CreateString( sc::TokenStringContext& rCxt, const ScAddress& rPos ) const; OUString CreateString( sc::TokenStringContext& rCxt, const ScAddress& rPos ) const;
void WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow );
#if DEBUG_FORMULA_COMPILER #if DEBUG_FORMULA_COMPILER
void Dump() const; void Dump() const;
#endif #endif
......
...@@ -3737,6 +3737,52 @@ OUString ScTokenArray::CreateString( sc::TokenStringContext& rCxt, const ScAddre ...@@ -3737,6 +3737,52 @@ OUString ScTokenArray::CreateString( sc::TokenStringContext& rCxt, const ScAddre
return aBuf.makeStringAndClear(); 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 #if DEBUG_FORMULA_COMPILER
void ScTokenArray::Dump() const void ScTokenArray::Dump() const
{ {
......
...@@ -128,7 +128,8 @@ void ImportExcel::Formula( ...@@ -128,7 +128,8 @@ void ImportExcel::Formula(
const ScTokenArray* pSharedCode = pFormConv->GetSharedFormula(aRefPos); const ScTokenArray* pSharedCode = pFormConv->GetSharedFormula(aRefPos);
if (pSharedCode) 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.getDoc().EnsureTable(aScPos.Tab());
rDoc.setFormulaCell(aScPos, pCell); rDoc.setFormulaCell(aScPos, pCell);
pCell->SetNeedNumberFormat(false); pCell->SetNeedNumberFormat(false);
...@@ -156,6 +157,7 @@ void ImportExcel::Formula( ...@@ -156,6 +157,7 @@ void ImportExcel::Formula(
if (pResult) if (pResult)
{ {
pCell = new ScFormulaCell(&rDoc.getDoc(), aScPos, *pResult); pCell = new ScFormulaCell(&rDoc.getDoc(), aScPos, *pResult);
pCell->GetCode()->WrapReference(aScPos, EXC_MAXCOL8, EXC_MAXROW8);
rDoc.getDoc().EnsureTable(aScPos.Tab()); rDoc.getDoc().EnsureTable(aScPos.Tab());
rDoc.setFormulaCell(aScPos, pCell); rDoc.setFormulaCell(aScPos, pCell);
SetLastFormula(aScPos.Col(), aScPos.Row(), fCurVal, nXF, pCell); SetLastFormula(aScPos.Col(), aScPos.Row(), fCurVal, nXF, pCell);
......
...@@ -877,6 +877,7 @@ void ImportExcel::Shrfmla( void ) ...@@ -877,6 +877,7 @@ void ImportExcel::Shrfmla( void )
ScDocumentImport& rDoc = GetDocImport(); ScDocumentImport& rDoc = GetDocImport();
ScFormulaCell* pCell = new ScFormulaCell(pD, aPos, *pErgebnis); ScFormulaCell* pCell = new ScFormulaCell(pD, aPos, *pErgebnis);
pCell->GetCode()->WrapReference(aPos, EXC_MAXCOL8, EXC_MAXROW8);
rDoc.getDoc().EnsureTable(aPos.Tab()); rDoc.getDoc().EnsureTable(aPos.Tab());
rDoc.setFormulaCell(aPos, pCell); rDoc.setFormulaCell(aPos, pCell);
pCell->SetNeedNumberFormat(false); pCell->SetNeedNumberFormat(false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment