summaryrefslogtreecommitdiff
path: root/svl/source
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2015-11-27 14:18:01 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-12-05 01:31:55 +0000
commit446a3a06098ef75c034ae00e6671255973e7e5a0 (patch)
tree278af76e94677ba38ff50a43ba0f95de4592a6f8 /svl/source
parent52fe817a32bf69417563e0b66d451e8fca19d212 (diff)
Resolves: tdf#96072 export Chart format codes in Excel notation
This is a combination of 4 commits. Omitted are 2246f478e2505388ab253d08a1d86b897251223b and 7340872a3450e38a7f820945585a9ee60b2a9d41 that replace the Calc code with calling the new SvNumberFormatter functions. introduce SvNumberFormatter::FillKeywordTableForExcel() ... to conflate the places that do this on their own. (cherry picked from commit b55548043e969a6aa4c211217cfc3fb85d50d2da) use proper case "General" keyword ... Excel doesn't seem to care though. (cherry picked from commit ea1db935b085507f11d05f8606a680d521db4838) 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. (cherry picked from commit 2011b5412c4daa47bc5624a2efc996960e19c2a9) 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. (cherry picked from commit 509cfa40691cf544519872a63335cff4a4d94006) 3697a808d8fee2417f0b0e03dba2b94ceea133dd 9223eaa655132b4106a35c94cb0005559d7575b1 201bb012df818129cbc65de0eee8eca59e57d829 Change-Id: Idde2173780e0515ad982b4be46fc4df23a7577ad Reviewed-on: https://gerrit.libreoffice.org/20249 Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com> Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'svl/source')
-rw-r--r--svl/source/numbers/zforlist.cxx72
1 files changed, 72 insertions, 0 deletions
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx
index d17954ec99cf..2aaa91a24fc0 100644
--- a/svl/source/numbers/zforlist.cxx
+++ b/svl/source/numbers/zforlist.cxx
@@ -718,6 +718,78 @@ void SvNumberFormatter::FillKeywordTable( NfKeywordTable& rKeywords,
}
+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";
+ // 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::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);