chart2/qa/extras/chart2export.cxx | 2 - include/svl/zforlist.hxx | 14 +++++++ oox/source/export/chartexport.cxx | 29 ++++++++++---- sc/source/filter/excel/xestyle.cxx | 61 ++----------------------------- svl/source/numbers/zforlist.cxx | 72 +++++++++++++++++++++++++++++++++++++ 5 files changed, 112 insertions(+), 66 deletions(-)
New commits: commit c06b24dc5636e1924ece928aef25baa4fa03d30e Author: Eike Rathke <er...@redhat.com> Date: Fri Nov 27 22:57:55 2015 +0100 Resolves: tdf#96072 export Chart format codes in Excel notation As for the change in chart2/qa/extras/chart2export.cxx Chart2ExportTest::testAxisNumberFormatXLSX() unit test: also Excel writes string parts of format codes quoted, including minus sign in negative subformat. Change-Id: I201bb012df818129cbc65de0eee8eca59e57d829 (cherry picked from commit 509cfa40691cf544519872a63335cff4a4d94006) diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx index 6aaba78..ad5859b 100644 --- a/chart2/qa/extras/chart2export.cxx +++ b/chart2/qa/extras/chart2export.cxx @@ -1281,7 +1281,7 @@ void Chart2ExportTest::testAxisNumberFormatXLSX() assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx[1]/c:numFmt", "formatCode", "0.00E+000"); assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx[1]/c:numFmt", "sourceLinked", "0"); - assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx[2]/c:numFmt", "formatCode", "[$$-409]#,##0;-[$$-409]#,##0"); + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx[2]/c:numFmt", "formatCode", "[$$-409]#,##0;\\-[$$-409]#,##0"); assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx[2]/c:numFmt", "sourceLinked", "1"); } diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx index 14e49a8..e62ad95 100644 --- a/oox/source/export/chartexport.cxx +++ b/oox/source/export/chartexport.cxx @@ -90,6 +90,10 @@ #include <comphelper/sequence.hxx> #include <xmloff/SchXMLSeriesHelper.hxx> #include "ColorPropertySet.hxx" + +#include <svl/zforlist.hxx> +#include <svl/numuno.hxx> + #include <set> #include <unordered_set> @@ -3753,17 +3757,26 @@ bool ChartExport::isDeep3dChart() OUString ChartExport::getNumberFormatCode(sal_Int32 nKey) const { + /* XXX if this was called more than one or two times per export the two + * SvNumberFormatter instances and NfKeywordTable should be member + * variables and initialized only once. */ + + OUString aCode("General"); // init with fallback uno::Reference<util::XNumberFormatsSupplier> xNumberFormatsSupplier(mxChartModel, uno::UNO_QUERY_THROW); - uno::Reference<util::XNumberFormats> xNumberFormats = xNumberFormatsSupplier->getNumberFormats(); - uno::Reference<beans::XPropertySet> xNumberFormat = xNumberFormats->getByKey(nKey); + SvNumberFormatsSupplierObj* pSupplierObj = SvNumberFormatsSupplierObj::getImplementation( xNumberFormatsSupplier); + if (!pSupplierObj) + return aCode; + + SvNumberFormatter* pNumberFormatter = pSupplierObj->GetNumberFormatter(); + if (!pNumberFormatter) + return aCode; - if (!xNumberFormat.is()) - return OUString(); + SvNumberFormatter aTempFormatter( comphelper::getProcessComponentContext(), LANGUAGE_ENGLISH_US); + NfKeywordTable aKeywords; + aTempFormatter.FillKeywordTableForExcel( aKeywords); + aCode = pNumberFormatter->GetFormatStringForExcel( nKey, aKeywords, aTempFormatter); - uno::Any aAny = xNumberFormat->getPropertyValue("FormatString"); - OUString aValue; - aAny >>= aValue; - return aValue; + return aCode; } }// drawingml commit 34d043b214fa97ab828e68e5d324d493485cbe9b Author: Eike Rathke <er...@redhat.com> Date: Fri Nov 27 21:32:09 2015 +0100 use SvNumberFormatter::GetFormatStringForExcel() Change-Id: I4d5f8aa33fffceaa080d8b2ef6a177b4680cf761 (cherry picked from commit 7340872a3450e38a7f820945585a9ee60b2a9d41) diff --git a/sc/source/filter/excel/xestyle.cxx b/sc/source/filter/excel/xestyle.cxx index be7a005..55ebdcf 100644 --- a/sc/source/filter/excel/xestyle.cxx +++ b/sc/source/filter/excel/xestyle.cxx @@ -1433,48 +1433,9 @@ void XclExpNumFmtBuffer::WriteFormatRecord( XclExpStream& rStrm, const XclExpNum namespace { -OUString GetNumberFormatCode(XclRoot& rRoot, const sal_uInt16 nScNumFmt, SvNumberFormatter* xFormatter, NfKeywordTable* pKeywordTable) +OUString GetNumberFormatCode(XclRoot& rRoot, const sal_uInt16 nScNumFmt, SvNumberFormatter* pFormatter, NfKeywordTable* pKeywordTable) { - OUString aFormatStr; - - if( const SvNumberformat* pEntry = rRoot.GetFormatter().GetEntry( nScNumFmt ) ) - { - if( pEntry->GetType() == css::util::NumberFormat::LOGICAL ) - { - // build Boolean number format - Color* pColor = nullptr; - OUString aTemp; - const_cast< SvNumberformat* >( pEntry )->GetOutputString( 1.0, aTemp, &pColor ); - aFormatStr += "\"" + aTemp + "\";\"" + aTemp + "\";\""; - const_cast< SvNumberformat* >( pEntry )->GetOutputString( 0.0, aTemp, &pColor ); - aFormatStr += aTemp + "\""; - } - else - { - LanguageType eLang = pEntry->GetLanguage(); - if( eLang != LANGUAGE_ENGLISH_US ) - { - sal_Int32 nCheckPos; - short nType = css::util::NumberFormat::DEFINED; - sal_uInt32 nKey; - OUString aTemp( pEntry->GetFormatstring() ); - xFormatter->PutandConvertEntry( aTemp, nCheckPos, nType, nKey, eLang, LANGUAGE_ENGLISH_US ); - OSL_ENSURE( nCheckPos == 0, "XclExpNumFmtBuffer::WriteFormatRecord - format code not convertible" ); - pEntry = xFormatter->GetEntry( nKey ); - } - - aFormatStr = pEntry->GetMappedFormatstring( *pKeywordTable, *xFormatter->GetLocaleData() ); - if( aFormatStr == "Standard" ) - aFormatStr = "General"; - } - } - else - { - OSL_FAIL( "XclExpNumFmtBuffer::WriteFormatRecord - format not found" ); - aFormatStr = "General"; - } - - return aFormatStr; + return rRoot.GetFormatter().GetFormatStringForExcel( nScNumFmt, *pKeywordTable, *pFormatter); } } commit f9c565ff7c8c65610890af50eda560a56e2d03af Author: Eike Rathke <er...@redhat.com> Date: Fri Nov 27 19:08:50 2015 +0100 introduce SvNumberFormatter::GetFormatStringForExcel() Taking implementation from sc/source/filter/excel/xestyle.cxx GetNumberFormatCode(), slightly modified to ensure valid conversion and force en-US locale data. Also don't unnecessarily convert if format is for system locale and system locale is en-US. Change-Id: I9223eaa655132b4106a35c94cb0005559d7575b1 (cherry picked from commit 2011b5412c4daa47bc5624a2efc996960e19c2a9) diff --git a/include/svl/zforlist.hxx b/include/svl/zforlist.hxx index 159763b..932fd86 100644 --- a/include/svl/zforlist.hxx +++ b/include/svl/zforlist.hxx @@ -759,9 +759,19 @@ public: void FillKeywordTable( NfKeywordTable& rKeywords, LanguageType eLang ); /** Fill a NfKeywordIndex table with keywords usable in Excel export with - GetMappedFormatstring() */ + GetFormatStringForExcel() or SvNumberformat::GetMappedFormatstring() */ void FillKeywordTableForExcel( NfKeywordTable& rKeywords ); + /** Return a format code string suitable for Excel export. + + @param rTempFormatter + SvNumberFormatter to use if a non-en-US format code needs to be + converted and put, should not be the same formatter to not + pollute the entries of this one here. + */ + OUString GetFormatStringForExcel( sal_uInt32 nKey, const NfKeywordTable& rKeywords, + SvNumberFormatter& rTempFormatter ) const; + /** Return a keyword for a language/country and NfKeywordIndex for XML import, to generate number format strings. */ OUString GetKeyword( LanguageType eLnge, sal_uInt16 nIndex ); diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx index 81502d5..078d566 100644 --- a/svl/source/numbers/zforlist.cxx +++ b/svl/source/numbers/zforlist.cxx @@ -791,6 +791,62 @@ void SvNumberFormatter::FillKeywordTableForExcel( NfKeywordTable& rKeywords ) } +OUString SvNumberFormatter::GetFormatStringForExcel( sal_uInt32 nKey, const NfKeywordTable& rKeywords, + SvNumberFormatter& rTempFormatter ) const +{ + OUString aFormatStr; + if (const SvNumberformat* pEntry = GetEntry( nKey)) + { + if (pEntry->GetType() == css::util::NumberFormat::LOGICAL) + { + // Build Boolean number format, which needs non-zero and zero + // subformat codes with TRUE and FALSE strings. + Color* pColor = nullptr; + OUString aTemp; + const_cast< SvNumberformat* >( pEntry )->GetOutputString( 1.0, aTemp, &pColor ); + aFormatStr += "\"" + aTemp + "\";\"" + aTemp + "\";\""; + const_cast< SvNumberformat* >( pEntry )->GetOutputString( 0.0, aTemp, &pColor ); + aFormatStr += aTemp + "\""; + } + else + { + LanguageType nLang = pEntry->GetLanguage(); + if (nLang == LANGUAGE_SYSTEM) + nLang = SvtSysLocale().GetLanguageTag().getLanguageType(); + if (nLang != LANGUAGE_ENGLISH_US) + { + sal_Int32 nCheckPos; + short nType = css::util::NumberFormat::DEFINED; + sal_uInt32 nTempKey; + OUString aTemp( pEntry->GetFormatstring()); + rTempFormatter.PutandConvertEntry( aTemp, nCheckPos, nType, nTempKey, nLang, LANGUAGE_ENGLISH_US); + SAL_WARN_IF( nCheckPos != 0, "svl.numbers", + "SvNumberFormatter::GetFormatStringForExcel - format code not convertible"); + if (nTempKey != NUMBERFORMAT_ENTRY_NOT_FOUND) + pEntry = rTempFormatter.GetEntry( nTempKey); + } + + if (pEntry) + { + // GetLocaleData() returns the current locale's data, so switch + // before (which doesn't do anything if it was the same locale + // already). + rTempFormatter.ChangeIntl( LANGUAGE_ENGLISH_US); + aFormatStr = pEntry->GetMappedFormatstring( rKeywords, *rTempFormatter.GetLocaleData()); + } + } + } + else + { + SAL_WARN("svl.numbers","SvNumberFormatter::GetFormatStringForExcel - format not found: " << nKey); + } + + if (aFormatStr.isEmpty()) + aFormatStr = "General"; + return aFormatStr; +} + + OUString SvNumberFormatter::GetKeyword( LanguageType eLnge, sal_uInt16 nIndex ) { ChangeIntl(eLnge); commit e96c66210c779a200765efae5b5c03ff3bdc34fe Author: Eike Rathke <er...@redhat.com> Date: Fri Nov 27 15:14:38 2015 +0100 use proper case "General" keyword ... Excel doesn't seem to care though. Change-Id: I3697a808d8fee2417f0b0e03dba2b94ceea133dd (cherry picked from commit ea1db935b085507f11d05f8606a680d521db4838) diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx index f12ee01..81502d5 100644 --- a/svl/source/numbers/zforlist.cxx +++ b/svl/source/numbers/zforlist.cxx @@ -779,6 +779,8 @@ void SvNumberFormatter::FillKeywordTableForExcel( NfKeywordTable& rKeywords ) { FillKeywordTable( rKeywords, LANGUAGE_ENGLISH_US ); + // Replace upper case "GENERAL" with proper case "General". + rKeywords[ NF_KEY_GENERAL ] = GetStandardName( LANGUAGE_ENGLISH_US ); // Remap codes unknown to Excel. rKeywords[ NF_KEY_NN ] = "DDD"; rKeywords[ NF_KEY_NNN ] = "DDDD"; commit 9b59abdb03f1da1d4cb3b4efb217c1077625efe7 Author: Eike Rathke <er...@redhat.com> Date: Fri Nov 27 14:33:44 2015 +0100 use SvNumberFormatter::FillKeywordTableForExcel() Change-Id: I83b0cd033ba46dabdde92ed2812398518d1895bf (cherry picked from commit 2246f478e2505388ab253d08a1d86b897251223b) diff --git a/sc/source/filter/excel/xestyle.cxx b/sc/source/filter/excel/xestyle.cxx index cd9f8e1..be7a005 100644 --- a/sc/source/filter/excel/xestyle.cxx +++ b/sc/source/filter/excel/xestyle.cxx @@ -1366,14 +1366,7 @@ XclExpNumFmtBuffer::XclExpNumFmtBuffer( const XclExpRoot& rRoot ) : default: mnXclOffset = 0; DBG_ERROR_BIFF(); } - mxFormatter->FillKeywordTable( *mpKeywordTable, LANGUAGE_ENGLISH_US ); - // remap codes unknown to Excel - (*mpKeywordTable)[ NF_KEY_NN ] = "DDD"; - (*mpKeywordTable)[ NF_KEY_NNN ] = "DDDD"; - // NNNN gets a separator appended in SvNumberformat::GetMappedFormatString() - (*mpKeywordTable)[ NF_KEY_NNNN ] = "DDDD"; - // Export the Thai T NatNum modifier. - (*mpKeywordTable)[ NF_KEY_THAI_T ] = "T"; + mxFormatter->FillKeywordTableForExcel( *mpKeywordTable ); } XclExpNumFmtBuffer::~XclExpNumFmtBuffer() @@ -2997,14 +2990,7 @@ XclExpDxfs::XclExpDxfs( const XclExpRoot& rRoot ) mxFormatter( new SvNumberFormatter( comphelper::getProcessComponentContext(), LANGUAGE_ENGLISH_US ) ), mpKeywordTable( new NfKeywordTable ) { - mxFormatter->FillKeywordTable( *mpKeywordTable, LANGUAGE_ENGLISH_US ); - // remap codes unknown to Excel - (*mpKeywordTable)[ NF_KEY_NN ] = "DDD"; - (*mpKeywordTable)[ NF_KEY_NNN ] = "DDDD"; - // NNNN gets a separator appended in SvNumberformat::GetMappedFormatString() - (*mpKeywordTable)[ NF_KEY_NNNN ] = "DDDD"; - // Export the Thai T NatNum modifier. - (*mpKeywordTable)[ NF_KEY_THAI_T ] = "T"; + mxFormatter->FillKeywordTableForExcel( *mpKeywordTable ); SCTAB nTables = rRoot.GetDoc().GetTableCount(); for(SCTAB nTab = 0; nTab < nTables; ++nTab) commit 8cd082adec3860ed0bf91218db8781308fadd75c Author: Eike Rathke <er...@redhat.com> Date: Fri Nov 27 14:18:01 2015 +0100 introduce SvNumberFormatter::FillKeywordTableForExcel() ... to conflate the places that do this on their own. Change-Id: Idde2173780e0515ad982b4be46fc4df23a7577ad (cherry picked from commit b55548043e969a6aa4c211217cfc3fb85d50d2da) diff --git a/include/svl/zforlist.hxx b/include/svl/zforlist.hxx index 2e3760e..159763b 100644 --- a/include/svl/zforlist.hxx +++ b/include/svl/zforlist.hxx @@ -758,6 +758,10 @@ public: /// Fill a NfKeywordIndex table with keywords of a language/country void FillKeywordTable( NfKeywordTable& rKeywords, LanguageType eLang ); + /** Fill a NfKeywordIndex table with keywords usable in Excel export with + GetMappedFormatstring() */ + void FillKeywordTableForExcel( NfKeywordTable& rKeywords ); + /** Return a keyword for a language/country and NfKeywordIndex for XML import, to generate number format strings. */ OUString GetKeyword( LanguageType eLnge, sal_uInt16 nIndex ); diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx index 53b4213..f12ee01 100644 --- a/svl/source/numbers/zforlist.cxx +++ b/svl/source/numbers/zforlist.cxx @@ -775,6 +775,20 @@ void SvNumberFormatter::FillKeywordTable( NfKeywordTable& rKeywords, } +void SvNumberFormatter::FillKeywordTableForExcel( NfKeywordTable& rKeywords ) +{ + FillKeywordTable( rKeywords, LANGUAGE_ENGLISH_US ); + + // Remap codes unknown to Excel. + rKeywords[ NF_KEY_NN ] = "DDD"; + rKeywords[ NF_KEY_NNN ] = "DDDD"; + // NNNN gets a separator appended in SvNumberformat::GetMappedFormatString() + rKeywords[ NF_KEY_NNNN ] = "DDDD"; + // Export the Thai T NatNum modifier. + rKeywords[ NF_KEY_THAI_T ] = "T"; +} + + OUString SvNumberFormatter::GetKeyword( LanguageType eLnge, sal_uInt16 nIndex ) { ChangeIntl(eLnge); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits