sc/source/ui/view/viewfun2.cxx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
New commits: commit 01f92e1ed22cb23b60052964a7203801393e5acf Author: Rafael Lima <rafael.palma.l...@gmail.com> AuthorDate: Fri Jun 7 20:20:59 2024 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Thu Jun 13 10:38:04 2024 +0200 tdf#161338 Do not change variable cell when Goal Seek fails When Goal Seek fails, N/A error is inserted in the cell even if the user chooses No in the message dialog. Note that the solver definition in ScDocument::Solver forcefully inserts N/A when the solver fails, which seems to be usefull when creating scripts that use the Goal Seek. However, this behavior is not usefull when using the UI. This patch restores the original value of the variable cell when Goal Seek fails. Change-Id: I52d83b9de9b13667a81dd4a3ae8ab1c8545d6958 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168537 Tested-by: Jenkins Reviewed-by: Heiko Tietze <heiko.tie...@documentfoundation.org> Reviewed-by: Rafael Lima <rafael.palma.l...@gmail.com> (cherry picked from commit d05f1ec2e20eb86ceb99e9ff5d4efb9ff9356dbb) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168722 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index 6e9095207b2b..e67ba5922516 100644 --- a/sc/source/ui/view/viewfun2.cxx +++ b/sc/source/ui/view/viewfun2.cxx @@ -2287,6 +2287,7 @@ void ScViewFunc::Solve( const ScSolveParam& rParam ) OUString aMsgStr; OUString aResStr; double nSolveResult; + double nOriginalValue = rDoc.GetValue(ScAddress(nDestCol, nDestRow, nDestTab)); GetFrameWin()->EnterWait(); @@ -2327,9 +2328,16 @@ void ScViewFunc::Solve( const ScSolveParam& rParam ) VclMessageType::Question, VclButtonsType::YesNo, aMsgStr)); xBox->set_title(ScResId(STR_MSSG_DOSUBTOTALS_0)); xBox->set_default_response(RET_NO); - if (xBox->run() == RET_YES) + int nResponse = xBox->run(); + 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 ); }