summaryrefslogtreecommitdiffstats
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@suse.com>2011-09-20 17:08:08 -0400
committerKohei Yoshida <kohei.yoshida@suse.com>2011-09-20 17:12:46 -0400
commit665d1011950dc41d9a7f8e95596d5e1d5d99ff63 (patch)
treebf96341b70d2e928d6a8062a52eac03945c9479f /sc
parentFix typo for 0ab55ac8e88f04258f1d3e79e984382f-lightproof-en-US_0.1.oxt (diff)
downloadcore-665d1011950dc41d9a7f8e95596d5e1d5d99ff63.tar.gz
core-665d1011950dc41d9a7f8e95596d5e1d5d99ff63.zip
Get DB range import from xlsx to work once again.
We need to map Excel's database ranges (or in Excel's terminology "tables") to named db ranges because they may be referenced in formula expressions. Also, Excel tables are always of the form Table*[] when used in formulas. Skip the "[]" part then the preceding token is a valid database range.
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/tokenarray.hxx1
-rw-r--r--sc/source/core/tool/compiler.cxx15
-rw-r--r--sc/source/core/tool/token.cxx7
3 files changed, 23 insertions, 0 deletions
diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx
index 740bbfa54e3c..b2f4565d5a45 100644
--- a/sc/inc/tokenarray.hxx
+++ b/sc/inc/tokenarray.hxx
@@ -73,6 +73,7 @@ public:
formula::FormulaToken* AddMatrixSingleReference( const ScSingleRefData& rRef );
formula::FormulaToken* AddDoubleReference( const ScComplexRefData& rRef );
formula::FormulaToken* AddRangeName( sal_uInt16 n, bool bGlobal );
+ formula::FormulaToken* AddDBRange( sal_uInt16 n );
formula::FormulaToken* AddExternalName( sal_uInt16 nFileId, const String& rName );
formula::FormulaToken* AddExternalSingleReference( sal_uInt16 nFileId, const String& rTabName, const ScSingleRefData& rRef );
formula::FormulaToken* AddExternalDoubleReference( sal_uInt16 nFileId, const String& rTabName, const ScComplexRefData& rRef );
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 876c992b2a59..c7d7d9b1d92c 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -3013,6 +3013,18 @@ bool ScCompiler::IsExternalNamedRange( const String& rSymbol )
bool ScCompiler::IsDBRange( const String& rName )
{
+ if (rName.EqualsAscii("[]"))
+ {
+ if (pRawToken && pRawToken->GetOpCode() == ocDBArea)
+ {
+ // In OOXML, a database range is named Table1[], Table2[] etc.
+ // Skip the [] part if the previous token is a valid db range.
+ ScRawToken aToken;
+ aToken.eOp = ocSkip;
+ pRawToken = aToken.Clone();
+ return true;
+ }
+ }
ScDBCollection::NamedDBs& rDBs = pDoc->GetDBCollection()->getNamedDBs();
const ScDBData* p = rDBs.findByUpperName(rName);
if (!p)
@@ -3798,6 +3810,9 @@ ScTokenArray* ScCompiler::CompileString( const String& rFormula )
while( NextNewToken( bInArray ) )
{
const OpCode eOp = pRawToken->GetOpCode();
+ if (eOp == ocSkip)
+ continue;
+
switch (eOp)
{
case ocOpen:
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index f0dc5cf90418..5ed165a89f7f 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1161,6 +1161,8 @@ bool ScTokenArray::AddFormulaToken(const com::sun::star::sheet::FormulaToken& _a
_aToken.Data >>= aTokenData;
if ( eOpCode == ocName )
AddRangeName(aTokenData.Index, aTokenData.Global);
+ else if (eOpCode == ocDBArea)
+ AddDBRange(aTokenData.Index);
}
else if ( aType.equals( cppu::UnoType<sheet::ExternalReference>::get() ) )
{
@@ -1604,6 +1606,11 @@ FormulaToken* ScTokenArray::AddRangeName( sal_uInt16 n, bool bGlobal )
return Add( new FormulaIndexToken( ocName, n, bGlobal));
}
+FormulaToken* ScTokenArray::AddDBRange( sal_uInt16 n )
+{
+ return Add( new FormulaIndexToken( ocDBArea, n));
+}
+
FormulaToken* ScTokenArray::AddExternalName( sal_uInt16 nFileId, const String& rName )
{
return Add( new ScExternalNameToken(nFileId, rName) );