Kaydet (Commit) ac836876 authored tarafından László Németh's avatar László Németh Kaydeden (comit) Xisco Faulí

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 19976f07
"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: 's avatarLászló Németh <nemeth@numbertext.org>
(cherry picked from commit 32a11727)
Reviewed-on: https://gerrit.libreoffice.org/73381
üst 4ace5fdb
...@@ -220,6 +220,7 @@ public: ...@@ -220,6 +220,7 @@ public:
void testTdf91634XLSX(); void testTdf91634XLSX();
void testTdf115159(); void testTdf115159();
void testTdf112567(); void testTdf112567();
void testTdf112567b();
void testTdf123645XLSX(); void testTdf123645XLSX();
void testTdf125173XLSX(); void testTdf125173XLSX();
void testTdf79972XLSX(); void testTdf79972XLSX();
...@@ -348,6 +349,7 @@ public: ...@@ -348,6 +349,7 @@ public:
CPPUNIT_TEST(testTdf91634XLSX); CPPUNIT_TEST(testTdf91634XLSX);
CPPUNIT_TEST(testTdf115159); CPPUNIT_TEST(testTdf115159);
CPPUNIT_TEST(testTdf112567); CPPUNIT_TEST(testTdf112567);
CPPUNIT_TEST(testTdf112567b);
CPPUNIT_TEST(testTdf123645XLSX); CPPUNIT_TEST(testTdf123645XLSX);
CPPUNIT_TEST(testTdf125173XLSX); CPPUNIT_TEST(testTdf125173XLSX);
CPPUNIT_TEST(testTdf79972XLSX); CPPUNIT_TEST(testTdf79972XLSX);
...@@ -4334,6 +4336,35 @@ void ScExportTest::testTdf112567() ...@@ -4334,6 +4336,35 @@ void ScExportTest::testTdf112567()
xDocSh->DoClose(); 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() void ScExportTest::testTdf123645XLSX()
{ {
ScDocShellRef xDocSh = loadDoc("chart_hyperlink.", FORMAT_XLSX); ScDocShellRef xDocSh = loadDoc("chart_hyperlink.", FORMAT_XLSX);
......
...@@ -92,6 +92,8 @@ public: ...@@ -92,6 +92,8 @@ public:
private: private:
/** Writes the body of the NAME record to the passed stream. */ /** Writes the body of the NAME record to the passed stream. */
virtual void WriteBody( XclExpStream& rStrm ) override; virtual void WriteBody( XclExpStream& rStrm ) override;
/** Convert localized range separators */
OUString GetWithDefaultRangeSeparator( const OUString& rSymbol ) const;
private: private:
OUString maOrigName; /// The original user-defined name. OUString maOrigName; /// The original user-defined name.
...@@ -294,6 +296,27 @@ void XclExpName::Save( XclExpStream& rStrm ) ...@@ -294,6 +296,27 @@ void XclExpName::Save( XclExpStream& rStrm )
XclExpRecord::Save( rStrm ); 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 ) void XclExpName::SaveXml( XclExpXmlStream& rStrm )
{ {
sax_fastparser::FSHelperPtr& rWorkbook = rStrm.GetCurrentStream(); sax_fastparser::FSHelperPtr& rWorkbook = rStrm.GetCurrentStream();
...@@ -314,7 +337,7 @@ void XclExpName::SaveXml( XclExpXmlStream& rStrm ) ...@@ -314,7 +337,7 @@ void XclExpName::SaveXml( XclExpXmlStream& rStrm )
// OOXTODO: XML_workbookParameter, "", // OOXTODO: XML_workbookParameter, "",
// OOXTODO: XML_xlm, "" // OOXTODO: XML_xlm, ""
); );
rWorkbook->writeEscaped( msSymbol ); rWorkbook->writeEscaped( GetWithDefaultRangeSeparator( msSymbol ) );
rWorkbook->endElement( XML_definedName ); rWorkbook->endElement( XML_definedName );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment