summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/svl/zforlist.hxx12
-rw-r--r--svl/source/numbers/zforlist.cxx56
2 files changed, 67 insertions, 1 deletions
diff --git a/include/svl/zforlist.hxx b/include/svl/zforlist.hxx
index 159763b451d8..932fd8615907 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 81502d5b9a10..078d566b2da9 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);