1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26
27 #include "xmloff/numehelp.hxx"
28
29 #include <xmloff/nmspmap.hxx>
30 #include "xmloff/xmlnmspe.hxx"
31 #include <xmloff/xmluconv.hxx>
32 #include <xmloff/xmltoken.hxx>
33 #include <xmloff/xmlexp.hxx>
34 #include <com/sun/star/uno/Reference.h>
35 #include <rtl/ustring.hxx>
36 #include <svl/zforlist.hxx>
37 #include <com/sun/star/util/NumberFormat.hpp>
38 #include <rtl/math.hxx>
39 #include <tools/debug.hxx>
40 #include <rtl/ustrbuf.hxx>
41
42 using namespace com::sun::star;
43 using namespace xmloff::token;
44
45 #define XML_TYPE "Type"
46 #define XML_CURRENCYSYMBOL "CurrencySymbol"
47 #define XML_CURRENCYABBREVIATION "CurrencyAbbreviation"
48 #define XML_STANDARDFORMAT "StandardFormat"
49
XMLNumberFormatAttributesExportHelper(::com::sun::star::uno::Reference<::com::sun::star::util::XNumberFormatsSupplier> & xTempNumberFormatsSupplier)50 XMLNumberFormatAttributesExportHelper::XMLNumberFormatAttributesExportHelper(
51 ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >& xTempNumberFormatsSupplier)
52 : xNumberFormats(xTempNumberFormatsSupplier.is() ? xTempNumberFormatsSupplier->getNumberFormats() : ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats > ()),
53 pExport(NULL),
54 sStandardFormat(RTL_CONSTASCII_USTRINGPARAM(XML_STANDARDFORMAT)),
55 sType(RTL_CONSTASCII_USTRINGPARAM(XML_TYPE)),
56 msCurrencySymbol(RTL_CONSTASCII_USTRINGPARAM(XML_CURRENCYSYMBOL)),
57 msCurrencyAbbreviation(RTL_CONSTASCII_USTRINGPARAM(XML_CURRENCYABBREVIATION)),
58 aNumberFormats()
59 {
60 }
61
XMLNumberFormatAttributesExportHelper(::com::sun::star::uno::Reference<::com::sun::star::util::XNumberFormatsSupplier> & xTempNumberFormatsSupplier,SvXMLExport & rTempExport)62 XMLNumberFormatAttributesExportHelper::XMLNumberFormatAttributesExportHelper(
63 ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >& xTempNumberFormatsSupplier,
64 SvXMLExport& rTempExport )
65 : xNumberFormats(xTempNumberFormatsSupplier.is() ? xTempNumberFormatsSupplier->getNumberFormats() : ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats > ()),
66 pExport(&rTempExport),
67 sStandardFormat(RTL_CONSTASCII_USTRINGPARAM(XML_STANDARDFORMAT)),
68 sType(RTL_CONSTASCII_USTRINGPARAM(XML_TYPE)),
69 sAttrValueType(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_VALUE_TYPE))),
70 sAttrValue(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_VALUE))),
71 sAttrDateValue(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_DATE_VALUE))),
72 sAttrTimeValue(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_TIME_VALUE))),
73 sAttrBooleanValue(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_BOOLEAN_VALUE))),
74 sAttrStringValue(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_STRING_VALUE))),
75 sAttrCurrency(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_CURRENCY))),
76 msCurrencySymbol(RTL_CONSTASCII_USTRINGPARAM(XML_CURRENCYSYMBOL)),
77 msCurrencyAbbreviation(RTL_CONSTASCII_USTRINGPARAM(XML_CURRENCYABBREVIATION)),
78 aNumberFormats()
79 {
80 }
81
~XMLNumberFormatAttributesExportHelper()82 XMLNumberFormatAttributesExportHelper::~XMLNumberFormatAttributesExportHelper()
83 {
84 }
85
GetCellType(const sal_Int32 nNumberFormat,rtl::OUString & sCurrency,sal_Bool & bIsStandard)86 sal_Int16 XMLNumberFormatAttributesExportHelper::GetCellType(const sal_Int32 nNumberFormat, rtl::OUString& sCurrency, sal_Bool& bIsStandard)
87 {
88 XMLNumberFormat aFormat(sEmpty, nNumberFormat, 0);
89 XMLNumberFormatSet::iterator aItr(aNumberFormats.find(aFormat));
90 XMLNumberFormatSet::iterator aEndItr(aNumberFormats.end());
91 if (aItr != aEndItr)
92 {
93 bIsStandard = aItr->bIsStandard;
94 sCurrency = aItr->sCurrency;
95 return aItr->nType;
96 }
97 else
98 {
99 aFormat.nType = GetCellType(nNumberFormat, bIsStandard);
100 aFormat.bIsStandard = bIsStandard;
101 if ((aFormat.nType & ~util::NumberFormat::DEFINED) == util::NumberFormat::CURRENCY)
102 if (GetCurrencySymbol(nNumberFormat, aFormat.sCurrency))
103 sCurrency = aFormat.sCurrency;
104 aNumberFormats.insert(aFormat);
105 return aFormat.nType;
106 }
107 }
108
WriteAttributes(SvXMLExport & rXMLExport,const sal_Int16 nTypeKey,const double & rValue,const rtl::OUString & rCurrency,sal_Bool bExportValue)109 void XMLNumberFormatAttributesExportHelper::WriteAttributes(SvXMLExport& rXMLExport,
110 const sal_Int16 nTypeKey,
111 const double& rValue,
112 const rtl::OUString& rCurrency,
113 sal_Bool bExportValue)
114 {
115 sal_Bool bWasSetTypeAttribute = sal_False;
116 switch(nTypeKey & ~util::NumberFormat::DEFINED)
117 {
118 case 0:
119 case util::NumberFormat::NUMBER:
120 case util::NumberFormat::SCIENTIFIC:
121 case util::NumberFormat::FRACTION:
122 {
123 if (!bWasSetTypeAttribute)
124 {
125 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_FLOAT);
126 bWasSetTypeAttribute = sal_True;
127 }
128 } // No Break
129 case util::NumberFormat::PERCENT:
130 {
131 if (!bWasSetTypeAttribute)
132 {
133 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_PERCENTAGE);
134 bWasSetTypeAttribute = sal_True;
135 }
136 } // No Break
137 case util::NumberFormat::CURRENCY:
138 {
139 if (!bWasSetTypeAttribute)
140 {
141 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_CURRENCY);
142 if (rCurrency.getLength() > 0)
143 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_CURRENCY, rCurrency);
144 bWasSetTypeAttribute = sal_True;
145 }
146
147 if (bExportValue)
148 {
149 rtl::OUString sValue( ::rtl::math::doubleToUString( rValue,
150 rtl_math_StringFormat_Automatic,
151 rtl_math_DecimalPlaces_Max, '.', sal_True));
152 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE, sValue);
153 }
154 }
155 break;
156 case util::NumberFormat::DATE:
157 case util::NumberFormat::DATETIME:
158 {
159 if (!bWasSetTypeAttribute)
160 {
161 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_DATE);
162 bWasSetTypeAttribute = sal_True;
163 }
164 if (bExportValue)
165 {
166 if ( rXMLExport.SetNullDateOnUnitConverter() )
167 {
168 rtl::OUStringBuffer sBuffer;
169 rXMLExport.GetMM100UnitConverter().convertDateTime(sBuffer, rValue);
170 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_DATE_VALUE, sBuffer.makeStringAndClear());
171 }
172 }
173 }
174 break;
175 case util::NumberFormat::TIME:
176 {
177 if (!bWasSetTypeAttribute)
178 {
179 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_TIME);
180 bWasSetTypeAttribute = sal_True;
181 }
182 if (bExportValue)
183 {
184 rtl::OUStringBuffer sBuffer;
185 rXMLExport.GetMM100UnitConverter().convertTime(sBuffer, rValue);
186 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_TIME_VALUE, sBuffer.makeStringAndClear());
187 }
188 }
189 break;
190 case util::NumberFormat::LOGICAL:
191 {
192 if (!bWasSetTypeAttribute)
193 {
194 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_BOOLEAN);
195 bWasSetTypeAttribute = sal_True;
196 }
197 if (bExportValue)
198 {
199 double fTempValue = rValue;
200 if (::rtl::math::approxEqual( fTempValue, 1.0 ))
201 {
202 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_BOOLEAN_VALUE, XML_TRUE);
203 }
204 else
205 {
206 if (::rtl::math::approxEqual( rValue, 0.0 ))
207 {
208 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_BOOLEAN_VALUE, XML_FALSE);
209 }
210 else
211 {
212 rtl::OUString sValue( ::rtl::math::doubleToUString(
213 fTempValue,
214 rtl_math_StringFormat_Automatic,
215 rtl_math_DecimalPlaces_Max, '.',
216 sal_True));
217 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_BOOLEAN_VALUE, sValue);
218 }
219 }
220 }
221 }
222 break;
223 case util::NumberFormat::TEXT:
224 {
225 if (!bWasSetTypeAttribute)
226 {
227 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_FLOAT);
228 bWasSetTypeAttribute = sal_True;
229 if (bExportValue)
230 {
231 rtl::OUString sValue( ::rtl::math::doubleToUString( rValue,
232 rtl_math_StringFormat_Automatic,
233 rtl_math_DecimalPlaces_Max, '.', sal_True));
234 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE, sValue);
235 }
236 }
237 }
238 break;
239 }
240 }
241
GetCurrencySymbol(const sal_Int32 nNumberFormat,rtl::OUString & sCurrencySymbol,uno::Reference<util::XNumberFormatsSupplier> & xNumberFormatsSupplier)242 sal_Bool XMLNumberFormatAttributesExportHelper::GetCurrencySymbol(const sal_Int32 nNumberFormat, rtl::OUString& sCurrencySymbol,
243 uno::Reference <util::XNumberFormatsSupplier>& xNumberFormatsSupplier)
244 {
245 if (xNumberFormatsSupplier.is())
246 {
247 uno::Reference <util::XNumberFormats> xNumberFormats(xNumberFormatsSupplier->getNumberFormats());
248 if (xNumberFormats.is())
249 {
250 try
251 {
252 uno::Reference <beans::XPropertySet> xNumberPropertySet(xNumberFormats->getByKey(nNumberFormat));
253 if ( xNumberPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_CURRENCYSYMBOL))) >>= sCurrencySymbol)
254 {
255 rtl::OUString sCurrencyAbbreviation;
256 if ( xNumberPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_CURRENCYABBREVIATION))) >>= sCurrencyAbbreviation)
257 {
258 if ( sCurrencyAbbreviation.getLength() != 0 )
259 sCurrencySymbol = sCurrencyAbbreviation;
260 else
261 {
262 if ( sCurrencySymbol.getLength() == 1 && sCurrencySymbol.toChar() == NfCurrencyEntry::GetEuroSymbol() )
263 sCurrencySymbol = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EUR"));
264 }
265 }
266 return sal_True;
267 }
268 }
269 catch ( uno::Exception& )
270 {
271 DBG_ERROR("Numberformat not found");
272 }
273 }
274 }
275 return sal_False;
276 }
277
278
GetCellType(const sal_Int32 nNumberFormat,sal_Bool & bIsStandard,uno::Reference<util::XNumberFormatsSupplier> & xNumberFormatsSupplier)279 sal_Int16 XMLNumberFormatAttributesExportHelper::GetCellType(const sal_Int32 nNumberFormat, sal_Bool& bIsStandard,
280 uno::Reference <util::XNumberFormatsSupplier>& xNumberFormatsSupplier)
281 {
282 if (xNumberFormatsSupplier.is())
283 {
284 uno::Reference <util::XNumberFormats> xNumberFormats(xNumberFormatsSupplier->getNumberFormats());
285 if (xNumberFormats.is())
286 {
287 try
288 {
289 uno::Reference <beans::XPropertySet> xNumberPropertySet(xNumberFormats->getByKey(nNumberFormat));
290 xNumberPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STANDARDFORMAT))) >>= bIsStandard;
291 sal_Int16 nNumberType = sal_Int16();
292 if ( xNumberPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_TYPE))) >>= nNumberType )
293 {
294 return nNumberType;
295 }
296 }
297 catch ( uno::Exception& )
298 {
299 DBG_ERROR("Numberformat not found");
300 }
301 }
302 }
303 return 0;
304 }
305
SetNumberFormatAttributes(SvXMLExport & rXMLExport,const sal_Int32 nNumberFormat,const double & rValue,sal_Bool bExportValue)306 void XMLNumberFormatAttributesExportHelper::SetNumberFormatAttributes(SvXMLExport& rXMLExport,
307 const sal_Int32 nNumberFormat, const double& rValue, sal_Bool bExportValue)
308 {
309 sal_Bool bIsStandard;
310 sal_Int16 nTypeKey = GetCellType(nNumberFormat, bIsStandard, rXMLExport.GetNumberFormatsSupplier());
311 rtl::OUString sCurrency;
312 if ((nTypeKey & ~util::NumberFormat::DEFINED) == util::NumberFormat::CURRENCY)
313 GetCurrencySymbol(nNumberFormat, sCurrency, rXMLExport.GetNumberFormatsSupplier());
314 WriteAttributes(rXMLExport, nTypeKey, rValue, sCurrency, bExportValue);
315 }
316
SetNumberFormatAttributes(SvXMLExport & rXMLExport,const rtl::OUString & rValue,const rtl::OUString & rCharacters,sal_Bool bExportValue,sal_Bool bExportTypeAttribute)317 void XMLNumberFormatAttributesExportHelper::SetNumberFormatAttributes(SvXMLExport& rXMLExport,
318 const rtl::OUString& rValue, const rtl::OUString& rCharacters,
319 sal_Bool bExportValue, sal_Bool bExportTypeAttribute)
320 {
321 if (bExportTypeAttribute)
322 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_STRING);
323 if (bExportValue && rValue.getLength() && (rValue != rCharacters))
324 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_STRING_VALUE, rValue);
325 }
326
GetCurrencySymbol(const sal_Int32 nNumberFormat,rtl::OUString & rCurrencySymbol)327 sal_Bool XMLNumberFormatAttributesExportHelper::GetCurrencySymbol(const sal_Int32 nNumberFormat, rtl::OUString& rCurrencySymbol)
328 {
329 if (!xNumberFormats.is() && pExport && pExport->GetNumberFormatsSupplier().is())
330 xNumberFormats.set(pExport->GetNumberFormatsSupplier()->getNumberFormats());
331
332 if (xNumberFormats.is())
333 {
334 try
335 {
336 uno::Reference <beans::XPropertySet> xNumberPropertySet(xNumberFormats->getByKey(nNumberFormat));
337 if ( xNumberPropertySet->getPropertyValue(msCurrencySymbol) >>= rCurrencySymbol)
338 {
339 rtl::OUString sCurrencyAbbreviation;
340 if ( xNumberPropertySet->getPropertyValue(msCurrencyAbbreviation) >>= sCurrencyAbbreviation)
341 {
342 if ( sCurrencyAbbreviation.getLength() != 0 )
343 rCurrencySymbol = sCurrencyAbbreviation;
344 else
345 {
346 if ( rCurrencySymbol.getLength() == 1 && rCurrencySymbol.toChar() == NfCurrencyEntry::GetEuroSymbol() )
347 rCurrencySymbol = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EUR"));
348 }
349 }
350 return sal_True;
351 }
352 }
353 catch ( uno::Exception& )
354 {
355 DBG_ERROR("Numberformat not found");
356 }
357 }
358 return sal_False;
359 }
360
GetCellType(const sal_Int32 nNumberFormat,sal_Bool & bIsStandard)361 sal_Int16 XMLNumberFormatAttributesExportHelper::GetCellType(const sal_Int32 nNumberFormat, sal_Bool& bIsStandard)
362 {
363 if (!xNumberFormats.is() && pExport && pExport->GetNumberFormatsSupplier().is())
364 xNumberFormats.set(pExport->GetNumberFormatsSupplier()->getNumberFormats());
365
366 if (xNumberFormats.is())
367 {
368 try
369 {
370 uno::Reference <beans::XPropertySet> xNumberPropertySet(xNumberFormats->getByKey(nNumberFormat));
371 if (xNumberPropertySet.is())
372 {
373 xNumberPropertySet->getPropertyValue(sStandardFormat) >>= bIsStandard;
374 sal_Int16 nNumberType = sal_Int16();
375 if ( xNumberPropertySet->getPropertyValue(sType) >>= nNumberType )
376 {
377 return nNumberType;
378 }
379 }
380 }
381 catch ( uno::Exception& )
382 {
383 DBG_ERROR("Numberformat not found");
384 }
385 }
386 return 0;
387 }
388
WriteAttributes(const sal_Int16 nTypeKey,const double & rValue,const rtl::OUString & rCurrency,sal_Bool bExportValue)389 void XMLNumberFormatAttributesExportHelper::WriteAttributes(
390 const sal_Int16 nTypeKey,
391 const double& rValue,
392 const rtl::OUString& rCurrency,
393 sal_Bool bExportValue)
394 {
395 if (!pExport)
396 return;
397
398 sal_Bool bWasSetTypeAttribute = sal_False;
399 switch(nTypeKey & ~util::NumberFormat::DEFINED)
400 {
401 case 0:
402 case util::NumberFormat::NUMBER:
403 case util::NumberFormat::SCIENTIFIC:
404 case util::NumberFormat::FRACTION:
405 {
406 if (!bWasSetTypeAttribute)
407 {
408 pExport->AddAttribute(sAttrValueType, XML_FLOAT);
409 bWasSetTypeAttribute = sal_True;
410 }
411 } // No Break
412 case util::NumberFormat::PERCENT:
413 {
414 if (!bWasSetTypeAttribute)
415 {
416 pExport->AddAttribute(sAttrValueType, XML_PERCENTAGE);
417 bWasSetTypeAttribute = sal_True;
418 }
419 } // No Break
420 case util::NumberFormat::CURRENCY:
421 {
422 if (!bWasSetTypeAttribute)
423 {
424 pExport->AddAttribute(sAttrValueType, XML_CURRENCY);
425 if (rCurrency.getLength() > 0)
426 pExport->AddAttribute(sAttrCurrency, rCurrency);
427 bWasSetTypeAttribute = sal_True;
428 }
429
430 if (bExportValue)
431 {
432 rtl::OUString sValue( ::rtl::math::doubleToUString( rValue,
433 rtl_math_StringFormat_Automatic,
434 rtl_math_DecimalPlaces_Max, '.', sal_True));
435 pExport->AddAttribute(sAttrValue, sValue);
436 }
437 }
438 break;
439 case util::NumberFormat::DATE:
440 case util::NumberFormat::DATETIME:
441 {
442 if (!bWasSetTypeAttribute)
443 {
444 pExport->AddAttribute(sAttrValueType, XML_DATE);
445 bWasSetTypeAttribute = sal_True;
446 }
447 if (bExportValue)
448 {
449 if ( pExport->SetNullDateOnUnitConverter() )
450 {
451 rtl::OUStringBuffer sBuffer;
452 pExport->GetMM100UnitConverter().convertDateTime(sBuffer, rValue);
453 pExport->AddAttribute(sAttrDateValue, sBuffer.makeStringAndClear());
454 }
455 }
456 }
457 break;
458 case util::NumberFormat::TIME:
459 {
460 if (!bWasSetTypeAttribute)
461 {
462 pExport->AddAttribute(sAttrValueType, XML_TIME);
463 bWasSetTypeAttribute = sal_True;
464 }
465 if (bExportValue)
466 {
467 rtl::OUStringBuffer sBuffer;
468 pExport->GetMM100UnitConverter().convertTime(sBuffer, rValue);
469 pExport->AddAttribute(sAttrTimeValue, sBuffer.makeStringAndClear());
470 }
471 }
472 break;
473 case util::NumberFormat::LOGICAL:
474 {
475 if (!bWasSetTypeAttribute)
476 {
477 pExport->AddAttribute(sAttrValueType, XML_BOOLEAN);
478 bWasSetTypeAttribute = sal_True;
479 }
480 if (bExportValue)
481 {
482 double fTempValue = rValue;
483 if (::rtl::math::approxEqual( fTempValue, 1.0 ))
484 {
485 pExport->AddAttribute(sAttrBooleanValue, XML_TRUE);
486 }
487 else
488 {
489 if (::rtl::math::approxEqual( rValue, 0.0 ))
490 {
491 pExport->AddAttribute(sAttrBooleanValue, XML_FALSE);
492 }
493 else
494 {
495 rtl::OUString sValue( ::rtl::math::doubleToUString(
496 fTempValue,
497 rtl_math_StringFormat_Automatic,
498 rtl_math_DecimalPlaces_Max, '.',
499 sal_True));
500 pExport->AddAttribute(sAttrBooleanValue, sValue);
501 }
502 }
503 }
504 }
505 break;
506 case util::NumberFormat::TEXT:
507 {
508 if (!bWasSetTypeAttribute)
509 {
510 pExport->AddAttribute(sAttrValueType, XML_FLOAT);
511 bWasSetTypeAttribute = sal_True;
512 if (bExportValue)
513 {
514 rtl::OUString sValue( ::rtl::math::doubleToUString( rValue,
515 rtl_math_StringFormat_Automatic,
516 rtl_math_DecimalPlaces_Max, '.', sal_True));
517 pExport->AddAttribute(sAttrValue, sValue);
518 }
519 }
520 }
521 break;
522 }
523 }
524
SetNumberFormatAttributes(const sal_Int32 nNumberFormat,const double & rValue,sal_Bool bExportValue)525 void XMLNumberFormatAttributesExportHelper::SetNumberFormatAttributes(
526 const sal_Int32 nNumberFormat, const double& rValue, sal_Bool bExportValue)
527 {
528 if (pExport)
529 {
530 sal_Bool bIsStandard;
531 rtl::OUString sCurrency;
532 sal_Int16 nTypeKey = GetCellType(nNumberFormat, sCurrency, bIsStandard);
533 WriteAttributes(nTypeKey, rValue, sCurrency, bExportValue);
534 }
535 else {
536 DBG_ERROR("no SvXMLExport given");
537 }
538 }
539
SetNumberFormatAttributes(const rtl::OUString & rValue,const rtl::OUString & rCharacters,sal_Bool bExportValue,sal_Bool bExportTypeAttribute)540 void XMLNumberFormatAttributesExportHelper::SetNumberFormatAttributes(
541 const rtl::OUString& rValue, const rtl::OUString& rCharacters,
542 sal_Bool bExportValue, sal_Bool bExportTypeAttribute)
543 {
544 if (pExport)
545 {
546 if (bExportTypeAttribute)
547 pExport->AddAttribute(sAttrValueType, XML_STRING);
548 if (bExportValue && rValue.getLength() && (rValue != rCharacters))
549 pExport->AddAttribute(sAttrStringValue, rValue);
550 }
551 else {
552 DBG_ERROR("no SvXMLExport given");
553 }
554 }
555