summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorEike Rathke [er] <eike.rathke@oracle.com>2011-02-23 17:04:08 +0100
committerMichael Meeks <michael.meeks@suse.com>2012-12-04 07:17:09 +0000
commite21858afef0f805d73a00dc66e092c159d369033 (patch)
treefa53fbcba035c870c9e2e0fa161f1d3d16876ab8 /sc
parent0352490c51b634fdedc3dc29ea1a3634c271b346 (diff)
calc66: in ADDRESS function handle sheet name of external document
- Previously, 'Doc'#Tab was escaped as '''Doc''#Tab' to form one sheet name. + Split 'Doc'#Tab to isolate Tab. * Enquote Tab only if quotes not already present. + Recombine strings to form 'Doc'#'Tab' (or 'Doc'#Tab if Tab wasn't necessary to be enquoted). - A sheet name given as empty string lead to a ''.A1 address. * Use sheet name only if not empty to form A1 in that case. Conflicts: sc/inc/compiler.hxx sc/source/core/tool/compiler.cxx
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/compiler.hxx7
-rw-r--r--sc/source/core/tool/address.cxx8
-rw-r--r--sc/source/core/tool/compiler.cxx51
-rw-r--r--sc/source/core/tool/interpr1.cxx22
4 files changed, 58 insertions, 30 deletions
diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx
index 86e46c5723ce..b1cbc5fae07f 100644
--- a/sc/inc/compiler.hxx
+++ b/sc/inc/compiler.hxx
@@ -385,10 +385,15 @@ public:
static void CheckTabQuotes( String& aTabName,
const formula::FormulaGrammar::AddressConvention eConv = formula::FormulaGrammar::CONV_OOO );
+ /** Analyzes a string for a 'Doc'#Tab construct, or 'Do''c'#Tab etc..
+
+ @returns the position of the unquoted # hash mark in 'Doc'#Tab, or
+ STRING_NOTFOUND if none. */
+ static xub_StrLen GetDocTabPos( const String& rString );
+
static bool EnQuote( String& rStr );
sal_Unicode GetNativeAddressSymbol( Convention::SpecialSymbolType eType ) const;
-
// Check if it is a valid english function name
bool IsEnglishSymbol( const String& rName );
diff --git a/sc/source/core/tool/address.cxx b/sc/source/core/tool/address.cxx
index 021abb38bc91..06280fa0d0a1 100644
--- a/sc/source/core/tool/address.cxx
+++ b/sc/source/core/tool/address.cxx
@@ -1701,8 +1701,8 @@ void ScAddress::Format( String& r, sal_uInt16 nFlags, const ScDocument* pDoc,
// External Reference, same as in ScCompiler::MakeTabStr()
if( aTabName.GetChar(0) == '\'' )
{ // "'Doc'#Tab"
- xub_StrLen nPos = ScGlobal::FindUnquoted( aTabName, SC_COMPILER_FILE_TAB_SEP);
- if (nPos != STRING_NOTFOUND && nPos > 0 && aTabName.GetChar(nPos-1) == '\'')
+ xub_StrLen nPos = ScCompiler::GetDocTabPos( aTabName);
+ if (nPos != STRING_NOTFOUND)
{
aDocName = aTabName.Copy( 0, nPos + 1 );
aTabName.Erase( 0, nPos + 1 );
@@ -1779,8 +1779,8 @@ lcl_Split_DocTab( const ScDocument* pDoc, SCTAB nTab,
// External reference, same as in ScCompiler::MakeTabStr()
if ( rTabName.GetChar(0) == '\'' )
{ // "'Doc'#Tab"
- xub_StrLen nPos = ScGlobal::FindUnquoted( rTabName, SC_COMPILER_FILE_TAB_SEP);
- if (nPos != STRING_NOTFOUND && nPos > 0 && rTabName.GetChar(nPos-1) == '\'')
+ xub_StrLen nPos = ScCompiler::GetDocTabPos( rTabName);
+ if (nPos != STRING_NOTFOUND)
{
rDocName = rTabName.Copy( 0, nPos + 1 );
rTabName.Erase( 0, nPos + 1 );
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 026486233e42..7b7d023f7c62 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -747,24 +747,20 @@ struct ConventionOOO_A1 : public Convention_A1
static String MakeTabStr( const ScCompiler& rComp, SCTAB nTab, String& aDoc )
{
String aString;
- rtl::OUString aTmp;
+ OUString aTmp;
if (!rComp.GetDoc()->GetName( nTab, aTmp ))
aString = ScGlobal::GetRscString(STR_NO_REF_TABLE);
else
{
aString = aTmp;
- if ( aString.GetChar(0) == '\'' )
- { // "'Doc'#Tab"
- xub_StrLen nPos = ScGlobal::FindUnquoted( aString, SC_COMPILER_FILE_TAB_SEP);
- if (nPos != STRING_NOTFOUND && nPos > 0 && aString.GetChar(nPos-1) == '\'')
- {
- aDoc = aString.Copy( 0, nPos + 1 );
- aString.Erase( 0, nPos + 1 );
- aDoc = INetURLObject::decode( aDoc, INET_HEX_ESCAPE,
- INetURLObject::DECODE_UNAMBIGUOUS );
- }
- else
- aDoc.Erase();
+ // "'Doc'#Tab"
+ xub_StrLen nPos = ScCompiler::GetDocTabPos( aString );
+ if ( nPos != STRING_NOTFOUND )
+ {
+ aDoc = aString.Copy( 0, nPos + 1 );
+ aString.Erase( 0, nPos + 1 );
+ aDoc = INetURLObject::decode( aDoc, INET_HEX_ESCAPE,
+ INetURLObject::DECODE_UNAMBIGUOUS );
}
else
aDoc.Erase();
@@ -1091,18 +1087,15 @@ struct ConventionXL
rTabName = aTmp;
// Cheesy hack to unparse the OOO style "'Doc'#Tab"
- if ( rTabName.GetChar(0) == '\'' )
+ xub_StrLen nPos = ScCompiler::GetDocTabPos( rTabName);
+ if (nPos != STRING_NOTFOUND)
{
- xub_StrLen nPos = ScGlobal::FindUnquoted( rTabName, SC_COMPILER_FILE_TAB_SEP);
- if (nPos != STRING_NOTFOUND && nPos > 0 && rTabName.GetChar(nPos-1) == '\'')
- {
- rDocName = rTabName.Copy( 0, nPos );
- // TODO : More research into how XL escapes the doc path
- rDocName = INetURLObject::decode( rDocName, INET_HEX_ESCAPE,
+ rDocName = rTabName.Copy( 0, nPos );
+ // TODO : More research into how XL escapes the doc path
+ rDocName = INetURLObject::decode( rDocName, INET_HEX_ESCAPE,
INetURLObject::DECODE_UNAMBIGUOUS );
- rTabName.Erase( 0, nPos + 1 );
- bHasDoc = true;
- }
+ rTabName.Erase( 0, nPos + 1 );
+ bHasDoc = true;
}
// XL uses the same sheet name quoting conventions in both modes
@@ -1769,6 +1762,18 @@ void ScCompiler::CheckTabQuotes( String& rString,
}
}
+
+xub_StrLen ScCompiler::GetDocTabPos( const String& rString )
+{
+ if (rString.GetChar(0) != '\'')
+ return STRING_NOTFOUND;
+ xub_StrLen nPos = ScGlobal::FindUnquoted( rString, SC_COMPILER_FILE_TAB_SEP);
+ // it must be 'Doc'#
+ if (nPos != STRING_NOTFOUND && rString.GetChar(nPos-1) != '\'')
+ nPos = STRING_NOTFOUND;
+ return nPos;
+}
+
//---------------------------------------------------------------------------
void ScCompiler::SetRefConvention( FormulaGrammar::AddressConvention eConv )
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 34cc5b763be9..32b5747cda28 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -7212,9 +7212,27 @@ void ScInterpreter::ScAddressFunc()
const ScAddress aAdr( nCol, nRow, 0);
aAdr.Format( aRefStr, nFlags, pDok, aDetails );
- if( nParamCount >= 5 )
+ if( nParamCount >= 5 && sTabStr.Len() )
{
- ScCompiler::CheckTabQuotes( sTabStr, eConv);
+ String aDoc;
+ if (eConv == FormulaGrammar::CONV_OOO)
+ {
+ // Isolate Tab from 'Doc'#Tab
+ xub_StrLen nPos = ScCompiler::GetDocTabPos( sTabStr);
+ if (nPos != STRING_NOTFOUND)
+ {
+ if (sTabStr.GetChar(nPos+1) == '$')
+ ++nPos; // also split 'Doc'#$Tab
+ aDoc = sTabStr.Copy( 0, nPos+1);
+ sTabStr.Erase( 0, nPos+1);
+ }
+ }
+ /* TODO: yet unsupported external reference in CONV_XL_R1C1 syntax may
+ * need some extra handling to isolate Tab from Doc. */
+ if (sTabStr.GetChar(0) != '\'' || sTabStr.GetChar(sTabStr.Len()-1) != '\'')
+ ScCompiler::CheckTabQuotes( sTabStr, eConv);
+ if (aDoc.Len())
+ sTabStr.Insert( aDoc, 0);
sTabStr += static_cast<sal_Unicode>(eConv == FormulaGrammar::CONV_XL_R1C1 ? '!' : '.');
sTabStr += aRefStr;
PushString( sTabStr );