sc/inc/document.hxx | 2 +- sc/source/core/data/documen4.cxx | 12 +++--------- sc/source/ui/view/viewfun2.cxx | 11 ++--------- 3 files changed, 6 insertions(+), 19 deletions(-)
New commits: commit ffa5c8e13970403319a6761811fd79fb51dbaff7 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Thu Jun 13 11:46:30 2024 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Fri Jun 14 06:06:46 2024 +0200 tdf#161338: Pass a flag to ScDocument::Solver to avoid #NA! on error This fixes the remaining problems: 1. It didn't restore variable cells with text of formulas properly. 2. Undoing after accepting the "closest value" dialog gave #NA! in the variable cell. This doesn't change the behavior of XGoalSeek::seekGoal. Change-Id: Ic9fbd3c99e6491b1c54b2e3b334090e51b1be661 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168763 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index cc714491e6d9..3d412761be39 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1982,7 +1982,7 @@ public: // Goal Seek solver bool Solver( SCCOL nFCol, SCROW nFRow, SCTAB nFTab, SCCOL nVCol, SCROW nVRow, SCTAB nVTab, - const OUString& sValStr, double& nX); + const OUString& sValStr, double& nX, bool setNA = true); ScGoalSeekSettings GetGoalSeekSettings() { return maGoalSeekSettings; } void SetGoalSeekSettings(ScGoalSeekSettings aNewSettings) { maGoalSeekSettings = aNewSettings; } diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx index 107c7fe80c5d..b722a55a29d0 100644 --- a/sc/source/core/data/documen4.cxx +++ b/sc/source/core/data/documen4.cxx @@ -72,7 +72,7 @@ using namespace formula; */ bool ScDocument::Solver(SCCOL nFCol, SCROW nFRow, SCTAB nFTab, SCCOL nVCol, SCROW nVRow, SCTAB nVTab, - const OUString& sValStr, double& nX) + const OUString& sValStr, double& nX, bool setNA) { bool bRet = false; nX = 0.0; @@ -244,16 +244,10 @@ bool ScDocument::Solver(SCCOL nFCol, SCROW nFRow, SCTAB nFTab, *pVCell = fSaveVal; SetDirty( aVRange, false ); pFormula->Interpret(); - if ( !bDoneIteration ) - { - SetError( nVCol, nVRow, nVTab, FormulaError::NotAvailable ); - } - } - else - { - SetError( nVCol, nVRow, nVTab, FormulaError::NotAvailable ); } } + if (!bRet && setNA) + SetError(nVCol, nVRow, nVTab, FormulaError::NotAvailable); return bRet; } diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index e67ba5922516..2254ae4b93d6 100644 --- a/sc/source/ui/view/viewfun2.cxx +++ b/sc/source/ui/view/viewfun2.cxx @@ -2287,8 +2287,6 @@ void ScViewFunc::Solve( const ScSolveParam& rParam ) OUString aMsgStr; OUString aResStr; double nSolveResult; - double nOriginalValue = rDoc.GetValue(ScAddress(nDestCol, nDestRow, nDestTab)); - GetFrameWin()->EnterWait(); bool bExact = @@ -2298,7 +2296,8 @@ void ScViewFunc::Solve( const ScSolveParam& rParam ) rParam.aRefFormulaCell.Tab(), nDestCol, nDestRow, nDestTab, aTargetValStr, - nSolveResult ); + nSolveResult, + false); // Do not set #NA! on error GetFrameWin()->LeaveWait(); @@ -2332,12 +2331,6 @@ void ScViewFunc::Solve( const ScSolveParam& rParam ) if (nResponse == RET_YES) EnterValue( nDestCol, nDestRow, nDestTab, nSolveResult ); - // tdf#161338 If Goal Seek fails, restore the original value - // Note that ScDocument::Solver forcefully changes the variable cell to N/A error - // if the Goal Seek solver fails; so here we need to restore the value - if (!bExact && nResponse == RET_NO) - rDoc.SetValue(nDestCol, nDestRow, nDestTab, nOriginalValue); - GetViewData().GetViewShell()->UpdateInputHandler( true ); }