diff options
author | Eike Rathke <erack@redhat.com> | 2016-10-27 12:52:01 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2016-10-27 12:52:34 +0200 |
commit | 02af87fdd76bc94fb51aeb160c74d6f719c42c63 (patch) | |
tree | 46a2371ec6fa1daf8d9873c3621a9c258ea2ea08 | |
parent | 91114f68e0a81d4f2a5354bc6057f62c22c780b4 (diff) |
Resolves: tdf#103531 OOXML: write external file ID within quoted sheet names
Excel expects '[1]Sheet Name' instead of [1]'Sheet Name' and complains if it
encounters the latter.
Fortunately Calc handles both.
Change-Id: If1129e58725b522ca4755c05e313c03fca065f28
-rw-r--r-- | sc/source/core/tool/compiler.cxx | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index 920b75b3a761..c86342307476 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -1470,12 +1470,23 @@ struct ConventionXL_OOX : public ConventionXL_A1 OUStringBuffer& rBuffer, const ScAddress& rPos, sal_uInt16 nFileId, const OUString& /*rFileName*/, const OUString& rTabName, const ScSingleRefData& rRef ) const override { - // [N]'Sheet Name'!$A$1 + // '[N]Sheet Name'!$A$1 or [N]SheetName!$A$1 // Where N is a 1-based positive integer number of a file name in OOXML // xl/externalLinks/externalLinkN.xml - ConventionXL_OOX::makeExternalDocStr(rBuffer, nFileId); - ScRangeStringConverter::AppendTableName(rBuffer, rTabName); + OUString aQuotedTab( rTabName); + ScCompiler::CheckTabQuotes( aQuotedTab); + if (!aQuotedTab.isEmpty() && aQuotedTab[0] == '\'') + { + rBuffer.append('\''); + ConventionXL_OOX::makeExternalDocStr( rBuffer, nFileId); + rBuffer.append( aQuotedTab.copy(1)); + } + else + { + ConventionXL_OOX::makeExternalDocStr( rBuffer, nFileId); + rBuffer.append( aQuotedTab); + } rBuffer.append('!'); makeSingleCellStr(rBuffer, rRef, rRef.toAbs(rPos)); @@ -1486,10 +1497,27 @@ struct ConventionXL_OOX : public ConventionXL_A1 const std::vector<OUString>& rTabNames, const OUString& rTabName, const ScComplexRefData& rRef ) const override { + // '[N]Sheet One':'Sheet Two'!A1:B2 or [N]SheetOne!A1:B2 + // Actually Excel writes '[N]Sheet One:Sheet Two'!A1:B2 but reads the + // simpler to produce and more logical form with independently quoted + // sheet names as well. The [N] having to be within the quoted sheet + // name is ugly enough.. + ScRange aAbsRef = rRef.toAbs(rPos); - ConventionXL_OOX::makeExternalDocStr(rBuffer, nFileId); - ConventionXL::makeExternalTabNameRange(rBuffer, rTabName, rTabNames, aAbsRef); + OUStringBuffer aBuf; + ConventionXL::makeExternalTabNameRange( aBuf, rTabName, rTabNames, aAbsRef); + if (!aBuf.isEmpty() && aBuf[0] == '\'') + { + rBuffer.append('\''); + ConventionXL_OOX::makeExternalDocStr( rBuffer, nFileId); + rBuffer.append( aBuf.copy(1)); + } + else + { + ConventionXL_OOX::makeExternalDocStr( rBuffer, nFileId); + rBuffer.append( aBuf); + } rBuffer.append('!'); makeSingleCellStr(rBuffer, rRef.Ref1, aAbsRef.aStart); |