update dev300-m58
[ooovba.git] / sc / source / filter / excel / excdoc.cxx
blob07dfe83c336101c14656a651f9f0c9a169a2052d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: excdoc.cxx,v $
10 * $Revision: 1.69.60.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
35 //------------------------------------------------------------------------
37 #include "scitems.hxx"
39 #include <comphelper/processfactory.hxx>
40 #include <svx/svdobj.hxx>
41 #include <svx/svditer.hxx>
42 #include <svx/svdpage.hxx>
43 #include <svx/lrspitem.hxx>
44 #include <svx/ulspitem.hxx>
45 #include <svtools/intitem.hxx>
46 #include <svtools/zformat.hxx>
47 #include <sot/storage.hxx>
48 #include <sfx2/objsh.hxx>
49 #include <tools/urlobj.hxx>
50 #include <rtl/ustring.hxx>
52 #include "cell.hxx"
53 #include "dociter.hxx"
54 #include "document.hxx"
55 #include "rangenam.hxx"
56 #include "dbcolect.hxx"
57 #include "global.hxx"
58 #include "globstr.hrc"
59 #include "progress.hxx"
60 #include "conditio.hxx"
61 #include "dpobject.hxx"
62 #include "attrib.hxx"
63 #include "scextopt.hxx"
64 #include "stlsheet.hxx"
65 #include "stlpool.hxx"
66 #include "olinetab.hxx"
67 #include "unonames.hxx"
68 #include "convuno.hxx"
69 #include "patattr.hxx"
70 #include "docoptio.hxx"
71 #include "tabprotection.hxx"
73 #include "excdoc.hxx"
74 #include "namebuff.hxx"
76 #include "xcl97rec.hxx"
77 #include "xcl97esc.hxx"
78 #include "xetable.hxx"
79 #include "xelink.hxx"
80 #include "xename.hxx"
81 #include "xepage.hxx"
82 #include "xeview.hxx"
83 #include "xecontent.hxx"
84 #include "xeescher.hxx"
85 #include "xepivot.hxx"
86 #include "XclExpChangeTrack.hxx"
88 #include <math.h>
90 #include <oox/core/tokens.hxx>
92 using ::rtl::OString;
94 static String lcl_GetVbaTabName( SCTAB n )
96 String aRet( RTL_CONSTASCII_USTRINGPARAM( "__VBA__" ) );
97 aRet += String::CreateFromInt32( static_cast<sal_uInt16>(n) );
98 return aRet;
102 static void lcl_AddBookviews( XclExpRecordList<>& aRecList, ExcTable& self )
104 aRecList.AppendNewRecord( new XclExpXmlStartElementRecord( XML_bookViews ) );
105 aRecList.AppendNewRecord( new XclExpWindow1( self.GetRoot() ) );
106 aRecList.AppendNewRecord( new XclExpXmlEndElementRecord( XML_bookViews ) );
109 static void lcl_AddCalcPr( XclExpRecordList<>& aRecList, ExcTable& self )
111 ScDocument& rDoc = self.GetDoc();
113 aRecList.AppendNewRecord( new XclExpXmlStartSingleElementRecord( XML_calcPr ) );
114 // OOXTODO: calcCompleted, calcId, calcMode, calcOnSave,
115 // concurrentCalc, concurrentManualCount,
116 // forceFullCalc, fullCalcOnLoad, fullPrecision
117 aRecList.AppendNewRecord( new XclCalccount( rDoc ) );
118 aRecList.AppendNewRecord( new XclRefmode( rDoc ) );
119 aRecList.AppendNewRecord( new XclIteration( rDoc ) );
120 aRecList.AppendNewRecord( new XclDelta( rDoc ) );
121 aRecList.AppendNewRecord( new XclExpBoolRecord(0x005F, true) ); // SAVERECALC
122 aRecList.AppendNewRecord( new XclExpXmlEndSingleElementRecord() ); // XML_calcPr
125 #if 0
126 // removed during rebase, because scsheetprotection02 is not yet up-stream :-(
127 static void lcl_AddWorkbookProtection( XclExpRecordList<>& aRecList, ExcTable& self )
129 aRecList.AppendNewRecord( new XclExpXmlStartSingleElementRecord( XML_workbookProtection ) );
130 const ScDocProtection* pProtect = self.GetDoc().GetDocProtection();
131 if (pProtect && pProtect->isProtected())
133 aRecList.AppendNewRecord( new XclExpWindowProtection(pProtect->isOptionEnabled(ScDocProtection::WINDOWS)) );
134 aRecList.AppendNewRecord( new XclExpProtection(pProtect->isOptionEnabled(ScDocProtection::STRUCTURE)) );
135 aRecList.AppendNewRecord( new XclExpPassHash(pProtect->getPasswordHash(PASSHASH_XL)) );
138 if( self.GetBiff() == EXC_BIFF8 )
140 aRecList.AppendNewRecord( new XclExpProt4Rev );
141 aRecList.AppendNewRecord( new XclExpProt4RevPass );
143 aRecList.AppendNewRecord( new XclExpXmlEndSingleElementRecord() ); // XML_workbookProtection
145 #endif
147 static void lcl_AddScenariosAndFilters( XclExpRecordList<>& aRecList, ExcTable& self, SCTAB mnScTab )
149 // Scenarios
150 aRecList.AppendNewRecord( new ExcEScenarioManager( self.GetDoc(), mnScTab ) );
151 // filter
152 aRecList.AppendRecord( self.GetFilterManager().CreateRecord( mnScTab ) );
156 ExcTable::ExcTable( const XclExpRoot& rRoot ) :
157 XclExpRoot( rRoot ),
158 mnScTab( SCTAB_GLOBAL ),
159 nExcTab( EXC_NOTAB ),
160 pTabNames( new NameBuffer( 0, 16 ) )
165 ExcTable::ExcTable( const XclExpRoot& rRoot, SCTAB nScTab ) :
166 XclExpRoot( rRoot ),
167 mnScTab( nScTab ),
168 nExcTab( rRoot.GetTabInfo().GetXclTab( nScTab ) ),
169 pTabNames( new NameBuffer( 0, 16 ) )
174 ExcTable::~ExcTable()
176 delete pTabNames;
180 void ExcTable::Add( XclExpRecordBase* pRec )
182 DBG_ASSERT( pRec, "-ExcTable::Add(): pRec ist NULL!" );
183 aRecList.AppendNewRecord( pRec );
187 void ExcTable::FillAsHeader( ExcBoundsheetList& rBoundsheetList )
189 InitializeGlobals();
191 RootData& rR = GetOldRoot();
192 ScDocument& rDoc = GetDoc();
193 XclExpTabInfo& rTabInfo = GetTabInfo();
195 if ( GetBiff() <= EXC_BIFF5 )
196 Add( new ExcBofW );
197 else
198 Add( new ExcBofW8 );
200 SCTAB nC;
201 String aTmpString;
202 SCTAB nScTabCount = rTabInfo.GetScTabCount();
203 UINT16 nExcTabCount = rTabInfo.GetXclTabCount();
204 UINT16 nCodenames = static_cast< UINT16 >( GetExtDocOptions().GetCodeNameCount() );
206 rR.pObjRecs = NULL; // per sheet
208 if( GetBiff() <= EXC_BIFF5 )
209 Add( new ExcDummy_00 );
210 else
212 if ( IsDocumentEncrypted() )
213 Add( new XclExpFilePass(GetRoot()) );
215 Add( new XclExpInterfaceHdr );
216 Add( new XclExpMMS );
217 Add( new XclExpInterfaceEnd );
218 Add( new XclExpWriteAccess );
219 Add( new XclExpCodePage );
220 Add( new XclExpDSF );
221 Add( new XclExpExcel9File );
222 rR.pTabId = new XclExpChTrTabId( Max( nExcTabCount, nCodenames ) );
223 Add( rR.pTabId );
224 if( HasVbaStorage() )
226 Add( new XclObproj );
227 const String& rCodeName = GetExtDocOptions().GetDocSettings().maGlobCodeName;
228 if( rCodeName.Len() )
229 Add( new XclCodename( rCodeName ) );
232 Add( new XclExpFnGroupCount );
235 // erst Namen- und Tabellen-Eintraege aufbauen
236 String aName;
238 for( nC = 0 ; nC < nScTabCount ; nC++ )
239 if( rTabInfo.IsExportTab( nC ) )
241 rDoc.GetName( nC, aTmpString );
242 *pTabNames << aTmpString;
245 if ( GetBiff() <= EXC_BIFF5 )
247 // global link table: EXTERNCOUNT, EXTERNSHEET, NAME
248 aRecList.AppendRecord( CreateRecord( EXC_ID_EXTERNSHEET ) );
249 aRecList.AppendRecord( CreateRecord( EXC_ID_NAME ) );
252 // document protection options
253 const ScDocProtection* pProtect = GetDoc().GetDocProtection();
254 if (pProtect && pProtect->isProtected())
256 Add( new XclExpWindowProtection(pProtect->isOptionEnabled(ScDocProtection::WINDOWS)) );
257 Add( new XclExpProtection(pProtect->isOptionEnabled(ScDocProtection::STRUCTURE)) );
258 #if ENABLE_SHEET_PROTECTION
259 Add( new XclExpPassHash(pProtect->getPasswordHash(PASSHASH_XL)) );
260 #endif
263 if( GetBiff() == EXC_BIFF8 )
265 Add( new XclExpProt4Rev );
266 Add( new XclExpProt4RevPass );
269 // document protection options
270 if( GetOutput() == EXC_OUTPUT_BINARY )
272 //lcl_AddWorkbookProtection( aRecList, *this );
273 lcl_AddBookviews( aRecList, *this );
276 Add( new XclExpXmlStartSingleElementRecord( XML_workbookPr ) );
278 if ( GetBiff() == EXC_BIFF8 )
280 Add( new XclExpBoolRecord(0x0040, false) ); // BACKUP
281 Add( new XclExpBoolRecord(0x008D, false) ); // HIDEOBJ
284 if( GetBiff() <= EXC_BIFF5 )
286 Add( new ExcDummy_040 );
287 Add( new Exc1904( rDoc ) );
288 Add( new ExcDummy_041 );
290 else
292 // BIFF8
293 Add( new Exc1904( rDoc ) );
294 Add( new XclExpBoolRecord( 0x000E, !rDoc.GetDocOptions().IsCalcAsShown() ) );
295 Add( new XclExpBoolRecord(0x01B7, false) ); // REFRESHALL
296 Add( new XclExpBoolRecord(0x00DA, false) ); // BOOKBOOL
297 // OOXTODO: The following /workbook/workbookPr attributes are mapped
298 // to various BIFF records that are not currently supported:
300 // XML_allowRefreshQuery: QSISTAG 802h: fEnableRefresh
301 // XML_autoCompressPictures: COMPRESSPICTURES 89Bh: fAutoCompressPictures
302 // XML_checkCompatibility: COMPAT12 88Ch: fNoCompatChk
303 // XML_codeName: "Calc"
304 // XML_defaultThemeVersion: ???
305 // XML_filterPrivacy: BOOKEXT 863h: fFilterPrivacy
306 // XML_hidePivotFieldList: BOOKBOOL DAh: fHidePivotTableFList
307 // XML_promptedSolutions: BOOKEXT 863h: fBuggedUserAboutSolution
308 // XML_publishItems: NAMEPUBLISH 893h: fPublished
309 // XML_saveExternalLinkValues: BOOKBOOL DAh: fNoSavSupp
310 // XML_showBorderUnselectedTables: BOOKBOOL DAh: fHideBorderUnsels
311 // XML_showInkAnnotation: BOOKEXT 863h: fShowInkAnnotation
312 // XML_showPivotChart: PIVOTCHARTBITS 859h: fGXHide??
313 // XML_updateLinks: BOOKBOOL DAh: grbitUpdateLinks
315 Add( new XclExpXmlEndSingleElementRecord() ); // XML_workbookPr
317 // Formatting: FONT, FORMAT, XF, STYLE, PALETTE
318 if( GetOutput() != EXC_OUTPUT_BINARY )
320 aRecList.AppendNewRecord( new XclExpXmlStyleSheet( *this ) );
322 else
324 aRecList.AppendRecord( CreateRecord( EXC_ID_FONTLIST ) );
325 aRecList.AppendRecord( CreateRecord( EXC_ID_FORMATLIST ) );
326 aRecList.AppendRecord( CreateRecord( EXC_ID_XFLIST ) );
327 aRecList.AppendRecord( CreateRecord( EXC_ID_PALETTE ) );
331 if( GetBiff() <= EXC_BIFF5 )
333 // Bundlesheet
334 for( nC = 0 ; nC < nScTabCount ; nC++ )
335 if( rTabInfo.IsExportTab( nC ) )
337 ExcBoundsheetList::RecordRefType xBoundsheet( new ExcBundlesheet( rR, nC ) );
338 aRecList.AppendRecord( xBoundsheet );
339 rBoundsheetList.AppendRecord( xBoundsheet );
342 else
344 // Pivot Cache
345 GetPivotTableManager().CreatePivotTables();
346 aRecList.AppendRecord( GetPivotTableManager().CreatePivotCachesRecord() );
348 // Change tracking
349 if( rDoc.GetChangeTrack() )
351 rR.pUserBViewList = new XclExpUserBViewList( *rDoc.GetChangeTrack() );
352 Add( rR.pUserBViewList );
355 // Natural Language Formulas Flag
356 aRecList.AppendNewRecord( new XclExpBoolRecord( EXC_ID_USESELFS, GetDoc().GetDocOptions().IsLookUpColRowNames() ) );
358 if( GetOutput() != EXC_OUTPUT_BINARY )
360 //lcl_AddWorkbookProtection( aRecList, *this );
361 lcl_AddBookviews( aRecList, *this );
364 // Bundlesheet
365 aRecList.AppendNewRecord( new XclExpXmlStartElementRecord( XML_sheets ) );
366 for( nC = 0 ; nC < nScTabCount ; nC++ )
367 if( rTabInfo.IsExportTab( nC ) )
369 ExcBoundsheetList::RecordRefType xBoundsheet( new ExcBundlesheet8( rR, nC ) );
370 aRecList.AppendRecord( xBoundsheet );
371 rBoundsheetList.AppendRecord( xBoundsheet );
373 aRecList.AppendNewRecord( new XclExpXmlEndElementRecord( XML_sheets ) );
375 for( SCTAB nAdd = 0; nC < static_cast<SCTAB>(nCodenames) ; nC++, nAdd++ )
377 aTmpString = lcl_GetVbaTabName( nAdd );
378 ExcBoundsheetList::RecordRefType xBoundsheet( new ExcBundlesheet8( aTmpString ) );
379 aRecList.AppendRecord( xBoundsheet );
380 rBoundsheetList.AppendRecord( xBoundsheet );
383 // COUNTRY - in BIFF8 in workbook globals
384 Add( new XclExpCountry( GetRoot() ) );
385 // link table: SUPBOOK, XCT, CRN, EXTERNNAME, EXTERNSHEET, NAME
386 aRecList.AppendRecord( CreateRecord( EXC_ID_EXTERNSHEET ) );
387 aRecList.AppendRecord( CreateRecord( EXC_ID_NAME ) );
389 if( GetOutput() != EXC_OUTPUT_BINARY )
390 lcl_AddCalcPr( aRecList, *this );
392 Add( new XclExpRecalcId );
394 // MSODRAWINGGROUP per-document data
395 Add( new XclMsodrawinggroup( rR, ESCHER_DggContainer ) );
396 // Shared string table: SST, EXTSST
397 aRecList.AppendRecord( CreateRecord( EXC_ID_SST ) );
399 Add( new XclExpBookExt );
402 Add( new ExcEof );
406 void ExcTable::FillAsTable( size_t nCodeNameIdx )
408 InitializeTable( mnScTab );
410 RootData& rR = GetOldRoot();
411 XclBiff eBiff = GetBiff();
412 ScDocument& rDoc = GetDoc();
414 DBG_ASSERT( (mnScTab >= 0L) && (mnScTab <= MAXTAB), "-ExcTable::Table(): mnScTab - no ordinary table!" );
415 DBG_ASSERT( nExcTab <= static_cast<sal_uInt16>(MAXTAB), "-ExcTable::Table(): nExcTab - no ordinary table!" );
417 if ( eBiff == EXC_BIFF8 )
418 // list holding OBJ records and creating MSODRAWING per-sheet data
419 rR.pObjRecs = new XclObjList( GetRoot() );
421 // cell table: DEFROWHEIGHT, DEFCOLWIDTH, COLINFO, DIMENSIONS, ROW, cell records
422 mxCellTable.reset( new XclExpCellTable( GetRoot() ) );
424 if( GetOutput() != EXC_OUTPUT_BINARY )
426 FillAsXmlTable( nCodeNameIdx );
427 return;
431 // WSBOOL needs data from page settings, create it here, add it later
432 ScfRef< XclExpPageSettings > xPageSett( new XclExpPageSettings( GetRoot() ) );
433 bool bFitToPages = xPageSett->GetPageData().mbFitToPages;
435 if( eBiff <= EXC_BIFF5 )
437 Add( new ExcBof );
438 Add( new ExcDummy_02a );
440 else
442 Add( new ExcBof8 );
443 lcl_AddCalcPr( aRecList, *this );
446 // GUTS (count & size of outline icons)
447 aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_GUTS ) );
448 // DEFROWHEIGHT, created by the cell table
449 aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID2_DEFROWHEIGHT ) );
451 // COUNTRY - in BIFF5/7 in every worksheet
452 if( eBiff <= EXC_BIFF5 )
453 Add( new XclExpCountry( GetRoot() ) );
455 Add( new XclExpWsbool( bFitToPages ) );
457 // page settings (SETUP and various other records)
458 aRecList.AppendRecord( xPageSett );
460 const ScTableProtection* pTabProtect = rDoc.GetTabProtection(mnScTab);
461 if (pTabProtect && pTabProtect->isProtected())
463 Add( new XclExpProtection(true) );
464 Add( new XclExpBoolRecord(0x00DD, pTabProtect->isOptionEnabled(ScTableProtection::SCENARIOS)) );
465 Add( new XclExpBoolRecord(0x0063, pTabProtect->isOptionEnabled(ScTableProtection::OBJECTS)) );
466 #if ENABLE_SHEET_PROTECTION
467 Add( new XclExpPassHash(pTabProtect->getPasswordHash(PASSHASH_XL)) );
468 #endif
471 // local link table: EXTERNCOUNT, EXTERNSHEET
472 if( eBiff <= EXC_BIFF5 )
473 aRecList.AppendRecord( CreateRecord( EXC_ID_EXTERNSHEET ) );
475 if ( eBiff == EXC_BIFF8 )
476 lcl_AddScenariosAndFilters( aRecList, *this, mnScTab );
478 // cell table: DEFCOLWIDTH, COLINFO, DIMENSIONS, ROW, cell records
479 aRecList.AppendRecord( mxCellTable );
481 // MERGEDCELLS record, generated by the cell table
482 aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_MERGEDCELLS ) );
483 // label ranges
484 if( eBiff == EXC_BIFF8 )
485 Add( new XclExpLabelranges( GetRoot() ) );
486 // data validation (DVAL and list of DV records), generated by the cell table
487 aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_DVAL ) );
489 if( eBiff == EXC_BIFF8 )
491 rR.pEscher->AddSdrPage();
492 //! close Escher group shape and ESCHER_DgContainer
493 //! opened by XclObjList ctor MSODRAWING
494 rR.pObjRecs->EndSheet();
495 // all MSODRAWING and OBJ stuff of this sheet goes here
496 Add( rR.pObjRecs );
498 // pivot tables
499 aRecList.AppendRecord( GetPivotTableManager().CreatePivotTablesRecord( mnScTab ) );
502 // list of NOTE records, generated by the cell table
503 aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_NOTE ) );
505 // sheet view settings: WINDOW2, SCL, PANE, SELECTION
506 aRecList.AppendNewRecord( new XclExpTabViewSettings( GetRoot(), mnScTab ) );
508 if( eBiff == EXC_BIFF8 )
510 // sheet protection options
511 Add( new XclExpSheetProtectOptions( GetRoot(), mnScTab ) );
513 // web queries
514 Add( new XclExpWebQueryBuffer( GetRoot() ) );
516 // conditional formats
517 Add( new XclExpCondFormatBuffer( GetRoot() ) );
519 if( HasVbaStorage() )
520 if( nCodeNameIdx < GetExtDocOptions().GetCodeNameCount() )
521 Add( new XclCodename( GetExtDocOptions().GetCodeName( nCodeNameIdx ) ) );
524 // list of HLINK records, generated by the cell table
525 aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_HLINK ) );
527 // change tracking
528 if( rR.pUserBViewList )
530 for( const XclExpUserBView* pBView = rR.pUserBViewList->First(); pBView; pBView = rR.pUserBViewList->Next() )
532 Add( new XclExpUsersViewBegin( pBView->GetGUID(), nExcTab ) );
533 Add( new XclExpUsersViewEnd );
537 // EOF
538 Add( new ExcEof );
541 void ExcTable::FillAsXmlTable( size_t nCodeNameIdx )
543 RootData& rR = GetOldRoot();
545 // WSBOOL needs data from page settings, create it here, add it later
546 ScfRef< XclExpPageSettings > xPageSett( new XclExpPageSettings( GetRoot() ) );
547 bool bFitToPages = xPageSett->GetPageData().mbFitToPages;
549 Add( new ExcBof8 );
551 Add( new XclExpWsbool( bFitToPages, mnScTab, &GetFilterManager() ) );
553 // GUTS (count & size of outline icons)
554 aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_GUTS ) );
555 // DEFROWHEIGHT, created by the cell table
556 aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID2_DEFROWHEIGHT ) );
558 aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID3_DIMENSIONS ) );
560 // sheet view settings: WINDOW2, SCL, PANE, SELECTION
561 aRecList.AppendNewRecord( new XclExpTabViewSettings( GetRoot(), mnScTab ) );
563 // cell table: DEFCOLWIDTH, COLINFO, DIMENSIONS, ROW, cell records
564 aRecList.AppendRecord( mxCellTable );
566 // label ranges
567 Add( new XclExpLabelranges( GetRoot() ) );
569 rR.pEscher->AddSdrPage();
570 //! close Escher group shape and ESCHER_DgContainer
571 //! opened by XclObjList ctor MSODRAWING
572 rR.pObjRecs->EndSheet();
573 // all MSODRAWING and OBJ stuff of this sheet goes here
574 Add( rR.pObjRecs );
576 // pivot tables
577 aRecList.AppendRecord( GetPivotTableManager().CreatePivotTablesRecord( mnScTab ) );
579 // list of NOTE records, generated by the cell table
580 XclExpRecordRef xNotes = mxCellTable->CreateRecord( EXC_ID_NOTE );
581 XclExpRecordList< XclExpNote >* xNoteList = dynamic_cast< XclExpRecordList< XclExpNote >* >( xNotes.get() );
582 if( xNoteList != NULL )
583 aRecList.AppendNewRecord( new XclExpComments( mnScTab, *xNoteList ) );
585 // web queries
586 Add( new XclExpWebQueryBuffer( GetRoot() ) );
588 lcl_AddScenariosAndFilters( aRecList, *this, mnScTab );
590 // MERGEDCELLS record, generated by the cell table
591 aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_MERGEDCELLS ) );
593 // conditional formats
594 Add( new XclExpCondFormatBuffer( GetRoot() ) );
596 if( HasVbaStorage() )
597 if( nCodeNameIdx < GetExtDocOptions().GetCodeNameCount() )
598 Add( new XclCodename( GetExtDocOptions().GetCodeName( nCodeNameIdx ) ) );
600 // data validation (DVAL and list of DV records), generated by the cell table
601 aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_DVAL ) );
603 // list of HLINK records, generated by the cell table
604 XclExpRecordRef xHyperlinks = mxCellTable->CreateRecord( EXC_ID_HLINK );
605 XclExpHyperlinkList* xHyperlinkList = dynamic_cast<XclExpHyperlinkList*>(xHyperlinks.get());
606 if( xHyperlinkList != NULL && !xHyperlinkList->IsEmpty() )
608 aRecList.AppendNewRecord( new XclExpXmlStartElementRecord( XML_hyperlinks ) );
609 aRecList.AppendRecord( xHyperlinks );
610 aRecList.AppendNewRecord( new XclExpXmlEndElementRecord( XML_hyperlinks ) );
613 aRecList.AppendRecord( xPageSett );
615 // change tracking
616 if( rR.pUserBViewList )
618 for( const XclExpUserBView* pBView = rR.pUserBViewList->First(); pBView; pBView = rR.pUserBViewList->Next() )
620 Add( new XclExpUsersViewBegin( pBView->GetGUID(), nExcTab ) );
621 Add( new XclExpUsersViewEnd );
625 // EOF
626 Add( new ExcEof );
630 void ExcTable::FillAsEmptyTable( size_t nCodeNameIdx )
632 InitializeTable( mnScTab );
634 if( HasVbaStorage() && (nCodeNameIdx < GetExtDocOptions().GetCodeNameCount()) )
636 if( GetBiff() <= EXC_BIFF5 )
638 Add( new ExcBof );
640 else
642 Add( new ExcBof8 );
643 Add( new XclCodename( GetExtDocOptions().GetCodeName( nCodeNameIdx ) ) );
645 // sheet view settings: WINDOW2, SCL, PANE, SELECTION
646 aRecList.AppendNewRecord( new XclExpTabViewSettings( GetRoot(), mnScTab ) );
647 Add( new ExcEof );
652 void ExcTable::Write( XclExpStream& rStrm )
654 SetCurrScTab( mnScTab );
655 if( mxCellTable.get() )
656 mxCellTable->Finalize();
657 aRecList.Save( rStrm );
661 void ExcTable::WriteXml( XclExpXmlStream& rStrm )
663 if (GetTabInfo().IsExportTab( mnScTab ) )
665 // worksheet export
666 String sSheetName = XclXmlUtils::GetStreamName( "xl/", "worksheets/sheet", mnScTab+1 );
668 sax_fastparser::FSHelperPtr pWorksheet = rStrm.GetStreamForPath( sSheetName );
670 rStrm.PushStream( pWorksheet );
672 pWorksheet->startElement( XML_worksheet,
673 XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
674 FSNS( XML_xmlns, XML_r ), "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
675 FSEND );
678 SetCurrScTab( mnScTab );
679 if( mxCellTable.get() )
680 mxCellTable->Finalize();
681 aRecList.SaveXml( rStrm );
683 if (GetTabInfo().IsExportTab( mnScTab ) )
685 rStrm.GetCurrentStream()->endElement( XML_worksheet );
686 rStrm.PopStream();
691 ExcDocument::ExcDocument( const XclExpRoot& rRoot ) :
692 XclExpRoot( rRoot ),
693 aHeader( rRoot ),
694 pExpChangeTrack( NULL )
699 ExcDocument::~ExcDocument()
701 maTableList.RemoveAllRecords(); //! for the following assertion
702 delete pExpChangeTrack;
706 void ExcDocument::ReadDoc( void )
708 InitializeConvert();
710 aHeader.FillAsHeader( maBoundsheetList );
712 SCTAB nScTab = 0, nScTabCount = GetTabInfo().GetScTabCount();
713 size_t nCodeNameIdx = 0, nCodeNameCount = GetExtDocOptions().GetCodeNameCount();
715 for( ; nScTab < nScTabCount; ++nScTab )
717 if( GetTabInfo().IsExportTab( nScTab ) )
719 ExcTableList::RecordRefType xTab( new ExcTable( GetRoot(), nScTab ) );
720 maTableList.AppendRecord( xTab );
721 xTab->FillAsTable( nCodeNameIdx );
722 ++nCodeNameIdx;
725 for( ; nCodeNameIdx < nCodeNameCount; ++nScTab, ++nCodeNameIdx )
727 ExcTableList::RecordRefType xTab( new ExcTable( GetRoot(), nScTab ) );
728 maTableList.AppendRecord( xTab );
729 xTab->FillAsEmptyTable( nCodeNameIdx );
732 if ( GetBiff() == EXC_BIFF8 )
734 // complete temporary Escher stream
735 GetOldRoot().pEscher->GetEx()->EndDocument();
737 // change tracking
738 if ( GetDoc().GetChangeTrack() )
739 pExpChangeTrack = new XclExpChangeTrack( GetRoot() );
744 void ExcDocument::Write( SvStream& rSvStrm )
746 if( !maTableList.IsEmpty() )
748 InitializeSave();
750 if ( GetBiff() == EXC_BIFF8 )
751 GetOldRoot().pEscher->GetStrm().Seek(0); // ready for take off
753 XclExpStream aXclStrm( rSvStrm, GetRoot() );
755 aHeader.Write( aXclStrm );
757 DBG_ASSERT( maTableList.GetSize() == maBoundsheetList.GetSize(),
758 "ExcDocument::Write - different number of sheets and BOUNDSHEET records" );
760 for( size_t nTab = 0, nTabCount = maTableList.GetSize(); nTab < nTabCount; ++nTab )
762 // set current stream position in BOUNDSHEET record
763 ExcBoundsheetRef xBoundsheet = maBoundsheetList.GetRecord( nTab );
764 if( xBoundsheet.get() )
765 xBoundsheet->SetStreamPos( aXclStrm.GetSvStreamPos() );
766 // write the table
767 maTableList.GetRecord( nTab )->Write( aXclStrm );
770 // write the table stream positions into the BOUNDSHEET records
771 for( size_t nBSheet = 0, nBSheetCount = maBoundsheetList.GetSize(); nBSheet < nBSheetCount; ++nBSheet )
772 maBoundsheetList.GetRecord( nBSheet )->UpdateStreamPos( aXclStrm );
774 if( pExpChangeTrack )
775 pExpChangeTrack->Write();
778 void ExcDocument::WriteXml( SvStream& rStrm )
780 if( !maTableList.IsEmpty() )
782 InitializeSave();
784 XclExpXmlStream aStrm( ::comphelper::getProcessServiceFactory(), rStrm, GetRoot() );
786 GetOldRoot().pEscher->GetStrm().Seek(0); // ready for take off
788 sax_fastparser::FSHelperPtr& rWorkbook = aStrm.GetCurrentStream();
789 rWorkbook->startElement( XML_workbook,
790 XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
791 FSNS(XML_xmlns, XML_r), "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
792 FSEND );
793 rWorkbook->singleElement( XML_fileVersion,
794 XML_appName, "Calc",
795 // OOXTODO: XML_codeName
796 // OOXTODO: XML_lastEdited
797 // OOXTODO: XML_lowestEdited
798 // OOXTODO: XML_rupBuild
799 FSEND );
801 aHeader.WriteXml( aStrm );
803 for( size_t nTab = 0, nTabCount = maTableList.GetSize(); nTab < nTabCount; ++nTab )
805 // set current stream position in BOUNDSHEET record
806 #if 0
807 ExcBoundsheetRef xBoundsheet = maBoundsheetList.GetRecord( nTab );
808 if( xBoundsheet.get() )
809 xBoundsheet->SetStreamPos( aXclStrm.GetSvStreamPos() );
810 #endif
811 // write the table
812 maTableList.GetRecord( nTab )->WriteXml( aStrm );
815 rWorkbook->endElement( XML_workbook );
816 rWorkbook.reset();
817 aStrm.commitStorage();
819 #if 0
820 if( pExpChangeTrack )
821 pExpChangeTrack->WriteXml();
822 #endif