summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--formula/source/core/api/FormulaCompiler.cxx1
-rw-r--r--sc/inc/simpleformulacalc.hxx4
-rw-r--r--sc/qa/unit/ucalc.cxx16
-rw-r--r--sc/qa/unit/ucalc.hxx2
-rw-r--r--sc/source/core/data/simpleformulacalc.cxx27
-rw-r--r--sc/source/core/inc/interpre.hxx1
-rw-r--r--sc/source/core/tool/interpr4.cxx5
7 files changed, 53 insertions, 3 deletions
diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx
index dc24f459a4e1..f0ed8c2724fd 100644
--- a/formula/source/core/api/FormulaCompiler.cxx
+++ b/formula/source/core/api/FormulaCompiler.cxx
@@ -1862,6 +1862,7 @@ const FormulaToken* FormulaCompiler::CreateStringFromToken( OUStringBuffer& rBuf
CreateStringFromDoubleRef( rBuffer, t);
break;
case svMatrix:
+ case svMatrixCell:
CreateStringFromMatrix( rBuffer, t );
break;
diff --git a/sc/inc/simpleformulacalc.hxx b/sc/inc/simpleformulacalc.hxx
index 4d4e96291b77..33ad37bf4119 100644
--- a/sc/inc/simpleformulacalc.hxx
+++ b/sc/inc/simpleformulacalc.hxx
@@ -30,6 +30,10 @@ private:
ScAddress maAddr;
ScDocument* mpDoc;
ScFormulaResult maResult;
+ const OUString maFormula;
+ formula::FormulaGrammar::Grammar maGram;
+ bool bIsMatrix;
+ OUString maMatrixFormulaResult;
public:
ScSimpleFormulaCalculator(ScDocument* pDoc, const ScAddress& rAddr,
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index f00e3a0a2faa..f729a08f9226 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -17,6 +17,7 @@
#include "scdll.hxx"
#include "formulacell.hxx"
+#include "simpleformulacalc.hxx"
#include "stringutil.hxx"
#include "scmatrix.hxx"
#include "drwlayer.hxx"
@@ -6470,6 +6471,21 @@ void Test::testMixData()
m_pDoc->DeleteTab(0);
}
+void Test::testFormulaWizardSubformula()
+{
+ m_pDoc->InsertTab(0, "Test");
+
+ m_pDoc->SetString(ScAddress(0,0,0), "=B0:B2");
+ m_pDoc->SetString(ScAddress(0,1,0), "=1"); // B0
+ m_pDoc->SetString(ScAddress(1,1,0), "=1/0"); // B1
+ m_pDoc->SetString(ScAddress(2,1,0), "=gibberish"); // B2
+ ScSimpleFormulaCalculator pFCell( m_pDoc, ScAddress(0,0,0), "" );
+ if ( pFCell.GetErrCode() == 0 )
+ CPPUNIT_ASSERT_EQUAL( OUString("{1, #DIV/0!, #NAME!}"), pFCell.GetString().getString() );
+
+ m_pDoc->DeleteTab(0);
+}
+
void Test::testSetStringAndNote()
{
m_pDoc->InsertTab(0, "Test");
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 6e65771b0db1..74031797f9ab 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -341,6 +341,7 @@ public:
void testSharedFormulaUnshareAreaListeners();
void testSharedFormulaListenerDeleteArea();
void testFormulaPosition();
+ void testFormulaWizardSubformula();
void testMixData();
@@ -593,6 +594,7 @@ public:
CPPUNIT_TEST(testSharedFormulaUnshareAreaListeners);
CPPUNIT_TEST(testSharedFormulaListenerDeleteArea);
CPPUNIT_TEST(testFormulaPosition);
+ CPPUNIT_TEST(testFormulaWizardSubformula);
CPPUNIT_TEST(testMixData);
CPPUNIT_TEST(testJumpToPrecedentsDependents);
CPPUNIT_TEST(testSetBackgroundColor);
diff --git a/sc/source/core/data/simpleformulacalc.cxx b/sc/source/core/data/simpleformulacalc.cxx
index c17313d512bd..69719ad512ee 100644
--- a/sc/source/core/data/simpleformulacalc.cxx
+++ b/sc/source/core/data/simpleformulacalc.cxx
@@ -20,9 +20,12 @@ ScSimpleFormulaCalculator::ScSimpleFormulaCalculator( ScDocument* pDoc, const Sc
, mbCalculated(false)
, maAddr(rAddr)
, mpDoc(pDoc)
+ , maFormula(rFormula)
+ , maGram(eGram)
+ , bIsMatrix(false)
{
// compile already here
- ScCompiler aComp(pDoc, rAddr);
+ ScCompiler aComp(mpDoc, maAddr);
aComp.SetGrammar(eGram);
mpCode.reset(aComp.CompileString(rFormula));
if(!mpCode->GetCodeError() && mpCode->GetLen())
@@ -40,8 +43,21 @@ void ScSimpleFormulaCalculator::Calculate()
mbCalculated = true;
ScInterpreter aInt(NULL, mpDoc, maAddr, *mpCode.get());
- aInt.Interpret();
-
+ aInt.AssertFormulaMatrix();
+
+ formula::StackVar aIntType = aInt.Interpret();
+ if ( aIntType == formula::svMatrixCell )
+ {
+ OUStringBuffer aStr;
+ ScCompiler aComp(mpDoc, maAddr);
+ aComp.SetGrammar(maGram);
+ mpCode.reset(aComp.CompileString(maFormula));
+ if(!mpCode->GetCodeError() && mpCode->GetLen())
+ aComp.CompileTokenArray();
+ aComp.CreateStringFromToken( aStr, aInt.GetResultToken().get(), true );
+ bIsMatrix = true;
+ maMatrixFormulaResult = aStr.toString();
+ }
mnFormatType = aInt.GetRetFormatType();
mnFormatIndex = aInt.GetRetFormatIndex();
maResult.SetToken(aInt.GetResultToken().get());
@@ -51,6 +67,8 @@ bool ScSimpleFormulaCalculator::IsValue()
{
Calculate();
+ if (bIsMatrix)
+ return false;
return maResult.IsValue();
}
@@ -79,6 +97,9 @@ svl::SharedString ScSimpleFormulaCalculator::GetString()
{
Calculate();
+ if (bIsMatrix)
+ return maMatrixFormulaResult;
+
if ((!mpCode->GetCodeError() || mpCode->GetCodeError() == errDoubleRef) &&
!maResult.GetResultError())
return maResult.GetString();
diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index aea7c5f57ac6..df87bda5cb10 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -890,6 +890,7 @@ public:
void SetError(sal_uInt16 nError)
{ if (nError && !nGlobalError) nGlobalError = nError; }
+ void AssertFormulaMatrix();
sal_uInt16 GetError() const { return nGlobalError; }
formula::StackVar GetResultType() const { return xResult->GetType(); }
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index 793b752e6796..e9612a5d8bb3 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -4540,6 +4540,11 @@ StackVar ScInterpreter::Interpret()
return eType;
}
+void ScInterpreter::AssertFormulaMatrix()
+{
+ bMatrixFormula = true;
+}
+
svl::SharedString ScInterpreter::GetStringResult() const
{
return xResult->GetString();