summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKatarina Behrens <Katarina.Behrens@cib.de>2017-05-10 15:30:39 +0200
committerEike Rathke <erack@redhat.com>2017-05-11 16:02:20 +0200
commit2dd2f3328acd564e5f77efa4fe91d67ac0984e63 (patch)
tree5171e1c2019bad7c9be0df88ecbbe1243a6fc5c7 /sc
parent9b623a71fa264a9f8c7885615fa295e6dc4123e2 (diff)
Get string also for external reference to double for operands of '&'
In a formula like ='ExtRef1' & 'ExtRef2', or ='LocalValue' & 'ExtRef1' empty string became an operand in concat operation if the referenced external cell was a non-string one. Change-Id: I7b0ac5de68349eae85afe48f377e30cab76e3fbf Reviewed-on: https://gerrit.libreoffice.org/37469 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/qa/unit/ucalc_formula.cxx17
-rw-r--r--sc/source/core/tool/interpr4.cxx13
2 files changed, 29 insertions, 1 deletions
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index 474fedbcacf5..8647328a8aa9 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -5873,6 +5873,22 @@ void testExtRefFuncVLOOKUP(ScDocument* pDoc, ScDocument& rExtDoc)
CPPUNIT_ASSERT_EQUAL(OUString("B2"), pDoc->GetString(ScAddress(1,0,0)));
}
+void testExtRefConcat(ScDocument* pDoc, ScDocument& rExtDoc)
+{
+ Test::clearRange(pDoc, ScRange(0, 0, 0, 1, 9, 0));
+ Test::clearRange(&rExtDoc, ScRange(0, 0, 0, 1, 9, 0));
+
+ sc::AutoCalcSwitch aACSwitch(*pDoc, true);
+
+ // String and number
+ rExtDoc.SetString(ScAddress(0,0,0), "Answer: ");
+ rExtDoc.SetValue(ScAddress(0,1,0), 42);
+
+ // Concat operation should combine string and number converted to string
+ pDoc->SetString(ScAddress(0,0,0), "='file:///extdata.fake'#Data.A1 & 'file:///extdata.fake'#Data.A2");
+ CPPUNIT_ASSERT_EQUAL(OUString("Answer: 42"), pDoc->GetString(ScAddress(0,0,0)));
+}
+
void Test::testExternalRefFunctions()
{
ScDocShellRef xExtDocSh = new ScDocShell;
@@ -5956,6 +5972,7 @@ void Test::testExternalRefFunctions()
testExtRefFuncT(m_pDoc, rExtDoc);
testExtRefFuncOFFSET(m_pDoc, rExtDoc);
testExtRefFuncVLOOKUP(m_pDoc, rExtDoc);
+ testExtRefConcat(m_pDoc, rExtDoc);
// Unload the external document shell.
xExtDocSh->DoClose();
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index d7260b5c1bd1..9ed69677369f 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -2325,7 +2325,18 @@ svl::SharedString ScInterpreter::GetString()
if (nGlobalError != FormulaError::NONE)
return svl::SharedString::getEmptyString();
- return pToken->GetString();
+ if (pToken->GetType() == svDouble)
+ {
+ double fVal = pToken->GetDouble();
+ sal_uLong nIndex = pFormatter->GetStandardFormat(
+ css::util::NumberFormat::NUMBER,
+ ScGlobal::eLnge);
+ OUString aStr;
+ pFormatter->GetInputLineString(fVal, nIndex, aStr);
+ return mrStrPool.intern(aStr);
+ }
+ else // svString or svEmpty
+ return pToken->GetString();
}
case svExternalDoubleRef:
{