summaryrefslogtreecommitdiff
path: root/sc/source/filter/excel/excdoc.cxx
blob: 32abbe3a018c7499e4cc14d335dad6dbb480bcc8 (plain)
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
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
/*************************************************************************
 *
 *  $RCSfile: excdoc.cxx,v $
 *
 *  $Revision: 1.22 $
 *
 *  last change: $Author: dr $ $Date: 2001-05-10 17:24:42 $
 *
 *  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

//------------------------------------------------------------------------

#include <math.h>

#include "scitems.hxx"

#include <svx/svdobj.hxx>
#include <svx/svditer.hxx>
#include <svx/svdpage.hxx>
#include <svx/lrspitem.hxx>
#include <svx/ulspitem.hxx>
#include <svtools/intitem.hxx>
#include <svtools/zformat.hxx>
#include <so3/svstor.hxx>
#include <sfx2/objsh.hxx>
#include <tools/urlobj.hxx>
#include <rtl/ustring>

#include <com/sun/star/uno/Reference.h>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/container/XIndexAccess.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/sheet/XAreaLinks.hpp>
#include <com/sun/star/sheet/XAreaLink.hpp>

#include "drwlayer.hxx"

#include "cell.hxx"
#include "dociter.hxx"
#include "document.hxx"
#include "rangenam.hxx"
#include "dbcolect.hxx"
#include "global.hxx"
#include "globstr.hrc"
#include "progress.hxx"
#include "conditio.hxx"
#include "dpobject.hxx"
#include "attrib.hxx"
#include "scextopt.hxx"
#include "stlsheet.hxx"
#include "stlpool.hxx"
#include "olinetab.hxx"
#include "unonames.hxx"
#include "convuno.hxx"

#include "excdoc.hxx"
#include "excupn.hxx"
#include "namebuff.hxx"

#include "xcl97dum.hxx"
#include "xcl97rec.hxx"
#include "xcl97esc.hxx"

#ifndef _SC_XCLEXPPIVOTTABLES_HXX
#include "XclExpPivotTables.hxx"
#endif
#ifndef _SC_XCLEXPCHANGETRACK_HXX
#include "XclExpChangeTrack.hxx"
#endif

using namespace ::com::sun::star;
using namespace ::rtl;


NameBuffer*     ExcDocument::pTabNames = NULL;



static String lcl_GetVbaTabName( UINT16 n )
{
    String  aRet( RTL_CONSTASCII_USTRINGPARAM( "__VBA__" ) );
    aRet += String::CreateFromInt32( n );
    return aRet;
}




ExcRecordListRefs::~ExcRecordListRefs()
{
}




ExcRecordListInst::~ExcRecordListInst()
{
    ExcRecord*  pDel = ( ExcRecord* ) List::First();
    while( pDel )
    {
        delete pDel;
        pDel = ( ExcRecord* ) List::Next();
    }
}




DefRowXFs::DefRowXFs( void )
{
    nLastList = 0;
    nLastRow = 0;
}


DefRowXFs::~DefRowXFs()
{
}


//void DefRowXFs::ChangeXF( ExcRow& rRow )
void DefRowXFs::ChangeXF( UINT16 nRowNum, UINT16& rXF )
{
    UINT32  nCnt;
    UINT16  nR, nXF;

    nCnt = UINT32List::Count();
    for( UINT32 n = ( nRowNum > nLastRow )? nLastList : 0 ; n < nCnt ; n++ )
    {
        Get( UINT32List::Get( n ), nR, nXF );
        if( nRowNum == nR )
        {
            rXF = nXF;

            nLastList = n;
            nLastRow = nR;

            return;
        }
    }
}




ExcRowBlock* ExcTable::pRowBlock = NULL;

ExcTable::ExcTable( RootData* pRD ) :
    ExcRoot( pRD ),
    nScTab( 0 ),
    nExcTab( EXC_TABBUF_INVALID ),
    pDefRowXFs( NULL )
{   }


ExcTable::ExcTable( RootData* pRD, UINT16 nScTable ) :
    ExcRoot( pRD ),
    nScTab( nScTable ),
    nExcTab( pRD->pTabBuffer->GetExcTable( nScTable ) ),
    pDefRowXFs( NULL )
{   }


ExcTable::~ExcTable()
{
    Clear();
}


void ExcTable::Clear( void )
{
    if( pDefRowXFs )
    {
        delete pDefRowXFs;
        pDefRowXFs = NULL;
    }
}


void ExcTable::AddRow( ExcRow* pRow )
{
    DBG_ASSERT( pRowBlock, "ExcTable::AddRow() - missing RowBlock!" );
    ExcRowBlock* pNewRowBlock = pRowBlock->Append( pRow );
    if( pNewRowBlock )
    {
        pRowBlock = pNewRowBlock;
        Add( pRowBlock );
    }
}


void ExcTable::AddUsedRow( ExcRow*& rpRow )
{
    if( rpRow->IsDefault() )
        delete rpRow;
    else
        AddRow( rpRow );
}


void ExcTable::AddWebQueries()
{
    SfxObjectShell* pShell = pExcRoot->pDoc->GetDocumentShell();
    if( !pShell ) return;

    uno::Reference< frame::XModel > xModel( pShell->GetModel() );
    uno::Reference< beans::XPropertySet > xPropSet( xModel, uno::UNO_QUERY );
    if( !xPropSet.is() ) return;

    uno::Reference< sheet::XAreaLinks > xAreaLinks;
    uno::Any aAny( xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_AREALINKS ) ) ) );
    if( !(aAny >>= xAreaLinks) ) return;

    uno::Reference< container::XIndexAccess > xLinksIAccess( xAreaLinks, uno::UNO_QUERY );
    if( !xLinksIAccess.is() ) return;

    const OUString aPropFilter( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_FILTER ) );
//  const OUString aPropFilterOpt( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_FILTOPT ) );
    const OUString aPropURL( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_LINKURL ) );
    const OUString aPropRefresh( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_REFDELAY ) );
    OUString aFilter, /*aFilterOpt,*/ aURL;
    OUString aWebQueryFilter( RTL_CONSTASCII_USTRINGPARAM( EXC_WEBQRY_FILTER ) );
    String aRangeName;
    sal_Int32 nRefresh;

    sal_Int32 nCount = xLinksIAccess->getCount();
    for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
    {
        uno::Reference< sheet::XAreaLink > xAreaLink;
        uno::Any aLinkAny( xLinksIAccess->getByIndex( nIndex ) );
        if( aLinkAny >>= xAreaLink )
        {
            table::CellRangeAddress aDestRange( xAreaLink->getDestArea() );
            if( aDestRange.Sheet == nScTab )
            {
                uno::Reference< beans::XPropertySet > xLinkProp( xAreaLink, uno::UNO_QUERY );
                if( xLinkProp.is() )
                {
                    aLinkAny = xLinkProp->getPropertyValue( aPropFilter );
                    aLinkAny >>= aFilter;
                    if( aFilter == aWebQueryFilter )
                    {
                        // get properties
//                      aLinkAny = xLinkProp->getPropertyValue( aPropFilterOpt );
//                      aLinkAny >>= aFilterOpt;
                        aLinkAny = xLinkProp->getPropertyValue( aPropURL );
                        aLinkAny >>= aURL;
                        aLinkAny = xLinkProp->getPropertyValue( aPropRefresh );
                        aLinkAny >>= nRefresh;
                        INetURLObject aURLObj( ScGlobal::GetAbsDocName( aURL, pExcRoot->pDoc->GetDocumentShell() ) );

                        // find range or create a new range
                        ScRange aScDestRange;
                        ScUnoConversion::FillScRange( aScDestRange, aDestRange );
                        ScRangeData* pRangeData = pExcRoot->pDoc->GetRangeName()->GetRangeAtBlock( aScDestRange );
                        if( pRangeData )
                            aRangeName = pRangeData->GetName();
                        else
                        {
                            ExcName* pExcName = new ExcName( pExcRoot, aScDestRange, aURLObj.getBase() );
                            pExcRoot->pNameList->Append( pExcName );
                            aRangeName = pExcName->GetName();
                        }

                        // create the web query record
                        Add( new XclExpWebQuery( aRangeName, aURLObj.getFSysPath( INetURLObject::FSYS_DOS ),
                            xAreaLink->getSourceArea(), nRefresh ) );
                    }
                }
            }
        }
    }
}


void ExcTable::SetDefRowXF( UINT16 nXF, UINT16 n )
{
    if( !pDefRowXFs )
        pDefRowXFs = new DefRowXFs;

    pDefRowXFs->Add( n, nXF );
}


void ExcTable::FillAsHeader( ExcRecordListRefs& rBSRecList )
{
    RootData&           rR          = *pExcRoot;
    ScDocument&         rDoc        = *rR.pDoc;
    XclExpTabNumBuffer& rTabBuffer  = *rR.pTabBuffer;

    if ( rR.eDateiTyp < Biff8 )
        Add( new ExcBofW );
    else
        Add( new ExcBofW8 );

    UINT16  nC;
    String  aTmpString;
    UINT16  nScTabCount     = rTabBuffer.GetScTabCount();
    UINT16  nExcTabCount    = rTabBuffer.GetExcTabCount();
    UINT16  nCodenames      = rR.nCodenames;

    ExcNameList*    pNameL      = rR.pNameList  = new ExcNameList;
    ExcPalette2*    pPalette2   = rR.pPalette2  = new ExcPalette2( *rR.pColor );
    UsedFontList*   pFontRecs   = rR.pFontRecs  = new UsedFontList( rR ) ;
    UsedFormList*   pFormRecs   = rR.pFormRecs  = new UsedFormList;
    UsedAttrList*   pXFRecs     = rR.pXFRecs    = new UsedAttrList( &rR, *pPalette2, *pFontRecs, *pFormRecs );

    XclSstList*         pSstRecs            = NULL;
    XclExternsheetList* pExternsheetRecs    = NULL;     // change: ExternsheetList includes Supbooks
    if ( rR.eDateiTyp >= Biff8 )
    {
        rR.pSstRecs         = pSstRecs          = new XclSstList;
        rR.pExternsheetRecs = pExternsheetRecs  = new XclExternsheetList( &rR );
    }

    rR.pObjRecs = NULL;             // per sheet
    rR.pNoteRecs = NULL;            // per sheet

    pFontRecs->SetBaseIndex( 6 );   // 6 statt 5 wegen Ausfall von 4!
    pFormRecs->SetBaseIndex( 164 ); // siehe auch ValueFormBuffer::nNewFormats
    pXFRecs->SetBaseIndex( 21 );

    ExcFont::SetPalette( *pPalette2 );
    ExcXf::SetPalette( *pPalette2 );

    if( rR.eDateiTyp < Biff8 )
        Add( new ExcDummy_00 );
    else
    {
        // first create style XFs
        SfxStyleSheetIterator   aStyleIter( rDoc.GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA );
        SfxStyleSheetBase*      pStyle = aStyleIter.First();
        ScPatternAttr*          pPatt;

        while( pStyle )
        {
            if( pStyle->IsUserDefined() )
            {
                pPatt = new ScPatternAttr( &pStyle->GetItemSet() );
                pXFRecs->Find( pPatt, TRUE );
            }
            pStyle = aStyleIter.Next();
        }

        Add( new ExcDummy8_00a );
        rR.pTabId = new XclExpChTrTabId( Max( nExcTabCount, nCodenames ) );
        Add( rR.pTabId );
        if( rR.bWriteVBAStorage )
        {
            Add( new XclObproj );
            const String*   p = rR.pExtDocOpt->GetCodename();
            if( p )
                Add( new XclCodename( *p ) );
        }
        Add( new ExcDummy8_00b );
    }

    // erst Namen- und Tabellen-Eintraege aufbauen
    DBG_ASSERT( rDoc.GetRangeName(), "-ExcTable::Header(): Keine Namen? Kann nicht angehen!" );

    String          aName;

    for( nC = 0 ; nC < nScTabCount ; nC++ )
        if( rTabBuffer.IsExportTable( nC ) )
        {
            rDoc.GetName( nC, aTmpString );
            *ExcDocument::pTabNames << aTmpString;
        }

    if ( rR.eDateiTyp < Biff8 )
    {
        // Externcount & Externsheet
        ExcExterncount* pExtCnt = new ExcExterncount( &rR, FALSE );

        Add( pExtCnt );

        ExcExternsheetList*     pExcExtShtList = new ExcExternsheetList;

        DBG_ASSERT( !rR.pExtSheetCntAndRecs, "*ExcTable::Header(): pExtSheetCntAndRecs already exist!" );

        rR.pExtSheetCntAndRecs = new ExcExternDup( *pExtCnt, *pExcExtShtList );

        Add( pExcExtShtList );

        for( nC = 0 ; nC < nScTabCount ; nC++ )
            if( rTabBuffer.IsExportTable( nC ) )
                pExcExtShtList->Add( new ExcExternsheet( &rR, nC ) );

        // Names
        Add( pNameL );

        ScRangeName&            rRangeNames = *rDoc.GetRangeName();
        UINT16                  j, nNames;
        nNames = rRangeNames.GetCount();
        for( j = 0 ; j < nNames ; j++ )
        {
            ScRangeData*        pData = ( ScRangeData * ) rRangeNames[ j ];
            DBG_ASSERT( pData, "-ExcTable::Header(): 1, 2, 3 - wer zaehlt hier falsch?" );

            if ( !rR.bBreakSharedFormula || !pData->HasType( RT_SHARED ) )
            {   // no SHARED_FORMULA_... names if not needed
                pData->SetExportIndex( rR.nRangeNameIndex++ );

                pNameL->Append( new ExcName( &rR, pData ) );
            }
        }
        ScDBCollection&         rDBAreas = *rDoc.GetDBCollection();
        nNames = rDBAreas.GetCount();
        for( j = 0 ; j < nNames ; j++ )
        {
            ScDBData*           pData = ( ScDBData * ) rDBAreas[ j ];
            DBG_ASSERT( pData, "-ExcTable::Header(): 1, 2, 3 - wer zaehlt hier falsch?" );

            pData->SetExportIndex( rR.nRangeNameIndex++ );
            pNameL->Append( new ExcName( &rR, pData ) );
        }

        Add( new ExcDummy_040 );
        Add( new Exc1904( rDoc ) );
        Add( new ExcDummy_041 );
        // Font
        Add( new ExcDummy_01 );
        Add( pFontRecs );
        // Format
        Add( new ExcDummy_Fm );
        Add( pFormRecs );
        // XF + Style
        Add( new ExcDummy_XF );
        Add( pXFRecs );
        // Style
        Add( new ExcDummy_Style );
        // Colors
        Add( pPalette2 );

        // Bundlesheet
        ExcBundlesheetBase* pBS;
        for( nC = 0 ; nC < nScTabCount ; nC++ )
            if( rTabBuffer.IsExportTable( nC ) )
            {
                pBS = new ExcBundlesheet( rR, nC );
                Add( pBS );
                rBSRecList.Append( pBS );
            }
    }
    else
    {
        Add( new ExcDummy8_040 );
        Add( new ExcWindow18( rR ) );
        Add( new Exc1904( rDoc ) );
        Add( new ExcDummy8_041 );
        // Font
        Add( new ExcDummy8_01 );
        Add( pFontRecs );
        // Format
        Add( new ExcDummy8_Fm );
        Add( pFormRecs );
        // XF + Style
        Add( new ExcDummy8_XF );
        Add( pXFRecs );
        // Style
        Add( new ExcDummy8_Style );

        // Pivot Cache
        ScDPCollection*     pDPColl = rDoc.GetDPCollection();
        if( pDPColl )
        {
            XclPivotCacheList* pPCList = new XclPivotCacheList( &rR, *pDPColl );
            rR.pPivotCacheList = pPCList;

            for( const XclPivotCache* pCache = pPCList->First(); pCache; pCache = pPCList->Next() )
            {
                Add( new XclSxIdStm( *pCache ) );
                Add( new XclSxVs( *pCache ) );
                Add( new XclDConRef( pCache->GetRange(), pCache->GetWorkbook() ) );
            }
        }

        // Colors
        Add( pPalette2 );

        // Change tracking
        if( rDoc.GetChangeTrack() )
        {
            rR.pUserBViewList = new XclExpUserBViewList( *rDoc.GetChangeTrack() );
            Add( rR.pUserBViewList );
        }

        // Natural Language Formulas Flag
        Add( new ExcDummy8_UsesElfs );

        // Bundlesheet
        ExcBundlesheetBase* pBS;
        for( nC = 0 ; nC < nScTabCount ; nC++ )
            if( rTabBuffer.IsExportTable( nC ) )
            {
                pBS = new ExcBundlesheet8( rR, nC );
                Add( pBS );
                rBSRecList.Append( pBS );
            }

        for( UINT16 nAdd = 0; nC < nCodenames ; nC++, nAdd++ )
        {
            aTmpString = lcl_GetVbaTabName( nAdd );
            pBS = new ExcBundlesheet8( aTmpString );
            Add( pBS );
            rBSRecList.Append( pBS );
        }

        // COUNTRY always Germany
        Add( new ExcDummy8_Country );
        // SUPBOOKs, XCTs, CRNs, EXTERNSHEET
        Add( pExternsheetRecs );
        // NAMEs
        Add( pNameL );

        ScRangeName&        rRangeNames = *rDoc.GetRangeName();
        UINT16              j, nNames;
        nNames = rRangeNames.GetCount();
        for( j = 0 ; j < nNames ; j++ )
        {
            ScRangeData*    pData = ( ScRangeData * ) rRangeNames[ j ];
            DBG_ASSERT( pData, "-ExcTable::Header(): 1, 2, 3 - wer zaehlt hier falsch?" );

            if ( !rR.bBreakSharedFormula || !pData->HasType( RT_SHARED ) )
            {   // no SHARED_FORMULA_... names if not needed
                ExcName*        pExcNameRec = new ExcName( &rR, pData );

                if( pExcNameRec->IsDummy() )
                    pData->SetExportIndex( 0xFFFF );
                else
                    pData->SetExportIndex( rR.nRangeNameIndex++ );

                pNameL->Append( pExcNameRec );
            }
        }

        // print range and titles
        for( nC = 0 ; nC < nScTabCount ; nC++ )
        {
            pNameL->Append( new XclPrintRange( &rR, nC, rDoc ) );
            pNameL->Append( new XclTitleRange( &rR, nC, rDoc ) );
        }

        ScDBCollection&     rDBAreas = *rDoc.GetDBCollection();
        nNames = rDBAreas.GetCount();
        for( j = 0 ; j < nNames ; j++ )
        {
            ScDBData*       pData = ( ScDBData * ) rDBAreas[ j ];
            DBG_ASSERT( pData, "-ExcTable::Header(): 1, 2, 3 - wer zaehlt hier falsch?" );

            pData->SetExportIndex( rR.nRangeNameIndex++ );
            pNameL->Append( new ExcName( &rR, pData ) );
        }

        // MSODRAWINGGROUP per-document data
        Add( new XclMsodrawinggroup( rR, ESCHER_DggContainer ) );
        // SST, EXTSST
        Add( pSstRecs );
    }

    Add( new ExcEof );
}


void ExcTable::FillAsTable( void )
{
    RootData&           rR          = *pExcRoot;
    ScDocument&         rDoc        = *rR.pDoc;
    XclExpTabNumBuffer& rTabBuffer  = *rR.pTabBuffer;

    if( nScTab >= rTabBuffer.GetScTabCount() )
    {
        CodenameList*       pL = rR.pExtDocOpt->GetCodenames();
        if( pL )
        {
            const String*   p = pL->Next();
            if( p )
                NullTab( p );
        }

        return;
    }

    UINT16                  nLastCol, nLastRow,         // in Tabelle
                            nFirstCol, nFirstRow;
    UINT16                  nPrevRow = 0;
    UINT16                  nColMin;                    // fuer aktuelle Zeile
                                                        //  Row-Records
    const UINT16            nDefXF = 0x0F;
    UINT16                  nCol = 0;
    UINT16                  nRow = 0;

    UINT16                  nMaxFlagCol = rDoc.GetLastFlaggedCol( nScTab );
    UINT16                  nMaxFlagRow = rDoc.GetLastFlaggedRow( nScTab );;

    ExcCell*                pAktExcCell;
    SvNumberFormatter&      rFormatter = *rR.pFormTable;
    const BiffTyp           eDateiTyp = rR.eDateiTyp;

    SfxStyleSheet*          pStSh = ( SfxStyleSheet* ) rDoc.GetStyleSheetPool()->Find(
                                        rDoc.GetPageStyle( nScTab ), SFX_STYLE_FAMILY_PAGE );
    rR.pStyleSheet = pStSh;

    SfxItemSet*             pStyleSheetItemSet = pStSh? &pStSh->GetItemSet() : NULL;
    rR.pStyleSheetItemSet = pStyleSheetItemSet;

    ExcRecordList*          pHlinks = new ExcRecordList;
    XclExpTableOpManager    aTableOpList;
    XclExpTableOp*          pTableOpRec = NULL;

    ExcArrays               aArrayFormList;
    ExcArray*               pLastArray = NULL;

    ExcArrays               aShrdFmlaList;
    ExcShrdFmla*            pShrdFmla = NULL;

    DBG_ASSERT( (nScTab >= 0L) && (nScTab <= MAXTAB), "-ExcTable::Table(): nScTab - no ordinary table!" );
    DBG_ASSERT( (nExcTab >= 0L) && (nExcTab <= MAXTAB), "-ExcTable::Table(): nExcTab - no ordinary table!" );

    rDoc.GetTableArea( nScTab, nLastCol, nLastRow );

    if( nLastRow > rR.nRowMax )     // max. Zeilenzahl ueberschritten?
    {
        nLastRow = rR.nRowMax;
        rR.bCellCut = TRUE;
    }

    // find outline range
    ScOutlineTable*         pOLTable    = rDoc.GetOutlineTable( nScTab );
    ScOutlineArray*         pOLColArray = NULL;
    ScOutlineArray*         pOLRowArray = NULL;
    if( pOLTable )
    {
        UINT16              nStart, nEnd;
        UINT16              nMaxOLCol = 0;
        UINT16              nMaxOLRow = 0;

        pOLColArray = pOLTable->GetColArray();
        if( pOLColArray )
        {
            pOLColArray->GetRange( nStart, nEnd );
            nMaxOLCol = nEnd + 1;
        }
        nMaxFlagCol = Max( nMaxFlagCol, nMaxOLCol );

        pOLRowArray = pOLTable->GetRowArray();
        if( pOLRowArray )
        {
            pOLRowArray->GetRange( nStart, nEnd );
            nMaxOLRow = nEnd + 1;
        }
        nMaxFlagRow = Max( nMaxFlagRow, nMaxOLRow );
    }
    nMaxFlagCol = Min( nMaxFlagCol, (UINT16) MAXCOL );
    nMaxFlagRow = Min( Min( nMaxFlagRow, (UINT16) MAXROW ), rR.nRowMax );

    ExcEOutline aExcOLCol( pOLColArray );
    ExcEOutline aExcOLRow( pOLRowArray );

    DBG_ASSERT( !rR.pCellMerging, "ExcTable::FillAsTable - old merging list found" );
    rR.pCellMerging = new XclExpCellMerging;


    ScUsedAreaIterator      aIterator( &rDoc, nScTab, 0, 0, nLastCol, nLastRow );
//  ScUsedAreaIterator      aIterator( &rDoc, nScTab, 0, 0, MAXCOL, MAXROW );
    const ScBaseCell*       pAktScCell;
    const ScPatternAttr*    pPatt;
    ExcBlankMulblank*       pLastBlank = NULL;
    ExcRKMulRK*             pLastRKMulRK = NULL;
    BOOL                    bIter;

    // jetz schon, um erste Zeile zu bekommen
    bIter = aIterator.GetNext();
    if( bIter )
    {
        nCol = aIterator.GetStartCol();
        nRow = aIterator.GetRow();

        if( nRow > rR.nRowMax )     // max. Zeilenzahl ueberschritten?
        {
            rR.bCellCut = TRUE;
            NullTab();
            return;
        }
        pAktScCell = aIterator.GetCell();
        pPatt = aIterator.GetPattern();
    }

    // Header und Default-Recs
    if( eDateiTyp < Biff8 )
    {
        Add( new ExcBof );
        // CALCMODE bis VCENTER
        Add( new ExcDummy_02 );
    }
    else
    {
        Add( new ExcBof8 );
        // CALCMODE bis VCENTER
        Add( new ExcDummy8_02 );
    }

    // GUTS (count & size of outline icons)
    Add( new ExcEGuts( pOLColArray, pOLRowArray ) );

    // HORIZONTALPAGEBREAKS & VERTICALPAGEBREAKS
    if( eDateiTyp < Biff8 )
    {
        Add( new XclExpPageBreaks( rR, nScTab, XclExpPageBreaks::pbHorizontal ) );
        Add( new XclExpPageBreaks( rR, nScTab, XclExpPageBreaks::pbVertical ) );
    }
    else
    {
        Add( new XclExpPageBreaks8( rR, nScTab, XclExpPageBreaks::pbHorizontal ) );
        Add( new XclExpPageBreaks8( rR, nScTab, XclExpPageBreaks::pbVertical ) );
    }

    const SvxLRSpaceItem&   rLRSpaceItem = ( const SvxLRSpaceItem& ) pStyleSheetItemSet->Get( ATTR_LRSPACE );
    Add( new ExcMargin( rLRSpaceItem.GetLeft(), IMPEXC_MARGINSIDE_LEFT ) );
    Add( new ExcMargin( rLRSpaceItem.GetRight(), IMPEXC_MARGINSIDE_RIGHT ) );

    const SvxULSpaceItem&   rULSpaceItem = ( const SvxULSpaceItem& ) pStyleSheetItemSet->Get( ATTR_ULSPACE );
    Add( new ExcMargin( rULSpaceItem.GetUpper(), IMPEXC_MARGINSIDE_TOP ) );
    Add( new ExcMargin( rULSpaceItem.GetLower(), IMPEXC_MARGINSIDE_BOTTOM ) );

    Add( new ExcPrintheaders( pStyleSheetItemSet ) );
    Add( new ExcPrintGridlines( pStyleSheetItemSet ) );
    Add( new ExcHcenter( pStyleSheetItemSet ) );
    Add( new ExcVcenter( pStyleSheetItemSet ) );

    Add( new ExcHeader( &rR, eDateiTyp >= Biff8 ) );
    Add( new ExcFooter( &rR, eDateiTyp >= Biff8 ) );
    Add( new ExcSetup( &rR ) );

    if( eDateiTyp >= Biff8 )
    {
        Add( new XclBGPic( rR ) );

        if( rDoc.IsTabProtected( nScTab ) )
            Add( new XclProtection() );
    }

    if ( eDateiTyp < Biff8 && rR.pExtSheetCntAndRecs )
        Add( new ExcExternDup( *rR.pExtSheetCntAndRecs ) );

    // Defcolwidth (Breite aus Excel-Dokument)
    ExcDefcolwidth*             pExcDefColWidth = new ExcDefcolwidth( 0x000a );
    Add( pExcDefColWidth );

    // COLINFO records
    ExcColinfo* pLastColInfo = new ExcColinfo( 0, nScTab, nDefXF, rR, aExcOLCol );
    ExcColinfo* pNewColInfo;

    Add( pLastColInfo );
    for( UINT16 iCol = 1; iCol <= MAXCOL; iCol++ )
    {
        pNewColInfo = new ExcColinfo( iCol, nScTab, nDefXF, rR, aExcOLCol );
        pLastColInfo->Expand( pNewColInfo );
        if( pNewColInfo )
        {
            pLastColInfo = pNewColInfo;
            Add( pLastColInfo );
        }
    }

    // Dimensions
    ExcDimensions*          pDimensions = new ExcDimensions( rR.eDateiTyp );
    Add( pDimensions );

    if ( rR.eDateiTyp >= Biff8 )
    {
        // Scenarios
        Add( new ExcEScenarioManager( rDoc, nScTab ) );
        // list holding OBJ records and creating MSODRAWING per-sheet data
        rR.pObjRecs = new XclObjList( rR );
        // AutoFilter
        Add( new ExcAutoFilterRecs( rR, nScTab ) );
        // list of NOTE records
        rR.pNoteRecs = new XclNoteList;
    }

    // NOTE
    const ScPostIt*         pNote = NULL;

    // rows & cols
    nFirstRow = nRow;
    nColMin = nFirstCol = nCol;
    pRowBlock = new ExcRowBlock;
    Add( pRowBlock );

    // at least one ROW rec
    if( !bIter )
        AddRow( new ExcRow( 0, nScTab, 0, 0, nDefXF, rDoc, aExcOLRow, *this ) );

    while( bIter )
    {
        nCol = aIterator.GetStartCol();     // nur bei erstem Durchlauf doppelt!
        pAktScCell = aIterator.GetCell();
        pPatt = aIterator.GetPattern();

        pAktExcCell = NULL;
        pTableOpRec = NULL;

        // add ROW recs from empty rows
        while( nPrevRow < nRow )
        {
            ExcRow* pRow = new ExcRow( nPrevRow, nScTab, 0, 0, nDefXF, rDoc, aExcOLRow, *this );
            AddUsedRow( pRow );
            nPrevRow++;
        }

        ScAddress   aScPos( nCol, nRow, nScTab );
        rR.sAddNoteText.Erase();

        if( pAktScCell )
        {// nicht-leere Zelle
            pLastBlank = NULL;
            pNote = pAktScCell->GetNotePtr();

            switch( pAktScCell->GetCellType() )
            {
                case CELLTYPE_NONE:
                    pLastRKMulRK = NULL;
                    break;
                case CELLTYPE_VALUE:
                {
                    double  fVal = ( ( ScValueCell * ) pAktScCell )->GetValue();
                    INT32   nRKValue;
                    if ( pPatt && (fVal == 0.0 || fVal == 1.0) &&
                            rFormatter.GetType(
                            ((const SfxUInt32Item&)pPatt->GetItem(
                            ATTR_VALUE_FORMAT )).GetValue() ) == NUMBERFORMAT_LOGICAL )
                    {
                        pLastRKMulRK = NULL;
                        pAktExcCell = new ExcBoolerr( aScPos, pPatt, rR, UINT8(fVal), FALSE );
                    }
                    else if( XclExpHelper::GetRKFromDouble( fVal, nRKValue ) )
                    {
                        if( pLastRKMulRK )
                        {
                            ExcRKMulRK* pNewRK = pLastRKMulRK->Extend( aScPos, pPatt, rR, nRKValue );
                            if( pNewRK )
                                pLastRKMulRK = pNewRK;

                            pAktExcCell = pNewRK;
                        }
                        else
                            pAktExcCell = pLastRKMulRK = new ExcRKMulRK( aScPos, pPatt, rR, nRKValue );
                    }
                    else
                    {
                        pAktExcCell = new ExcNumber( aScPos, pPatt, rR, fVal );
                        pLastRKMulRK = NULL;
                    }
                }
                break;
                case CELLTYPE_STRING:
                {
                    pLastRKMulRK = NULL;
                    String  aTemp;

                    ( ( ScStringCell* ) pAktScCell )->GetString( aTemp );

                    if ( rR.eDateiTyp < Biff8 )
                        pAktExcCell = new ExcLabel( aScPos, pPatt, rR, aTemp );
                    else
                        pAktExcCell = new ExcLabelSst( aScPos, pPatt, rR, aTemp );
                }
                break;
                case CELLTYPE_FORMULA:
                {
                    pLastRKMulRK = NULL;
                    ScFormulaCell*      pFormCell = ( ScFormulaCell * ) pAktScCell;
                    ULONG   nCellNumForm = ( pPatt ?
                        (( const SfxUInt32Item& ) pPatt->GetItem(
                        ATTR_VALUE_FORMAT )).GetValue() : 0 );
                    ULONG   nAltNumForm;
                    BOOL    bForceAltNumForm;
                    if( ( nCellNumForm % SV_COUNTRY_LANGUAGE_OFFSET ) == 0 )
                    {
                        // #73420# Xcl doesn't know boolean number formats,
                        // we write "TRUE";"TRUE";"FALSE" or "WAHR";"WAHR";"FALSCH"
                        // or any other language dependent key words instead.
                        // Don't do it for automatic formula formats,
                        // because Xcl gets them right.
                        if( pFormCell->GetFormatType() == NUMBERFORMAT_LOGICAL )
                            nAltNumForm = NUMBERFORMAT_ENTRY_NOT_FOUND;
                        else
                            nAltNumForm = pFormCell->GetStandardFormat(
                                rFormatter, nCellNumForm );
                        bForceAltNumForm = FALSE;
                    }
                    else
                    {
                        // #73420# If number format set is boolean and
                        // automatic format is boolean don't write that ugly
                        // special format.
                        if( pFormCell->GetFormatType() == NUMBERFORMAT_LOGICAL
                                && rFormatter.GetType( nCellNumForm ) == NUMBERFORMAT_LOGICAL )
                        {
                            nAltNumForm = 0;
                            bForceAltNumForm = TRUE;
                        }
                        else
                        {
                            nAltNumForm = NUMBERFORMAT_ENTRY_NOT_FOUND;
                            bForceAltNumForm = FALSE;
                        }

                    }
                    ExcFormula* pFmlaCell = new ExcFormula(
                        aScPos, pPatt, rR, nAltNumForm, bForceAltNumForm, *pFormCell->GetCode(),
                        &pLastArray, ( ScMatrixMode ) pFormCell->GetMatrixFlag(), &pShrdFmla, &aShrdFmlaList );
                    pAktExcCell = pFmlaCell;
                    pTableOpRec = aTableOpList.InsertCell( pFormCell->GetCode(), *pFmlaCell );
                }
                break;
                case CELLTYPE_EDIT:
                {
                    pLastRKMulRK = NULL;
                    if( rR.eDateiTyp < Biff8 )
                        pAktExcCell = new ExcRString( aScPos, pPatt, rR, *((ScEditCell*) pAktScCell) );
                    else
                        pAktExcCell = new ExcLabelSst( aScPos, pPatt, rR, *((ScEditCell*) pAktScCell) );

                    XclHlink*&      rpHlink = rR.pLastHlink;
                    if( rpHlink )
                    {
                        rpHlink->SetPosition( aScPos );
                        pHlinks->Append( rpHlink );
                        rpHlink = NULL;
                    }
                }
                break;
                case CELLTYPE_NOTE:
                {
                    pAktExcCell = NULL;
                    pLastRKMulRK = NULL;
                    DBG_ASSERT( pNote, "-ExcTable::Table(): Note-Cell ohne Note!" );
                }
                break;
#ifdef DBG_UTIL
                case CELLTYPE_DESTROYED:
                    pAktExcCell = NULL;
                    pLastRKMulRK = NULL;
                    break;
#endif
                default:
                    DBG_ERROR( "*ExcTable::Table(): Unbekannter Zelltyp" );
                    pAktExcCell = NULL;
                    pLastRKMulRK = NULL;
            }
        }
        else
        {// leere Zelle mit Attributierung
            pNote = NULL;

            UINT16  nColCnt = aIterator.GetEndCol() - aIterator.GetStartCol() + 1;

            if( pLastBlank && pLastBlank->GetLastCol() + 1 == aIterator.GetStartCol() )
            {
                pLastBlank->Add( aScPos, pPatt, rR, nColCnt, *this );

                pAktScCell = NULL;  // kein NEUER Record!
            }
            else
            {
                pLastBlank = new ExcBlankMulblank( aScPos, pPatt, rR, nColCnt, *this );
                pAktExcCell = pLastBlank;
            }
        }

        if( pAktExcCell )
        {
            Add( pAktExcCell );

            if( pLastArray )
            {
                if( aArrayFormList.Insert( pLastArray ) )
                    Add( pLastArray );  // really new
                else
                    delete pLastArray;  // allready added

                pLastArray = NULL;
            }

            if( pShrdFmla )
            {
                aShrdFmlaList.Append( pShrdFmla );
                Add( pShrdFmla );
                pShrdFmla = NULL;
            }
        }

        if( pTableOpRec )
            Add( pTableOpRec );

        // notes
        String sNoteText;
        String sNoteAuthor;
        if( pNote )
        {
            sNoteText = pNote->GetText();
            sNoteAuthor = pNote->GetAuthor();
        }
        if( rR.sAddNoteText.Len() )
        {
            if( sNoteText.Len() )
                (sNoteText += (sal_Unicode) 0x0A) += (sal_Unicode) 0x0A;
            sNoteText += rR.sAddNoteText;
        }
        if( sNoteText.Len() || sNoteAuthor.Len() )
        {
            if ( rR.eDateiTyp < Biff8 )
                Add( new ExcNote( aScPos, sNoteText, rR ) );
            else
                rR.pNoteRecs->Add( new XclNote( rR, aScPos, sNoteText, sNoteAuthor ) );
        }

        // merged cells
        if( pPatt )
        {
            ScMergeAttr& rItem = (ScMergeAttr&) pPatt->GetItem( ATTR_MERGE );
            if( rItem.IsMerged() )
            {
                UINT16 nXF = (pAktExcCell ? pAktExcCell->GetXF() :
                            (pLastBlank ? pLastBlank->GetXF() :
                            (pLastRKMulRK ? pLastRKMulRK->GetXF() : 0)));
                for( UINT16 iCol = aIterator.GetStartCol(); iCol <= aIterator.GetEndCol(); iCol++ )
                    rR.pCellMerging->Append( iCol, rItem.GetColMerge(), nRow, rItem.GetRowMerge(), nXF );
            }
        }

        bIter = aIterator.GetNext();

        // new row number
        if( bIter )
        {
            nRow = aIterator.GetRow();
            if( nRow > rR.nRowMax )     // Excel row limit
                bIter = FALSE;
        }

        // new row -> add previous ROW rec
        if( !bIter || (nPrevRow < nRow) )
        {
            AddRow( new ExcRow( nPrevRow, nScTab, nColMin, nCol, nDefXF, rDoc, aExcOLRow, *this ) );

            nPrevRow++;
            nColMin = aIterator.GetStartCol();
            nFirstCol = Min( nFirstCol, nColMin );

        }
    }

    // remaining rows with attributes
    while( nRow < nMaxFlagRow )
    {
        nRow++;
        ExcRow* pRow = new ExcRow( nRow, nScTab, 0, 0, nDefXF, rDoc, aExcOLRow, *this );
        AddUsedRow( pRow );
    }

    // insert merged cells
    Add( rR.pCellMerging );
    rR.pCellMerging = NULL;
    // update dimensions
    pDimensions->SetLimits( nFirstCol, nFirstRow, nLastCol, nLastRow );
    // update formula cells for multiple operations
    aTableOpList.UpdateCells();

    if( rR.eDateiTyp < Biff8 )
    {
        Add( new ExcWindow2( nExcTab ) );
        Add( new ExcSelection( 3, 0, 0 ) );
    }
    else
    {
        ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
        if( pDrawLayer )
        {
            SdrPage* pPage = pDrawLayer->GetPage( nScTab );
            if( pPage )
                rR.pEscher->GetEx()->AddSdrPage( *pPage );
        }
        //! close Escher group shape and ESCHER_DgContainer
        //! opened by XclObjList ctor MSODRAWING
        rR.pObjRecs->EndSheet();
        // all MSODRAWING and OBJ stuff of this sheet goes here
        Add( rR.pObjRecs );
        // NOTE records
        Add( rR.pNoteRecs );

        // pivot tables
        ScDPCollection*     pDPColl = rDoc.GetDPCollection();
        XclPivotCacheList*  pPCList = rR.pPivotCacheList;
        if( pDPColl && pPCList )
        {
            for( USHORT nObjCnt = 0; nObjCnt < pDPColl->GetCount(); nObjCnt++ )
            {
                ScDPObject*             pDPObject   = (*pDPColl)[ nObjCnt ];
                const XclPivotCache*    pCache      = pPCList->Get( nObjCnt );

                if( pDPObject && pCache )
                {
                    const ScRange& rRange = pDPObject->GetOutRange();
                    if( rRange.aStart.Tab() == nScTab )
                        Add( new XclPivotTableRecs( *pCache, nObjCnt ) );
                }
            }
        }

        // WINDOW2
        Add( new ExcWindow28( rR, nScTab ) );
    }

    if( rR.eDateiTyp >= Biff8 )
    {
        // web queries
        AddWebQueries();

        // conditional formats
        const ScConditionalFormatList*  pCondFormList = rDoc.GetCondFormList();
        if( pCondFormList )
        {
            UINT32                      nCondCnt = pCondFormList->Count();
            ScConditionalFormat* const* ppCondForm = pCondFormList->GetData();
            ScRangeList*                pRangeList = NULL;

            while( nCondCnt )
            {
                if( *ppCondForm )
                {
                    const ScConditionalFormat&  rCF = **ppCondForm;

                    if( pRangeList )
                        pRangeList->Clear();
                    else
                        pRangeList = new ScRangeList;

                    rDoc.FindConditionalFormat( rCF.GetKey(), *pRangeList );

                    if( pRangeList->Count() )
                    {
                        Add( new XclCondFormat( rCF, pRangeList, rR ) );
                        pRangeList = NULL;
                    }
                }

                ppCondForm++;
                nCondCnt--;
            }

            if( pRangeList )
                delete pRangeList;
        }

        if( rR.bWriteVBAStorage )
        {
            CodenameList*       pL = rR.pExtDocOpt->GetCodenames();
            if( pL )
            {
                const String* p = nExcTab ? pL->Next() : pL->First();
                if( p )
                    Add( new XclCodename( *p ) );
            }
        }
    }

    rR.pStyleSheet = NULL;
    rR.pStyleSheetItemSet = NULL;

    Add( pHlinks );

    // change tracking
    if( rR.pUserBViewList )
    {
        for( const XclExpUserBView* pBView = rR.pUserBViewList->First(); pBView; pBView = rR.pUserBViewList->Next() )
        {
            Add( new XclExpUsersViewBegin( pBView->GetGUID(), nExcTab ) );
            Add( new XclExpUsersViewEnd );
        }
    }

    // EOF
    Add( new ExcEof );
}


void ExcTable::NullTab( const String* pCodename )
{
    DBG_ASSERT( (nScTab >= 0L) && (nScTab <= MAXTAB), "-ExcTable::Table(): nScTab - no ordinary table!" );
    DBG_ASSERT( (nExcTab >= 0L) && (nExcTab <= MAXTAB), "-ExcTable::Table(): nExcTab - no ordinary table!" );

    RootData&       rR = *pExcRoot;

    if ( rR.eDateiTyp < Biff8 )
    {
        Add( new ExcBof );
        Add( new ExcWindow2( nExcTab ) );
    }
    else
    {
        Add( new ExcBof8 );

        if( pCodename )
            Add( new XclCodename( *pCodename ) );
        else
        {
            // create at least the MSODRAWING per-sheet data
            rR.pObjRecs = new XclObjList( rR );
            // all drawing obects
            ScDrawLayer*    pDrawLayer = pExcRoot->pDoc->GetDrawLayer();
            if ( pDrawLayer )
            {
                SdrPage*    pPage = pDrawLayer->GetPage( nScTab );
                if ( pPage )
                    rR.pEscher->GetEx()->AddSdrPage( *pPage );
            }
            //! close Escher group shape and ESCHER_DgContainer
            //! opened by XclObjList ctor MSODRAWING
            rR.pObjRecs->EndSheet();
            Add( rR.pObjRecs );
        }
        // WINDOW2

        Add( new ExcWindow28( rR, nScTab ) );
    }
    Add( new ExcEof );
}


void ExcTable::ModifyToDefaultRowXF( UINT16 nRowNum, UINT16& rXF )
{
    if( pDefRowXFs )
        pDefRowXFs->ChangeXF( nRowNum, rXF );
}


void ExcTable::Write( XclExpStream& rStr )
{
    ExcRecord*          pAkt = aRecList.First();

    while( pAkt )
    {
        pAkt->Save( rStr );
        pAkt = aRecList.Next();
    }
}




void ExcDocument::Clear( void )
{
    ExcTable*           pDelTab = ( ExcTable* ) List::First();
    while( pDelTab )
    {
        delete pDelTab;
        pDelTab = ( ExcTable * ) List::Next();
    }
    List::Clear();
}


ExcDocument::ExcDocument( RootData* pRD ) :
    ExcRoot( pRD ),
    aHeader( pRD ),
    pExpChangeTrack( NULL )
{
    pTabNames = new NameBuffer( 0, 16 );

    pPrgrsBar = new ScProgress(
        NULL, ScGlobal::GetRscString(STR_SAVE_DOC),
        ( UINT32 ) pExcRoot->pDoc->GetCellCount() * 2 );
    ExcCell::SetPrgrsBar( *pPrgrsBar );
}


ExcDocument::~ExcDocument()
{
    Clear();

    DBG_ASSERT( ExcCell::_nRefCount == 0, "*ExcDocument::~ExcDocument(): Ein'n hab'n wir noch!" );

    delete pTabNames;
#ifdef DBG_UTIL
    pTabNames = NULL;
#endif

    delete pPrgrsBar;
    ExcCell::ClearPrgrsBar();

    if( pExpChangeTrack )
        delete pExpChangeTrack;
}


