28#include <com/sun/star/uno/Reference.h>
29#include <rtl/ustring.hxx>
31#include <com/sun/star/util/NumberFormat.hpp>
32#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
34#include <rtl/math.hxx>
35#include <rtl/ustrbuf.hxx>
36#include <osl/diagnose.h>
42constexpr OUStringLiteral
gsType(u
"Type");
47 css::uno::Reference< css::util::XNumberFormatsSupplier >
const & xTempNumberFormatsSupplier)
48 : m_xNumberFormats(xTempNumberFormatsSupplier.is() ? xTempNumberFormatsSupplier->
getNumberFormats() : css::
uno::
Reference< css::util::XNumberFormats > ()),
54 css::uno::Reference< css::util::XNumberFormatsSupplier >
const & xTempNumberFormatsSupplier,
56: m_xNumberFormats(xTempNumberFormatsSupplier.is() ? xTempNumberFormatsSupplier->
getNumberFormats() : css::
uno::
Reference< css::util::XNumberFormats > ()),
57 m_pExport(&rTempExport),
78 bIsStandard = aItr->bIsStandard;
79 sCurrency = aItr->sCurrency;
86 if ((aFormat.
nType & ~util::NumberFormat::DEFINED) == util::NumberFormat::CURRENCY)
95 const sal_Int16 nTypeKey,
97 const OUString& rCurrency,
100 bool bWasSetTypeAttribute =
false;
101 switch(nTypeKey & ~util::NumberFormat::DEFINED)
104 case util::NumberFormat::NUMBER:
105 case util::NumberFormat::SCIENTIFIC:
106 case util::NumberFormat::FRACTION:
109 bWasSetTypeAttribute =
true;
112 case util::NumberFormat::PERCENT:
114 if (!bWasSetTypeAttribute)
117 bWasSetTypeAttribute =
true;
121 case util::NumberFormat::CURRENCY:
123 if (!bWasSetTypeAttribute)
126 if (!rCurrency.isEmpty())
132 OUString sValue( ::rtl::math::doubleToUString( rValue,
133 rtl_math_StringFormat_Automatic,
134 rtl_math_DecimalPlaces_Max,
'.',
true));
139 case util::NumberFormat::DATE:
140 case util::NumberFormat::DATETIME:
147 OUStringBuffer sBuffer;
154 case util::NumberFormat::TIME:
159 OUStringBuffer sBuffer;
165 case util::NumberFormat::LOGICAL:
170 double fTempValue = rValue;
171 if (::rtl::math::approxEqual( fTempValue, 1.0 ))
183 OUString sValue( ::rtl::math::doubleToUString(
185 rtl_math_StringFormat_Automatic,
186 rtl_math_DecimalPlaces_Max,
'.',
194 case util::NumberFormat::TEXT:
199 OUString sValue( ::rtl::math::doubleToUString( rValue,
200 rtl_math_StringFormat_Automatic,
201 rtl_math_DecimalPlaces_Max,
'.',
true));
210 uno::Reference <util::XNumberFormatsSupplier>
const & xNumberFormatsSupplier)
212 if (xNumberFormatsSupplier.is())
214 uno::Reference <util::XNumberFormats> xNumberFormats(xNumberFormatsSupplier->getNumberFormats());
215 if (xNumberFormats.is())
219 uno::Reference <beans::XPropertySet> xNumberPropertySet(xNumberFormats->getByKey(nNumberFormat));
220 if ( xNumberPropertySet->getPropertyValue(
gsCurrencySymbol) >>= sCurrencySymbol)
222 OUString sCurrencyAbbreviation;
225 if ( !sCurrencyAbbreviation.isEmpty())
226 sCurrencySymbol = sCurrencyAbbreviation;
229 if ( sCurrencySymbol.getLength() == 1 && sCurrencySymbol.toChar() == NfCurrencyEntry::GetEuroSymbol() )
230 sCurrencySymbol =
"EUR";
236 catch ( uno::Exception& )
238 OSL_FAIL(
"Numberformat not found");
247 uno::Reference <util::XNumberFormatsSupplier>
const & xNumberFormatsSupplier)
249 if (xNumberFormatsSupplier.is())
251 uno::Reference <util::XNumberFormats> xNumberFormats(xNumberFormatsSupplier->getNumberFormats());
252 if (xNumberFormats.is())
256 uno::Reference <beans::XPropertySet> xNumberPropertySet(xNumberFormats->getByKey(nNumberFormat));
258 sal_Int16 nNumberType = sal_Int16();
259 if ( xNumberPropertySet->getPropertyValue(
gsType) >>= nNumberType )
264 catch ( uno::Exception& )
266 OSL_FAIL(
"Numberformat not found");
274 const sal_Int32 nNumberFormat,
const double& rValue,
bool bExportValue)
279 if ((nTypeKey & ~util::NumberFormat::DEFINED) == util::NumberFormat::CURRENCY)
281 WriteAttributes(rXMLExport, nTypeKey, rValue, sCurrency, bExportValue);
285 const OUString& rValue, std::u16string_view rCharacters,
286 bool bExportValue,
bool bExportTypeAttribute)
288 if (bExportTypeAttribute)
290 if (bExportValue && !rValue.isEmpty() && (rValue != rCharacters))
303 uno::Reference <beans::XPropertySet> xNumberPropertySet(
m_xNumberFormats->getByKey(nNumberFormat));
304 if ( xNumberPropertySet->getPropertyValue(
gsCurrencySymbol) >>= rCurrencySymbol)
306 OUString sCurrencyAbbreviation;
309 if ( !sCurrencyAbbreviation.isEmpty())
310 rCurrencySymbol = sCurrencyAbbreviation;
313 if ( rCurrencySymbol.getLength() == 1 && rCurrencySymbol.toChar() == NfCurrencyEntry::GetEuroSymbol() )
314 rCurrencySymbol =
"EUR";
320 catch ( uno::Exception& )
322 OSL_FAIL(
"Numberformat not found");
337 uno::Reference <beans::XPropertySet> xNumberPropertySet(
m_xNumberFormats->getByKey(nNumberFormat));
338 if (xNumberPropertySet.is())
341 sal_Int16 nNumberType = sal_Int16();
342 if ( xNumberPropertySet->getPropertyValue(
gsType) >>= nNumberType )
348 catch ( uno::Exception& )
350 OSL_FAIL(
"Numberformat not found");
357 const sal_Int16 nTypeKey,
358 const double& rValue,
359 const OUString& rCurrency,
360 bool bExportValue, sal_uInt16 nNamespace)
365 bool bWasSetTypeAttribute =
false;
367 switch(nTypeKey & ~util::NumberFormat::DEFINED)
370 case util::NumberFormat::NUMBER:
371 case util::NumberFormat::SCIENTIFIC:
372 case util::NumberFormat::FRACTION:
375 bWasSetTypeAttribute =
true;
378 case util::NumberFormat::PERCENT:
380 if (!bWasSetTypeAttribute)
383 bWasSetTypeAttribute =
true;
387 case util::NumberFormat::CURRENCY:
389 if (!bWasSetTypeAttribute)
392 if (!rCurrency.isEmpty())
398 OUString sValue( ::rtl::math::doubleToUString( rValue,
399 rtl_math_StringFormat_Automatic,
400 rtl_math_DecimalPlaces_Max,
'.',
true));
405 case util::NumberFormat::DATE:
406 case util::NumberFormat::DATETIME:
413 OUStringBuffer sBuffer;
420 case util::NumberFormat::TIME:
425 OUStringBuffer sBuffer;
431 case util::NumberFormat::LOGICAL:
436 double fTempValue = rValue;
437 if (::rtl::math::approxEqual( fTempValue, 1.0 ))
449 OUString sValue( ::rtl::math::doubleToUString(
451 rtl_math_StringFormat_Automatic,
452 rtl_math_DecimalPlaces_Max,
'.',
460 case util::NumberFormat::TEXT:
465 OUString sValue( ::rtl::math::doubleToUString( rValue,
466 rtl_math_StringFormat_Automatic,
467 rtl_math_DecimalPlaces_Max,
'.',
true));
476 const sal_Int32 nNumberFormat,
const double& rValue,
bool bExportValue,
477 sal_uInt16 nNamespace,
bool bExportCurrencySymbol)
483 sal_Int16 nTypeKey =
GetCellType(nNumberFormat, sCurrency, bIsStandard);
484 if(!bExportCurrencySymbol)
490 OSL_FAIL(
"no SvXMLExport given");
495 const OUString& rValue, std::u16string_view rCharacters,
497 sal_uInt16 nNamespace)
502 if (bExportValue && !rValue.isEmpty() && (rValue != rCharacters))
506 OSL_FAIL(
"no SvXMLExport given");
const SvXMLNamespaceMap & GetNamespaceMap() const
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
css::uno::Reference< css::util::XNumberFormatsSupplier > & GetNumberFormatsSupplier()
const SvXMLUnitConverter & GetMM100UnitConverter() const
bool SetNullDateOnUnitConverter()
set null date from model to unit converter, if not already done
OUString GetQNameByKey(sal_uInt16 nKey, const OUString &rLocalName, bool bCache=true) const
void convertDateTime(OUStringBuffer &rBuffer, const double &fDateTime, bool const bAddTimeIf0AM=false)
convert double to ISO Date Time String
static void convertDuration(OUStringBuffer &rBuffer, const double fTime)
Handling of tokens in XML:
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
constexpr OUStringLiteral gsType(u"Type")
constexpr OUStringLiteral gsCurrencySymbol(u"CurrencySymbol")
constexpr OUStringLiteral gsStandardFormat(u"StandardFormat")
constexpr OUStringLiteral gsCurrencyAbbreviation(u"CurrencyAbbreviation")
OReadStatusBarDocumentHandler::StatusBar_XML_Namespace nNamespace
constexpr sal_uInt16 XML_NAMESPACE_OFFICE