tdf#112567 XLSX export: correct built-in names
Non-en_US locale setting resulted broken XLSX export
with incorrect localized range separator. The previous
commit 19976f079800ec4c1d0d5d7e226986cb41f834c2
"tdf#112567 XLSX export: fix broken built-in names"
only avoided of the bad export of the XSLX documents
with correct definedName.
Note: this commit fixes the bad XLSX documents
during the next import/export cycle.
Change-Id: I9101c5df0f29c7a42fd49f4c2765dcf47a711916
Reviewed-on: https://gerrit.libreoffice.org/73220
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
diff --git a/sc/qa/unit/data/ods/tdf112567.ods b/sc/qa/unit/data/ods/tdf112567.ods
new file mode 100644
index 0000000..fda7999
--- /dev/null
+++ b/sc/qa/unit/data/ods/tdf112567.ods
Binary files differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index 94bfd5a..416fb9f 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -220,6 +220,7 @@
void testTdf91634XLSX();
void testTdf115159();
void testTdf112567();
void testTdf112567b();
void testTdf123645XLSX();
void testTdf125173XLSX();
void testTdf79972XLSX();
@@ -348,6 +349,7 @@
CPPUNIT_TEST(testTdf91634XLSX);
CPPUNIT_TEST(testTdf115159);
CPPUNIT_TEST(testTdf112567);
CPPUNIT_TEST(testTdf112567b);
CPPUNIT_TEST(testTdf123645XLSX);
CPPUNIT_TEST(testTdf125173XLSX);
CPPUNIT_TEST(testTdf79972XLSX);
@@ -4334,6 +4336,35 @@
xDocSh->DoClose();
}
void ScExportTest::testTdf112567b()
{
// Set the system locale to Hungarian (a language with different range separator)
SvtSysLocaleOptions aOptions;
aOptions.SetLocaleConfigString("hu-HU");
aOptions.Commit();
comphelper::ScopeGuard g([&aOptions] {
aOptions.SetLocaleConfigString(OUString());
aOptions.Commit();
});
ScDocShellRef xShell = loadDoc("tdf112567.", FORMAT_ODS);
CPPUNIT_ASSERT(xShell.is());
ScDocShellRef xDocSh = saveAndReload(xShell.get(), FORMAT_XLSX);
CPPUNIT_ASSERT(xDocSh.is());
xShell->DoClose();
xmlDocPtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/workbook.xml", FORMAT_XLSX);
CPPUNIT_ASSERT(pDoc);
//assert the existing OOXML built-in name is not duplicated
assertXPath(pDoc, "/x:workbook/x:definedNames/x:definedName", 1);
//and it contains "," instead of ";"
assertXPathContent(pDoc, "/x:workbook/x:definedNames/x:definedName[1]", "Sheet1!$A:$A,Sheet1!$1:$1");
xDocSh->DoClose();
}
void ScExportTest::testTdf123645XLSX()
{
ScDocShellRef xDocSh = loadDoc("chart_hyperlink.", FORMAT_XLSX);
diff --git a/sc/source/filter/excel/xename.cxx b/sc/source/filter/excel/xename.cxx
index ee418fb..35d84b8 100644
--- a/sc/source/filter/excel/xename.cxx
+++ b/sc/source/filter/excel/xename.cxx
@@ -92,6 +92,8 @@
private:
/** Writes the body of the NAME record to the passed stream. */
virtual void WriteBody( XclExpStream& rStrm ) override;
/** Convert localized range separators */
OUString GetWithDefaultRangeSeparator( const OUString& rSymbol ) const;
private:
OUString maOrigName; /// The original user-defined name.
@@ -294,6 +296,27 @@
XclExpRecord::Save( rStrm );
}
OUString XclExpName::GetWithDefaultRangeSeparator( const OUString& rSymbol ) const
{
sal_Int32 nPos = rSymbol.indexOf(';');
if ( nPos > -1 )
{
// convert with validation
ScRange aRange;
ScAddress::Details detailsXL( ::formula::FormulaGrammar::CONV_XL_A1 );
ScRefFlags nRes = aRange.Parse( rSymbol.copy(0, nPos), &GetDocRef(), detailsXL );
if ( nRes & ScRefFlags::VALID )
{
nRes = aRange.Parse( rSymbol.copy(nPos+1), &GetDocRef(), detailsXL );
if ( nRes & ScRefFlags::VALID )
{
return rSymbol.replaceFirst(";", ",");
}
}
}
return rSymbol;
}
void XclExpName::SaveXml( XclExpXmlStream& rStrm )
{
sax_fastparser::FSHelperPtr& rWorkbook = rStrm.GetCurrentStream();
@@ -314,7 +337,7 @@
// OOXTODO: XML_workbookParameter, "",
// OOXTODO: XML_xlm, ""
);
rWorkbook->writeEscaped( msSymbol );
rWorkbook->writeEscaped( GetWithDefaultRangeSeparator( msSymbol ) );
rWorkbook->endElement( XML_definedName );
}