void ExcDocument::ReadDoc( void )
{
    pExcRoot->nCodenames = pExcRoot->pTabBuffer->GetCodenameCount();

    aHeader.FillAsHeader( aBundleSheetRecList );

    UINT16          nTabs = pExcRoot->pTabBuffer->GetMaxScTabCount();
    UINT16          nTabCnt;
    pExcRoot->pAktTab = &nTabCnt;

    for( nTabCnt = 0 ; nTabCnt < nTabs ; nTabCnt++ )
        Add( nTabCnt );

    pExcRoot->pAktTab = NULL;

    if ( pExcRoot->eDateiTyp >= Biff8 )
    {
        // complete temporary Escher stream
        pExcRoot->pEscher->GetEx()->EndDocument();

        // change tracking
        if ( pExcRoot->pDoc->GetChangeTrack() )
            pExpChangeTrack = new XclExpChangeTrack( pExcRoot );
    }
}


void ExcDocument::Add( UINT16 nScTab )
{
    if( pExcRoot->pTabBuffer->IsExportTable( nScTab ) )
    {
        ExcTable* pTab = new ExcTable( pExcRoot, nScTab );
        List::Insert( pTab, LIST_APPEND );
        pTab->FillAsTable();
    }
}


void ExcDocument::Write( SvStream& rSvStrm )
{
    if( List::Count() > 0 )
    {
        ULONG nMaxRecordLen;
        if ( pExcRoot->eDateiTyp >= Biff8 )
        {
            pExcRoot->pEscher->GetStrm().Seek(0);   // ready for take off
            nMaxRecordLen = EXC_MAXRECLEN_BIFF8;
        }
        else
            nMaxRecordLen = EXC_MAXRECLEN_BIFF5;

        pExcRoot->pPalette2->ReduceColors();

        XclExpStream        aXclStrm( rSvStrm, nMaxRecordLen );
        ExcTable*           pAktTab = ( ExcTable* ) List::First();
        ExcBundlesheetBase* pAktBS = ( ExcBundlesheetBase* ) aBundleSheetRecList.First();

        aHeader.Write( aXclStrm );

        while( pAktTab )
        {
            DBG_ASSERT( pAktBS, "-ExcDocument::Write(): BundleSheetRecs und Tabs passen nicht zusammen!" );
            pAktBS->SetStreamPos( aXclStrm.GetStreamPos() );
            pAktTab->Write( aXclStrm );
            pAktTab = ( ExcTable* ) List::Next();
            pAktBS = ( ExcBundlesheetBase* ) aBundleSheetRecList.Next();
        }

        DBG_ASSERT( !pAktBS, "+ExcDocument::Write(): mehr BundleSheetRecs als Tabs!" );

        // BundleSheetRecs anpassen
        pAktBS = ( ExcBundlesheetBase* ) aBundleSheetRecList.First();
        while( pAktBS )
        {
            pAktBS->UpdateStreamPos( aXclStrm );
            pAktBS = ( ExcBundlesheetBase* ) aBundleSheetRecList.Next();
        }

    }
    if( pExcRoot->pPivotCacheList )
        pExcRoot->pPivotCacheList->Write();
    if( pExpChangeTrack )
        pExpChangeTrack->Write();
}