diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-01-30 15:55:58 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-01-30 19:18:41 -0500 |
commit | 54ebe3df4a4c24dec7c38487a7da387fee266321 (patch) | |
tree | 25c8b4762b0ec75678abd0b91319e39f76a82b5c | |
parent | 24bce470788aa34e5e1bb001250bfa14cee1c75e (diff) |
bnc#615317: Recompile cells with #NAME! for English function name option.
When the option for using English function name changes, we should re-compile
all cells with #NAME! as the error may have been caused by unresolved function
name which may be fixed after the option change.
Change-Id: Id340ce9b5db3ed368b98e814861be5c3f96df071
-rw-r--r-- | sc/inc/column.hxx | 2 | ||||
-rw-r--r-- | sc/inc/document.hxx | 12 | ||||
-rw-r--r-- | sc/inc/table.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/column.cxx | 35 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 16 | ||||
-rw-r--r-- | sc/source/core/data/table2.cxx | 12 | ||||
-rw-r--r-- | sc/source/ui/app/scmod.cxx | 29 |
7 files changed, 102 insertions, 6 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index f4370a98356a..f6dff3bec784 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -251,6 +251,8 @@ public: void CompileAll(); void CompileXML( ScProgress& rProgress ); + bool CompileErrorCells(sal_uInt16 nErrCode); + void ResetChanged( SCROW nStartRow, SCROW nEndRow ); bool UpdateReference( UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nRow1, SCTAB nTab1, diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index c3dd9900e333..6483c65bc06a 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -860,6 +860,18 @@ public: void CompileAll(); void CompileXML(); + /** + * Re-compile formula cells with error. + * + * @param nErrCode specified error code to match. Only those cells with + * this error code will be re-compiled. If this value is + * 0, cells with any error values will be re-compiled. + * + * @return true if at least one cell is re-compiled, false if no cells are + * re-compiled. + */ + bool CompileErrorCells(sal_uInt16 nErrCode); + ScAutoNameCache* GetAutoNameCache() { return pAutoNameCache; } SC_DLLPUBLIC void SetAutoNameCache( ScAutoNameCache* pCache ); diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 30eb97abb66d..fd2aece5e356 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -447,6 +447,8 @@ public: void CompileAll(); void CompileXML( ScProgress& rProgress ); + bool CompileErrorCells(sal_uInt16 nErrCode); + void UpdateReference( UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, SCsCOL nDx, SCsROW nDy, SCsTAB nDz, diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index 01f85fe34d7f..b74d32548039 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -2135,6 +2135,41 @@ void ScColumn::CompileXML( ScProgress& rProgress ) } } +bool ScColumn::CompileErrorCells(sal_uInt16 nErrCode) +{ + if (maItems.empty()) + return false; + + bool bCompiled = false; + std::vector<ColEntry>::iterator it = maItems.begin(), itEnd = maItems.end(); + for (; it != itEnd; ++it) + { + ScBaseCell* pCell = it->pCell; + if (pCell->GetCellType() != CELLTYPE_FORMULA) + // Not a formula cell. Skip it. + continue; + + ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pCell); + sal_uInt16 nCurError = pFCell->GetRawError(); + if (!nCurError) + // It's not an error cell. Skip it. + continue; + + if (nErrCode && nCurError != nErrCode) + // Error code is specified, and it doesn't match. Skip it. + continue; + + pFCell->GetCode()->SetCodeError(0); + pFCell->SetCompile(true); + OUStringBuffer aBuf; + pFCell->GetFormula(aBuf, pDocument->GetGrammar()); + pFCell->Compile(aBuf.makeStringAndClear(), false, pDocument->GetGrammar()); + + bCompiled = true; + } + + return bCompiled; +} void ScColumn::CalcAfterLoad() { diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index 1b11231c0b43..8667b3fa1b3c 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -3381,6 +3381,22 @@ void ScDocument::CompileXML() SetAutoCalc( bOldAutoCalc ); } +bool ScDocument::CompileErrorCells(sal_uInt16 nErrCode) +{ + bool bCompiled = false; + TableContainer::iterator it = maTabs.begin(), itEnd = maTabs.end(); + for (; it != itEnd; ++it) + { + ScTable* pTab = *it; + if (!pTab) + continue; + + if (pTab->CompileErrorCells(nErrCode)) + bCompiled = true; + } + + return bCompiled; +} void ScDocument::CalcAfterLoad() { diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 2ad97a633c08..9d553fae9863 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -1546,6 +1546,18 @@ void ScTable::CompileXML( ScProgress& rProgress ) mpCondFormatList->CompileXML(); } +bool ScTable::CompileErrorCells(sal_uInt16 nErrCode) +{ + bool bCompiled = false; + for (SCCOL i = 0; i <= MAXCOL; ++i) + { + if (aCol[i].CompileErrorCells(nErrCode)) + bCompiled = true; + } + + return bCompiled; +} + void ScTable::CalcAfterLoad() { for (SCCOL i=0; i <= MAXCOL; i++) aCol[i].CalcAfterLoad(); diff --git a/sc/source/ui/app/scmod.cxx b/sc/source/ui/app/scmod.cxx index d4ed9daca3c1..38fc9ecb3002 100644 --- a/sc/source/ui/app/scmod.cxx +++ b/sc/source/ui/app/scmod.cxx @@ -100,6 +100,7 @@ #include "scslots.hxx" #include "scabstdlg.hxx" +#include "formula/errorcodes.hxx" #define SC_IDLE_MIN 150 #define SC_IDLE_MAX 3000 @@ -998,12 +999,13 @@ void ScModule::ModifyOptions( const SfxItemSet& rOptSet ) ScDocShell* pDocSh = PTR_CAST(ScDocShell, SfxObjectShell::Current()); ScDocument* pDoc = pDocSh ? pDocSh->GetDocument() : NULL; const SfxPoolItem* pItem = NULL; - sal_Bool bRepaint = false; - sal_Bool bUpdateMarks = false; - sal_Bool bUpdateRefDev = false; - sal_Bool bCalcAll = false; - sal_Bool bSaveAppOptions = false; - sal_Bool bSaveInputOptions = false; + bool bRepaint = false; + bool bUpdateMarks = false; + bool bUpdateRefDev = false; + bool bCalcAll = false; + bool bSaveAppOptions = false; + bool bSaveInputOptions = false; + bool bCompileErrorCells = false; //-------------------------------------------------------------------------- @@ -1065,6 +1067,13 @@ void ScModule::ModifyOptions( const SfxItemSet& rOptSet ) // Formula options have changed. Repaint the column headers. bRepaint = true; + if (pFormulaCfg && pFormulaCfg->GetUseEnglishFuncName() != rOpt.GetUseEnglishFuncName()) + { + // Re-compile formula cells with error as the error may have been + // caused by unresolved function names. + bCompileErrorCells = true; + } + SetFormulaOptions( rOpt ); if ( pDocSh ) @@ -1313,6 +1322,14 @@ void ScModule::ModifyOptions( const SfxItemSet& rOptSet ) // Neuberechnung anstossen? + if (pDoc && bCompileErrorCells) + { + // Re-compile cells with name error, and recalc if at least one cell + // has been re-compiled. In the future we may want to find a way to + // recalc only those that are affected. + bCalcAll = pDoc->CompileErrorCells(ScErrorCodes::errNoName); + } + if ( pDoc && bCalcAll ) { WaitObject aWait( pDocSh->GetActiveDialogParent() ); |