From 18cccd62fb5b730319878df6fac748d5cdf73f1f Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Sat, 27 Dec 2014 06:51:52 +0100 Subject: handle index based external refs in formulas in ooxml import, fdo#85617 Change-Id: Ie4f43f041f5d614b9c2826c74574c854af05c266 --- sc/source/core/tool/compiler.cxx | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index 0c273b3fe5f3..1c292aa28776 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -1322,6 +1322,52 @@ struct ConventionXL_OOX : public ConventionXL_A1 * CellStr. */ } + static void parseExternalDocNameOOX(const OUString& rFormula, sal_Int32& rSrcPos) + { + sal_Int32 nLen = rFormula.getLength(); + const sal_Unicode* p = rFormula.getStr(); + for (sal_Int32 i = rSrcPos; i < nLen; ++i) + { + sal_Unicode c = p[i]; + if (i == rSrcPos) + { + // first character must be '['. + if (c != '[') + return; + } + else if (c == ']') + { + rSrcPos = i + 1; + } + } + } + + virtual ParseResult parseAnyToken( const OUString& rFormula, + sal_Int32 nSrcPos, + const CharClass* pCharClass) const SAL_OVERRIDE + { + parseExternalDocNameOOX(rFormula, nSrcPos); + + ParseResult aRet; + if ( lcl_isValidQuotedText(rFormula, nSrcPos, aRet) ) + return aRet; + + static const sal_Int32 nStartFlags = KParseTokens::ANY_LETTER_OR_NUMBER | + KParseTokens::ASC_UNDERSCORE | KParseTokens::ASC_DOLLAR; + static const sal_Int32 nContFlags = nStartFlags | KParseTokens::ASC_DOT; + // '?' allowed in range names + const OUString aAddAllowed("?!"); + return pCharClass->parseAnyToken( rFormula, + nSrcPos, nStartFlags, aAddAllowed, nContFlags, aAddAllowed ); + } + + virtual bool parseExternalName( const OUString& rSymbol, OUString& rFile, OUString& rName, + const ScDocument* pDoc, + const uno::Sequence* pExternalLinks ) const SAL_OVERRIDE + { + return ConventionXL::parseExternalName( rSymbol, rFile, rName, pDoc, pExternalLinks); + } + virtual void makeExternalRefStr( OUStringBuffer& rBuffer, const ScAddress& rPos, sal_uInt16 nFileId, const OUString& /*rFileName*/, const OUString& rTabName, const ScSingleRefData& rRef ) const SAL_OVERRIDE -- cgit v1.2.3