1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
|
/*************************************************************************
*
* $RCSfile: XMLConverter.cxx,v $
*
* $Revision: 1.19 $
*
* last change: $Author: sab $ $Date: 2001-11-15 11:36:12 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#ifdef PCH
#include "filt_pch.hxx"
#endif
#pragma hdrstop
//___________________________________________________________________
#ifndef _SC_XMLCONVERTER_HXX
#include "XMLConverter.hxx"
#endif
#ifndef SC_RANGELST_HXX
#include "rangelst.hxx"
#endif
#ifndef SC_RANGEUTL_HXX
#include "rangeutl.hxx"
#endif
#ifndef SC_DOCUNO_HXX
#include "docuno.hxx"
#endif
#ifndef SC_CONVUNO_HXX
#include "convuno.hxx"
#endif
#ifndef SC_DOCUMENT_HXX
#include "document.hxx"
#endif
#ifndef _DATETIME_HXX
#include <tools/datetime.hxx>
#endif
#ifndef _XMLOFF_XMLTOKEN_HXX
#include <xmloff/xmltoken.hxx>
#endif
#ifndef _XMLOFF_XMLUCONV_HXX
#include <xmloff/xmluconv.hxx>
#endif
#ifndef _COM_SUN_STAR_UTIL_DATETIME_HPP_
#include <com/sun/star/util/DateTime.hpp>
#endif
using namespace ::rtl;
using namespace ::com::sun::star;
using namespace xmloff::token;
//___________________________________________________________________
void ScXMLConverter::AssignString(
OUString& rString,
const OUString& rNewStr,
sal_Bool bAppendStr )
{
if( bAppendStr )
{
if( rNewStr.getLength() )
{
if( rString.getLength() )
rString += GetXMLToken( XML_WS );
rString += rNewStr;
}
}
else
rString = rNewStr;
}
sal_Int32 ScXMLConverter::IndexOf(
const OUString& rString,
sal_Unicode cSearchChar,
sal_Int32 nOffset,
sal_Unicode cQuote )
{
sal_Int32 nLength = rString.getLength();
sal_Int32 nIndex = nOffset;
sal_Bool bQuoted = sal_False;
sal_Bool bExitLoop = sal_False;
while( !bExitLoop && (nIndex < nLength) )
{
sal_Unicode cCode = rString[ nIndex ];
bExitLoop = (cCode == cSearchChar) && !bQuoted;
bQuoted = (bQuoted != (cCode == cQuote));
if( !bExitLoop )
nIndex++;
}
return (nIndex < nLength) ? nIndex : -1;
}
sal_Int32 ScXMLConverter::IndexOfDifferent(
const OUString& rString,
sal_Unicode cSearchChar,
sal_Int32 nOffset )
{
sal_Int32 nLength = rString.getLength();
sal_Int32 nIndex = nOffset;
sal_Bool bExitLoop = sal_False;
while( !bExitLoop && (nIndex < nLength) )
{
bExitLoop = (rString[ nIndex ] != cSearchChar);
if( !bExitLoop )
nIndex++;
}
return (nIndex < nLength) ? nIndex : -1;
}
//___________________________________________________________________
void ScXMLConverter::GetTokenByOffset(
OUString& rToken,
const OUString& rString,
sal_Int32& nOffset,
sal_Unicode cQuote )
{
sal_Int32 nLength = rString.getLength();
if( nOffset >= nLength )
{
rToken = OUString();
nOffset = -1;
}
else
{
sal_Int32 nTokenEnd = IndexOf( rString, ' ', nOffset );
if( nTokenEnd < 0 )
nTokenEnd = nLength;
rToken = rString.copy( nOffset, nTokenEnd - nOffset );
sal_Int32 nNextBegin = IndexOfDifferent( rString, ' ', nTokenEnd );
nOffset = (nNextBegin < 0) ? nLength : nNextBegin;
}
}
sal_Int32 ScXMLConverter::GetTokenCount( const OUString& rString )
{
OUString sToken;
sal_Int32 nCount = 0;
sal_Int32 nOffset = 0;
while( nOffset >= 0 )
{
GetTokenByOffset( sToken, rString, nOffset );
if( nOffset >= 0 )
nCount++;
}
return nCount;
}
void ScXMLConverter::AppendString( OUString& rString, const OUString& rNewStr )
{
AssignString( rString, rNewStr, sal_True );
}
ScDocument* ScXMLConverter::GetScDocument( uno::Reference< frame::XModel > xModel )
{
if (xModel.is())
{
ScModelObj* pDocObj = ScModelObj::getImplementation( xModel );
return pDocObj ? pDocObj->GetDocument() : NULL;
}
return NULL;
}
//___________________________________________________________________
sal_Bool ScXMLConverter::GetAddressFromString(
ScAddress& rAddress,
const OUString& rAddressStr,
const ScDocument* pDocument,
sal_Int32& nOffset )
{
OUString sToken;
GetTokenByOffset( sToken, rAddressStr, nOffset );
if( nOffset >= 0 )
return ((rAddress.Parse( sToken, (ScDocument*) pDocument ) & SCA_VALID) == SCA_VALID);
return sal_False;
}
sal_Bool ScXMLConverter::GetRangeFromString(
ScRange& rRange,
const OUString& rRangeStr,
const ScDocument* pDocument,
sal_Int32& nOffset )
{
OUString sToken;
sal_Bool bResult(sal_False);
GetTokenByOffset( sToken, rRangeStr, nOffset );
if( nOffset >= 0 )
{
sal_Int32 nIndex = IndexOf( sToken, GetXMLToken(XML__COLON)[0], 0 );
if( nIndex < 0 )
{
bResult = ((rRange.aStart.Parse( sToken, (ScDocument*) pDocument ) & SCA_VALID) == SCA_VALID);
rRange.aEnd = rRange.aStart;
}
else
{
bResult = (((rRange.aStart.Parse( sToken.copy( 0, nIndex ), (ScDocument*) pDocument ) & SCA_VALID) == SCA_VALID) &&
((rRange.aEnd.Parse( sToken.copy( nIndex + 1 ), (ScDocument*) pDocument ) & SCA_VALID) == SCA_VALID));
}
}
return bResult;
}
void ScXMLConverter::GetRangeListFromString(
ScRangeList& rRangeList,
const OUString& rRangeListStr,
const ScDocument* pDocument )
{
DBG_ASSERT( rRangeListStr.getLength(), "ScXMLConverter::GetRangeListFromString - empty string!" );
sal_Int32 nOffset = 0;
while( nOffset >= 0 )
{
ScRange* pRange = new ScRange;
if( GetRangeFromString( *pRange, rRangeListStr, pDocument, nOffset ) && (nOffset >= 0) )
rRangeList.Insert( pRange, LIST_APPEND );
}
}
//___________________________________________________________________
sal_Bool ScXMLConverter::GetAreaFromString(
ScArea& rArea,
const OUString& rRangeStr,
const ScDocument* pDocument,
sal_Int32& nOffset )
{
ScRange aScRange;
sal_Bool bResult(sal_False);
if( GetRangeFromString( aScRange, rRangeStr, pDocument, nOffset ) && (nOffset >= 0) )
{
rArea.nTab = aScRange.aStart.Tab();
rArea.nColStart = aScRange.aStart.Col();
rArea.nRowStart = aScRange.aStart.Row();
rArea.nColEnd = aScRange.aEnd.Col();
rArea.nRowEnd = aScRange.aEnd.Row();
bResult = sal_True;
}
return bResult;
}
//___________________________________________________________________
sal_Bool ScXMLConverter::GetAddressFromString(
table::CellAddress& rAddress,
const OUString& rAddressStr,
const ScDocument* pDocument,
sal_Int32& nOffset )
{
ScAddress aScAddress;
sal_Bool bResult(sal_False);
if( GetAddressFromString( aScAddress, rAddressStr, pDocument, nOffset ) && (nOffset >= 0) )
{
ScUnoConversion::FillApiAddress( rAddress, aScAddress );
bResult = sal_True;
}
return bResult;
}
sal_Bool ScXMLConverter::GetRangeFromString(
table::CellRangeAddress& rRange,
const OUString& rRangeStr,
const ScDocument* pDocument,
sal_Int32& nOffset )
{
ScRange aScRange;
sal_Bool bResult(sal_False);
if( GetRangeFromString( aScRange, rRangeStr, pDocument, nOffset ) && (nOffset >= 0) )
{
ScUnoConversion::FillApiRange( rRange, aScRange );
bResult = sal_True;
}
return bResult;
}
void ScXMLConverter::GetRangeListFromString(
uno::Sequence< table::CellRangeAddress >& rRangeSeq,
const OUString& rRangeListStr,
const ScDocument* pDocument )
{
DBG_ASSERT( rRangeListStr.getLength(), "ScXMLConverter::GetRangeListFromString - empty string!" );
table::CellRangeAddress aRange;
sal_Int32 nOffset = 0;
while( nOffset >= 0 )
{
if( GetRangeFromString( aRange, rRangeListStr, pDocument, nOffset ) && (nOffset >= 0) )
{
rRangeSeq.realloc( rRangeSeq.getLength() + 1 );
rRangeSeq[ rRangeSeq.getLength() - 1 ] = aRange;
}
}
}
//___________________________________________________________________
void ScXMLConverter::GetStringFromAddress(
OUString& rString,
const ScAddress& rAddress,
const ScDocument* pDocument,
sal_Bool bAppendStr,
sal_uInt16 nFormatFlags )
{
if (pDocument && pDocument->HasTable(rAddress.Tab()))
{
String sAddress;
rAddress.Format( sAddress, nFormatFlags, (ScDocument*) pDocument );
AssignString( rString, sAddress, bAppendStr );
}
}
void ScXMLConverter::GetStringFromRange(
OUString& rString,
const ScRange& rRange,
const ScDocument* pDocument,
sal_Bool bAppendStr,
sal_uInt16 nFormatFlags )
{
if (pDocument && pDocument->HasTable(rRange.aStart.Tab()))
{
ScAddress aStartAddress( rRange.aStart );
ScAddress aEndAddress( rRange.aEnd );
String sStartAddress;
String sEndAddress;
aStartAddress.Format( sStartAddress, nFormatFlags, (ScDocument*) pDocument );
aEndAddress.Format( sEndAddress, nFormatFlags, (ScDocument*) pDocument );
OUString sOUStartAddress( sStartAddress );
sOUStartAddress += GetXMLToken( XML__COLON );
sOUStartAddress += OUString( sEndAddress );
AssignString( rString, sOUStartAddress, bAppendStr );
}
}
void ScXMLConverter::GetStringFromRangeList(
OUString& rString,
const ScRangeList* pRangeList,
const ScDocument* pDocument,
sal_uInt16 nFormatFlags )
{
OUString sRangeListStr;
if( pRangeList )
{
sal_Int32 nCount = pRangeList->Count();
for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
{
const ScRange* pRange = pRangeList->GetObject( nIndex );
if( pRange )
GetStringFromRange( sRangeListStr, *pRange, pDocument, sal_True, nFormatFlags );
}
}
rString = sRangeListStr;
}
//___________________________________________________________________
void ScXMLConverter::GetStringFromArea(
OUString& rString,
const ScArea& rArea,
const ScDocument* pDocument,
sal_Bool bAppendStr,
sal_uInt16 nFormatFlags )
{
ScRange aRange( rArea.nColStart, rArea.nRowStart, rArea.nTab, rArea.nColEnd, rArea.nRowEnd, rArea.nTab );
GetStringFromRange( rString, aRange, pDocument, bAppendStr, nFormatFlags );
}
//___________________________________________________________________
void ScXMLConverter::GetStringFromAddress(
OUString& rString,
const table::CellAddress& rAddress,
const ScDocument* pDocument,
sal_Bool bAppendStr,
sal_uInt16 nFormatFlags )
{
ScAddress aScAddress( static_cast<USHORT>(rAddress.Column), static_cast<USHORT>(rAddress.Row), rAddress.Sheet );
GetStringFromAddress( rString, aScAddress, pDocument, bAppendStr, nFormatFlags );
}
void ScXMLConverter::GetStringFromRange(
OUString& rString,
const table::CellRangeAddress& rRange,
const ScDocument* pDocument,
sal_Bool bAppendStr,
sal_uInt16 nFormatFlags )
{
ScRange aScRange( static_cast<USHORT>(rRange.StartColumn), static_cast<USHORT>(rRange.StartRow), rRange.Sheet,
static_cast<USHORT>(rRange.EndColumn), static_cast<USHORT>(rRange.EndRow), rRange.Sheet );
GetStringFromRange( rString, aScRange, pDocument, bAppendStr, nFormatFlags );
}
void ScXMLConverter::GetStringFromRangeList(
OUString& rString,
const uno::Sequence< table::CellRangeAddress >& rRangeSeq,
const ScDocument* pDocument,
sal_uInt16 nFormatFlags )
{
OUString sRangeListStr;
sal_Int32 nCount = rRangeSeq.getLength();
for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
{
const table::CellRangeAddress& rRange = rRangeSeq[ nIndex ];
GetStringFromRange( sRangeListStr, rRange, pDocument, sal_True, nFormatFlags );
}
rString = sRangeListStr;
}
//___________________________________________________________________
sheet::GeneralFunction ScXMLConverter::GetFunctionFromString( const OUString& sFunction )
{
if( IsXMLToken(sFunction, XML_SUM ) )
return sheet::GeneralFunction_SUM;
if( IsXMLToken(sFunction, XML_AUTO ) )
return sheet::GeneralFunction_AUTO;
if( IsXMLToken(sFunction, XML_COUNT ) )
return sheet::GeneralFunction_COUNT;
if( IsXMLToken(sFunction, XML_COUNTNUMS ) )
return sheet::GeneralFunction_COUNTNUMS;
if( IsXMLToken(sFunction, XML_PRODUCT ) )
return sheet::GeneralFunction_PRODUCT;
if( IsXMLToken(sFunction, XML_AVERAGE ) )
return sheet::GeneralFunction_AVERAGE;
if( IsXMLToken(sFunction, XML_MAX ) )
return sheet::GeneralFunction_MAX;
if( IsXMLToken(sFunction, XML_MIN ) )
return sheet::GeneralFunction_MIN;
if( IsXMLToken(sFunction, XML_STDEV ) )
return sheet::GeneralFunction_STDEV;
if( IsXMLToken(sFunction, XML_STDEVP ) )
return sheet::GeneralFunction_STDEVP;
if( IsXMLToken(sFunction, XML_VAR ) )
return sheet::GeneralFunction_VAR;
if( IsXMLToken(sFunction, XML_VARP ) )
return sheet::GeneralFunction_VARP;
return sheet::GeneralFunction_NONE;
}
ScSubTotalFunc ScXMLConverter::GetSubTotalFuncFromString( const OUString& sFunction )
{
if( IsXMLToken(sFunction, XML_SUM ) )
return SUBTOTAL_FUNC_SUM;
if( IsXMLToken(sFunction, XML_COUNT ) )
return SUBTOTAL_FUNC_CNT;
if( IsXMLToken(sFunction, XML_COUNTNUMS ) )
return SUBTOTAL_FUNC_CNT2;
if( IsXMLToken(sFunction, XML_PRODUCT ) )
return SUBTOTAL_FUNC_PROD;
if( IsXMLToken(sFunction, XML_AVERAGE ) )
return SUBTOTAL_FUNC_AVE;
if( IsXMLToken(sFunction, XML_MAX ) )
return SUBTOTAL_FUNC_MAX;
if( IsXMLToken(sFunction, XML_MIN ) )
return SUBTOTAL_FUNC_MIN;
if( IsXMLToken(sFunction, XML_STDEV ) )
return SUBTOTAL_FUNC_STD;
if( IsXMLToken(sFunction, XML_STDEVP ) )
return SUBTOTAL_FUNC_STDP;
if( IsXMLToken(sFunction, XML_VAR ) )
return SUBTOTAL_FUNC_VAR;
if( IsXMLToken(sFunction, XML_VARP ) )
return SUBTOTAL_FUNC_VARP;
return SUBTOTAL_FUNC_NONE;
}
//___________________________________________________________________
void ScXMLConverter::GetStringFromFunction(
OUString& rString,
const sheet::GeneralFunction eFunction,
sal_Bool bAppendStr )
{
OUString sFuncStr;
switch( eFunction )
{
case sheet::GeneralFunction_AUTO: sFuncStr = GetXMLToken( XML_AUTO ); break;
case sheet::GeneralFunction_AVERAGE: sFuncStr = GetXMLToken( XML_AVERAGE ); break;
case sheet::GeneralFunction_COUNT: sFuncStr = GetXMLToken( XML_COUNT ); break;
case sheet::GeneralFunction_COUNTNUMS: sFuncStr = GetXMLToken( XML_COUNTNUMS ); break;
case sheet::GeneralFunction_MAX: sFuncStr = GetXMLToken( XML_MAX ); break;
case sheet::GeneralFunction_MIN: sFuncStr = GetXMLToken( XML_MIN ); break;
case sheet::GeneralFunction_NONE: sFuncStr = GetXMLToken( XML_NONE ); break;
case sheet::GeneralFunction_PRODUCT: sFuncStr = GetXMLToken( XML_PRODUCT ); break;
case sheet::GeneralFunction_STDEV: sFuncStr = GetXMLToken( XML_STDEV ); break;
case sheet::GeneralFunction_STDEVP: sFuncStr = GetXMLToken( XML_STDEVP ); break;
case sheet::GeneralFunction_SUM: sFuncStr = GetXMLToken( XML_SUM ); break;
case sheet::GeneralFunction_VAR: sFuncStr = GetXMLToken( XML_VAR ); break;
case sheet::GeneralFunction_VARP: sFuncStr = GetXMLToken( XML_VARP ); break;
}
AssignString( rString, sFuncStr, bAppendStr );
}
void ScXMLConverter::GetStringFromFunction(
OUString& rString,
const ScSubTotalFunc eFunction,
sal_Bool bAppendStr )
{
OUString sFuncStr;
switch( eFunction )
{
case SUBTOTAL_FUNC_AVE: sFuncStr = GetXMLToken( XML_AVERAGE ); break;
case SUBTOTAL_FUNC_CNT: sFuncStr = GetXMLToken( XML_COUNT ); break;
case SUBTOTAL_FUNC_CNT2: sFuncStr = GetXMLToken( XML_COUNTNUMS ); break;
case SUBTOTAL_FUNC_MAX: sFuncStr = GetXMLToken( XML_MAX ); break;
case SUBTOTAL_FUNC_MIN: sFuncStr = GetXMLToken( XML_MIN ); break;
case SUBTOTAL_FUNC_NONE: sFuncStr = GetXMLToken( XML_NONE ); break;
case SUBTOTAL_FUNC_PROD: sFuncStr = GetXMLToken( XML_PRODUCT ); break;
case SUBTOTAL_FUNC_STD: sFuncStr = GetXMLToken( XML_STDEV ); break;
case SUBTOTAL_FUNC_STDP: sFuncStr = GetXMLToken( XML_STDEVP ); break;
case SUBTOTAL_FUNC_SUM: sFuncStr = GetXMLToken( XML_SUM ); break;
case SUBTOTAL_FUNC_VAR: sFuncStr = GetXMLToken( XML_VAR ); break;
case SUBTOTAL_FUNC_VARP: sFuncStr = GetXMLToken( XML_VARP ); break;
}
AssignString( rString, sFuncStr, bAppendStr );
}
//___________________________________________________________________
sheet::DataPilotFieldOrientation ScXMLConverter::GetOrientationFromString(
const OUString& rString )
{
if( IsXMLToken(rString, XML_COLUMN ) )
return sheet::DataPilotFieldOrientation_COLUMN;
if( IsXMLToken(rString, XML_ROW ) )
return sheet::DataPilotFieldOrientation_ROW;
if( IsXMLToken(rString, XML_PAGE ) )
return sheet::DataPilotFieldOrientation_PAGE;
if( IsXMLToken(rString, XML_DATA ) )
return sheet::DataPilotFieldOrientation_DATA;
return sheet::DataPilotFieldOrientation_HIDDEN;
}
//___________________________________________________________________
void ScXMLConverter::GetStringFromOrientation(
OUString& rString,
const sheet::DataPilotFieldOrientation eOrientation,
sal_Bool bAppendStr )
{
OUString sOrientStr;
switch( eOrientation )
{
case sheet::DataPilotFieldOrientation_HIDDEN:
sOrientStr = GetXMLToken( XML_HIDDEN );
break;
case sheet::DataPilotFieldOrientation_COLUMN:
sOrientStr = GetXMLToken( XML_COLUMN );
break;
case sheet::DataPilotFieldOrientation_ROW:
sOrientStr = GetXMLToken( XML_ROW );
break;
case sheet::DataPilotFieldOrientation_PAGE:
sOrientStr = GetXMLToken( XML_PAGE );
break;
case sheet::DataPilotFieldOrientation_DATA:
sOrientStr = GetXMLToken( XML_DATA );
break;
}
AssignString( rString, sOrientStr, bAppendStr );
}
//___________________________________________________________________
ScDetectiveObjType ScXMLConverter::GetDetObjTypeFromString( const OUString& rString )
{
if( IsXMLToken(rString, XML_FROM_SAME_TABLE ) )
return SC_DETOBJ_ARROW;
if( IsXMLToken(rString, XML_FROM_ANOTHER_TABLE ) )
return SC_DETOBJ_FROMOTHERTAB;
if( IsXMLToken(rString, XML_TO_ANOTHER_TABLE ) )
return SC_DETOBJ_TOOTHERTAB;
return SC_DETOBJ_NONE;
}
sal_Bool ScXMLConverter::GetDetOpTypeFromString( ScDetOpType& rDetOpType, const OUString& rString )
{
if( IsXMLToken(rString, XML_TRACE_DEPENDENTS ) )
rDetOpType = SCDETOP_ADDSUCC;
else if( IsXMLToken(rString, XML_TRACE_PRECEDENTS ) )
rDetOpType = SCDETOP_ADDPRED;
else if( IsXMLToken(rString, XML_TRACE_ERRORS ) )
rDetOpType = SCDETOP_ADDERROR;
else if( IsXMLToken(rString, XML_REMOVE_DEPENDENTS ) )
rDetOpType = SCDETOP_DELSUCC;
else if( IsXMLToken(rString, XML_REMOVE_PRECEDENTS ) )
rDetOpType = SCDETOP_DELPRED;
else
return sal_False;
return sal_True;
}
//___________________________________________________________________
void ScXMLConverter::GetStringFromDetObjType(
OUString& rString,
const ScDetectiveObjType eObjType,
sal_Bool bAppendStr )
{
OUString sTypeStr;
switch( eObjType )
{
case SC_DETOBJ_ARROW:
sTypeStr = GetXMLToken( XML_FROM_SAME_TABLE );
break;
case SC_DETOBJ_FROMOTHERTAB:
sTypeStr = GetXMLToken( XML_FROM_ANOTHER_TABLE );
break;
case SC_DETOBJ_TOOTHERTAB:
sTypeStr = GetXMLToken( XML_TO_ANOTHER_TABLE );
break;
}
AssignString( rString, sTypeStr, bAppendStr );
}
void ScXMLConverter::GetStringFromDetOpType(
OUString& rString,
const ScDetOpType eOpType,
sal_Bool bAppendStr )
{
OUString sTypeStr;
switch( eOpType )
{
case SCDETOP_ADDSUCC:
sTypeStr = GetXMLToken( XML_TRACE_DEPENDENTS );
break;
case SCDETOP_ADDPRED:
sTypeStr = GetXMLToken( XML_TRACE_PRECEDENTS );
break;
case SCDETOP_ADDERROR:
sTypeStr = GetXMLToken( XML_TRACE_ERRORS );
break;
case SCDETOP_DELSUCC:
sTypeStr = GetXMLToken( XML_REMOVE_DEPENDENTS );
break;
case SCDETOP_DELPRED:
sTypeStr = GetXMLToken( XML_REMOVE_PRECEDENTS );
break;
}
AssignString( rString, sTypeStr, bAppendStr );
}
//___________________________________________________________________
void ScXMLConverter::ParseFormula(OUString& sFormula, const sal_Bool bIsFormula)
{
OUStringBuffer sBuffer(sFormula.getLength());
sal_Bool bInQuotationMarks(sal_False);
sal_Bool bInDoubleQuotationMarks(sal_False);
sal_Int16 nCountBraces(0);
sal_Unicode chPrevious('=');
for (sal_Int32 i = 0; i < sFormula.getLength(); i++)
{
if (sFormula[i] == '\'' && !bInDoubleQuotationMarks)
bInQuotationMarks = !bInQuotationMarks;
else if (sFormula[i] == '"' && !bInQuotationMarks)
bInDoubleQuotationMarks = !bInDoubleQuotationMarks;
if (bInQuotationMarks || bInDoubleQuotationMarks)
sBuffer.append(sFormula[i]);
else if (sFormula[i] == '[')
nCountBraces++;
else if (sFormula[i] == ']')
nCountBraces--;
else if ((sFormula[i] != '.') ||
((nCountBraces == 0) && bIsFormula) ||
!((chPrevious == '[') || (chPrevious == ':') || (chPrevious == ' ') || (chPrevious == '=')))
sBuffer.append(sFormula[i]);
chPrevious = sFormula[i];
}
sFormula = sBuffer.makeStringAndClear();
}
//_____________________________________________________________________
void ScXMLConverter::ConvertDateTimeToString(const DateTime& aDateTime, rtl::OUStringBuffer& sDate)
{
util::DateTime aAPIDateTime;
ConvertCoreToAPIDateTime(aDateTime, aAPIDateTime);
SvXMLUnitConverter::convertDateTime(sDate, aAPIDateTime);
}
void ScXMLConverter::ConvertStringToDateTime(const rtl::OUString& sDate, DateTime& aDateTime, SvXMLUnitConverter* pUnitConverter)
{
com::sun::star::util::DateTime aAPIDateTime;
pUnitConverter->convertDateTime(aAPIDateTime, sDate);
ConvertAPIToCoreDateTime(aAPIDateTime, aDateTime);
}
void ScXMLConverter::ConvertCoreToAPIDateTime(const DateTime& aDateTime, util::DateTime& rDateTime)
{
rDateTime.Year = aDateTime.GetYear();
rDateTime.Month = aDateTime.GetMonth();
rDateTime.Day = aDateTime.GetDay();
rDateTime.Hours = aDateTime.GetHour();
rDateTime.Minutes = aDateTime.GetMin();
rDateTime.Seconds = aDateTime.GetSec();
rDateTime.HundredthSeconds = aDateTime.Get100Sec();
}
void ScXMLConverter::ConvertAPIToCoreDateTime(const util::DateTime& aDateTime, DateTime& rDateTime)
{
Date aDate(aDateTime.Day, aDateTime.Month, aDateTime.Year);
Time aTime(aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds, aDateTime.HundredthSeconds);
DateTime aTempDateTime (aDate, aTime);
rDateTime = aTempDateTime;
}
|