bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / filter / excel / excdoc.cxx
blob7c64d474746e02af03a5228bb29287bdd5424e73
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "scitems.hxx"
22 #include <comphelper/processfactory.hxx>
23 #include <svx/svdobj.hxx>
24 #include <svx/svditer.hxx>
25 #include <svx/svdpage.hxx>
26 #include <editeng/lrspitem.hxx>
27 #include <editeng/ulspitem.hxx>
28 #include <svl/intitem.hxx>
29 #include <svl/zformat.hxx>
30 #include <sot/storage.hxx>
31 #include <sfx2/objsh.hxx>
32 #include <rtl/ustring.hxx>
34 #include "formulacell.hxx"
35 #include "dociter.hxx"
36 #include "document.hxx"
37 #include "rangenam.hxx"
38 #include "dbdata.hxx"
39 #include "global.hxx"
40 #include "globstr.hrc"
41 #include "progress.hxx"
42 #include "conditio.hxx"
43 #include "dpobject.hxx"
44 #include "attrib.hxx"
45 #include "scextopt.hxx"
46 #include "stlsheet.hxx"
47 #include "stlpool.hxx"
48 #include "olinetab.hxx"
49 #include "unonames.hxx"
50 #include "convuno.hxx"
51 #include "patattr.hxx"
52 #include "docoptio.hxx"
53 #include "tabprotection.hxx"
54 #include "postit.hxx"
56 #include "excdoc.hxx"
57 #include "namebuff.hxx"
58 #include "xeextlst.hxx"
60 #include "xcl97rec.hxx"
61 #include "xcl97esc.hxx"
62 #include "xetable.hxx"
63 #include "xelink.hxx"
64 #include "xename.hxx"
65 #include "xepage.hxx"
66 #include "xeview.hxx"
67 #include "xecontent.hxx"
68 #include "xeescher.hxx"
69 #include "xepivot.hxx"
70 #include "XclExpChangeTrack.hxx"
72 #include <math.h>
74 #include <com/sun/star/document/XDocumentProperties.hpp>
75 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
76 #include <oox/token/tokens.hxx>
77 #include <boost/shared_ptr.hpp>
79 using namespace oox;
81 static String lcl_GetVbaTabName( SCTAB n )
83 OUString aRet = "__VBA__" + OUString::number( static_cast<sal_uInt16>(n) );
84 return aRet;
88 static void lcl_AddBookviews( XclExpRecordList<>& aRecList, ExcTable& self )
90 aRecList.AppendNewRecord( new XclExpXmlStartElementRecord( XML_bookViews ) );
91 aRecList.AppendNewRecord( new XclExpWindow1( self.GetRoot() ) );
92 aRecList.AppendNewRecord( new XclExpXmlEndElementRecord( XML_bookViews ) );
95 static void lcl_AddCalcPr( XclExpRecordList<>& aRecList, ExcTable& self )
97 ScDocument& rDoc = self.GetDoc();
99 aRecList.AppendNewRecord( new XclExpXmlStartSingleElementRecord( XML_calcPr ) );
100 // OOXTODO: calcCompleted, calcId, calcMode, calcOnSave,
101 // concurrentCalc, concurrentManualCount,
102 // forceFullCalc, fullCalcOnLoad, fullPrecision
103 aRecList.AppendNewRecord( new XclCalccount( rDoc ) );
104 aRecList.AppendNewRecord( new XclRefmode( rDoc ) );
105 aRecList.AppendNewRecord( new XclIteration( rDoc ) );
106 aRecList.AppendNewRecord( new XclDelta( rDoc ) );
107 aRecList.AppendNewRecord( new XclExpBoolRecord(0x005F, true) ); // SAVERECALC
108 aRecList.AppendNewRecord( new XclExpXmlEndSingleElementRecord() ); // XML_calcPr
111 static void lcl_AddWorkbookProtection( XclExpRecordList<>& aRecList, ExcTable& self )
113 aRecList.AppendNewRecord( new XclExpXmlStartSingleElementRecord( XML_workbookProtection ) );
115 const ScDocProtection* pProtect = self.GetDoc().GetDocProtection();
116 if (pProtect && pProtect->isProtected())
118 aRecList.AppendNewRecord( new XclExpWindowProtection(pProtect->isOptionEnabled(ScDocProtection::WINDOWS)) );
119 aRecList.AppendNewRecord( new XclExpProtection(pProtect->isOptionEnabled(ScDocProtection::STRUCTURE)) );
120 aRecList.AppendNewRecord( new XclExpPassHash(pProtect->getPasswordHash(PASSHASH_XL)) );
123 aRecList.AppendNewRecord( new XclExpXmlEndSingleElementRecord() ); // XML_workbookProtection
126 static void lcl_AddScenariosAndFilters( XclExpRecordList<>& aRecList, const XclExpRoot& rRoot, SCTAB nScTab )
128 // Scenarios
129 aRecList.AppendNewRecord( new ExcEScenarioManager( rRoot, nScTab ) );
130 // filter
131 aRecList.AppendRecord( rRoot.GetFilterManager().CreateRecord( nScTab ) );
135 ExcTable::ExcTable( const XclExpRoot& rRoot ) :
136 XclExpRoot( rRoot ),
137 mnScTab( SCTAB_GLOBAL ),
138 nExcTab( EXC_NOTAB ),
139 pTabNames( new NameBuffer( 0, 16 ) ),
140 mxNoteList( new XclExpNoteList )
145 ExcTable::ExcTable( const XclExpRoot& rRoot, SCTAB nScTab ) :
146 XclExpRoot( rRoot ),
147 mnScTab( nScTab ),
148 nExcTab( rRoot.GetTabInfo().GetXclTab( nScTab ) ),
149 pTabNames( new NameBuffer( 0, 16 ) ),
150 mxNoteList( new XclExpNoteList )
155 ExcTable::~ExcTable()
157 delete pTabNames;
161 void ExcTable::Add( XclExpRecordBase* pRec )
163 OSL_ENSURE( pRec, "-ExcTable::Add(): pRec is NULL!" );
164 aRecList.AppendNewRecord( pRec );
168 void ExcTable::FillAsHeader( ExcBoundsheetList& rBoundsheetList )
170 InitializeGlobals();
172 RootData& rR = GetOldRoot();
173 ScDocument& rDoc = GetDoc();
174 XclExpTabInfo& rTabInfo = GetTabInfo();
176 if ( GetBiff() <= EXC_BIFF5 )
177 Add( new ExcBofW );
178 else
179 Add( new ExcBofW8 );
181 SCTAB nC;
182 OUString aTmpString;
183 SCTAB nScTabCount = rTabInfo.GetScTabCount();
184 sal_uInt16 nExcTabCount = rTabInfo.GetXclTabCount();
185 sal_uInt16 nCodenames = static_cast< sal_uInt16 >( GetExtDocOptions().GetCodeNameCount() );
187 SfxObjectShell* pShell = GetDocShell();
188 sal_uInt16 nWriteProtHash = pShell ? pShell->GetModifyPasswordHash() : 0;
189 bool bRecommendReadOnly = pShell && pShell->IsLoadReadonly();
191 if( (nWriteProtHash > 0) || bRecommendReadOnly )
192 Add( new XclExpEmptyRecord( EXC_ID_WRITEPROT ) );
194 // TODO: correct codepage for BIFF5?
195 sal_uInt16 nCodePage = XclTools::GetXclCodePage( (GetBiff() <= EXC_BIFF5) ? RTL_TEXTENCODING_MS_1252 : RTL_TEXTENCODING_UNICODE );
197 if( GetBiff() <= EXC_BIFF5 )
199 Add( new XclExpEmptyRecord( EXC_ID_INTERFACEHDR ) );
200 Add( new XclExpUInt16Record( EXC_ID_MMS, 0 ) );
201 Add( new XclExpEmptyRecord( EXC_ID_TOOLBARHDR ) );
202 Add( new XclExpEmptyRecord( EXC_ID_TOOLBAREND ) );
203 Add( new XclExpEmptyRecord( EXC_ID_INTERFACEEND ) );
204 Add( new ExcDummy_00 );
206 else
208 if( IsDocumentEncrypted() )
209 Add( new XclExpFileEncryption( GetRoot() ) );
210 Add( new XclExpInterfaceHdr( nCodePage ) );
211 Add( new XclExpUInt16Record( EXC_ID_MMS, 0 ) );
212 Add( new XclExpInterfaceEnd );
213 Add( new XclExpWriteAccess );
216 Add( new XclExpFileSharing( GetRoot(), nWriteProtHash, bRecommendReadOnly ) );
217 Add( new XclExpUInt16Record( EXC_ID_CODEPAGE, nCodePage ) );
219 if( GetBiff() == EXC_BIFF8 )
221 Add( new XclExpBoolRecord( EXC_ID_DSF, false ) );
222 Add( new XclExpEmptyRecord( EXC_ID_XL9FILE ) );
223 rR.pTabId = new XclExpChTrTabId( std::max( nExcTabCount, nCodenames ) );
224 Add( rR.pTabId );
225 if( HasVbaStorage() )
227 Add( new XclObproj );
228 const String& rCodeName = GetExtDocOptions().GetDocSettings().maGlobCodeName;
229 if( rCodeName.Len() )
230 Add( new XclCodename( rCodeName ) );
234 Add( new XclExpUInt16Record( EXC_ID_FNGROUPCOUNT, 14 ) );
236 // erst Namen- und Tabellen-Eintraege aufbauen
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 if( GetOutput() == EXC_OUTPUT_BINARY )
255 lcl_AddWorkbookProtection( aRecList, *this );
257 if( GetBiff() == EXC_BIFF8 )
259 Add( new XclExpProt4Rev );
260 Add( new XclExpProt4RevPass );
263 lcl_AddBookviews( aRecList, *this );
266 Add( new XclExpXmlStartSingleElementRecord( XML_workbookPr ) );
267 if ( GetBiff() == EXC_BIFF8 && GetOutput() != EXC_OUTPUT_BINARY )
269 Add( new XclExpBoolRecord(0x0040, false, XML_backupFile ) ); // BACKUP
270 Add( new XclExpBoolRecord(0x008D, false, XML_showObjects ) ); // HIDEOBJ
273 if ( GetBiff() == EXC_BIFF8 )
275 Add( new XclExpBoolRecord(0x0040, false) ); // BACKUP
276 Add( new XclExpBoolRecord(0x008D, false) ); // HIDEOBJ
279 if( GetBiff() <= EXC_BIFF5 )
281 Add( new ExcDummy_040 );
282 Add( new Exc1904( rDoc ) );
283 Add( new ExcDummy_041 );
285 else
287 // BIFF8
288 Add( new Exc1904( rDoc ) );
289 Add( new XclExpBoolRecord( 0x000E, !rDoc.GetDocOptions().IsCalcAsShown() ) );
290 Add( new XclExpBoolRecord(0x01B7, false) ); // REFRESHALL
291 Add( new XclExpBoolRecord(0x00DA, false) ); // BOOKBOOL
292 // OOXTODO: The following /workbook/workbookPr attributes are mapped
293 // to various BIFF records that are not currently supported:
295 // XML_allowRefreshQuery: QSISTAG 802h: fEnableRefresh
296 // XML_autoCompressPictures: COMPRESSPICTURES 89Bh: fAutoCompressPictures
297 // XML_checkCompatibility: COMPAT12 88Ch: fNoCompatChk
298 // XML_codeName: "Calc"
299 // XML_defaultThemeVersion: ???
300 // XML_filterPrivacy: BOOKEXT 863h: fFilterPrivacy
301 // XML_hidePivotFieldList: BOOKBOOL DAh: fHidePivotTableFList
302 // XML_promptedSolutions: BOOKEXT 863h: fBuggedUserAboutSolution
303 // XML_publishItems: NAMEPUBLISH 893h: fPublished
304 // XML_saveExternalLinkValues: BOOKBOOL DAh: fNoSavSupp
305 // XML_showBorderUnselectedTables: BOOKBOOL DAh: fHideBorderUnsels
306 // XML_showInkAnnotation: BOOKEXT 863h: fShowInkAnnotation
307 // XML_showPivotChart: PIVOTCHARTBITS 859h: fGXHide??
308 // XML_updateLinks: BOOKBOOL DAh: grbitUpdateLinks
310 Add( new XclExpXmlEndSingleElementRecord() ); // XML_workbookPr
312 // Formatting: FONT, FORMAT, XF, STYLE, PALETTE
313 if( GetOutput() != EXC_OUTPUT_BINARY )
315 aRecList.AppendNewRecord( new XclExpXmlStyleSheet( *this ) );
317 else
319 aRecList.AppendRecord( CreateRecord( EXC_ID_FONTLIST ) );
320 aRecList.AppendRecord( CreateRecord( EXC_ID_FORMATLIST ) );
321 aRecList.AppendRecord( CreateRecord( EXC_ID_XFLIST ) );
322 aRecList.AppendRecord( CreateRecord( EXC_ID_PALETTE ) );
326 if( GetBiff() <= EXC_BIFF5 )
328 // Bundlesheet
329 for( nC = 0 ; nC < nScTabCount ; nC++ )
330 if( rTabInfo.IsExportTab( nC ) )
332 ExcBoundsheetList::RecordRefType xBoundsheet( new ExcBundlesheet( rR, nC ) );
333 aRecList.AppendRecord( xBoundsheet );
334 rBoundsheetList.AppendRecord( xBoundsheet );
337 else
339 // Pivot Cache
340 GetPivotTableManager().CreatePivotTables();
341 aRecList.AppendRecord( GetPivotTableManager().CreatePivotCachesRecord() );
343 // Change tracking
344 if( rDoc.GetChangeTrack() )
346 rR.pUserBViewList = new XclExpUserBViewList( *rDoc.GetChangeTrack() );
347 Add( rR.pUserBViewList );
350 // Natural Language Formulas Flag
351 aRecList.AppendNewRecord( new XclExpBoolRecord( EXC_ID_USESELFS, GetDoc().GetDocOptions().IsLookUpColRowNames() ) );
353 if( GetOutput() != EXC_OUTPUT_BINARY )
355 lcl_AddWorkbookProtection( aRecList, *this );
356 lcl_AddBookviews( aRecList, *this );
359 // Bundlesheet
360 aRecList.AppendNewRecord( new XclExpXmlStartElementRecord( XML_sheets ) );
361 for( nC = 0 ; nC < nScTabCount ; nC++ )
362 if( rTabInfo.IsExportTab( nC ) )
364 ExcBoundsheetList::RecordRefType xBoundsheet( new ExcBundlesheet8( rR, nC ) );
365 aRecList.AppendRecord( xBoundsheet );
366 rBoundsheetList.AppendRecord( xBoundsheet );
368 aRecList.AppendNewRecord( new XclExpXmlEndElementRecord( XML_sheets ) );
370 for( SCTAB nAdd = 0; nC < static_cast<SCTAB>(nCodenames) ; nC++, nAdd++ )
372 aTmpString = lcl_GetVbaTabName( nAdd );
373 ExcBoundsheetList::RecordRefType xBoundsheet( new ExcBundlesheet8( aTmpString ) );
374 aRecList.AppendRecord( xBoundsheet );
375 rBoundsheetList.AppendRecord( xBoundsheet );
378 // COUNTRY - in BIFF8 in workbook globals
379 Add( new XclExpCountry( GetRoot() ) );
380 // link table: SUPBOOK, XCT, CRN, EXTERNNAME, EXTERNSHEET, NAME
381 aRecList.AppendRecord( CreateRecord( EXC_ID_EXTERNSHEET ) );
382 aRecList.AppendRecord( CreateRecord( EXC_ID_NAME ) );
384 if( GetOutput() != EXC_OUTPUT_BINARY )
385 lcl_AddCalcPr( aRecList, *this );
387 Add( new XclExpRecalcId );
389 // MSODRAWINGGROUP per-document data
390 aRecList.AppendRecord( GetObjectManager().CreateDrawingGroup() );
391 // Shared string table: SST, EXTSST
392 aRecList.AppendRecord( CreateRecord( EXC_ID_SST ) );
394 Add( new XclExpBookExt );
397 Add( new ExcEof );
401 void ExcTable::FillAsTable( SCTAB nCodeNameIdx )
403 InitializeTable( mnScTab );
405 RootData& rR = GetOldRoot();
406 XclBiff eBiff = GetBiff();
407 ScDocument& rDoc = GetDoc();
409 OSL_ENSURE( (mnScTab >= 0L) && (mnScTab <= MAXTAB), "-ExcTable::Table(): mnScTab - no ordinary table!" );
410 OSL_ENSURE( nExcTab <= static_cast<sal_uInt16>(MAXTAB), "-ExcTable::Table(): nExcTab - no ordinary table!" );
412 // create a new OBJ list for this sheet (may be used by notes, autofilter, data validation)
413 if( eBiff == EXC_BIFF8 )
414 GetObjectManager().StartSheet();
416 // cell table: DEFROWHEIGHT, DEFCOLWIDTH, COLINFO, DIMENSIONS, ROW, cell records
417 mxCellTable.reset( new XclExpCellTable( GetRoot() ) );
419 //export cell notes
420 ScNotes::iterator itr = rDoc.GetNotes(mnScTab)->begin();
421 ScNotes::iterator itrEnd = rDoc.GetNotes(mnScTab)->end();
422 for (; itr != itrEnd; ++itr)
424 // notes
425 const ScPostIt* pScNote = itr->second;
426 ScAddress aScPos( itr->first.first, itr->first.second, mnScTab );
427 mxNoteList->AppendNewRecord( new XclExpNote( GetRoot(), aScPos, pScNote, OUString() ) );
430 if( GetOutput() != EXC_OUTPUT_BINARY )
432 FillAsXmlTable( nCodeNameIdx );
433 return;
437 // WSBOOL needs data from page settings, create it here, add it later
438 boost::shared_ptr< XclExpPageSettings > xPageSett( new XclExpPageSettings( GetRoot() ) );
439 bool bFitToPages = xPageSett->GetPageData().mbFitToPages;
441 if( eBiff <= EXC_BIFF5 )
443 Add( new ExcBof );
444 Add( new ExcDummy_02a );
446 else
448 Add( new ExcBof8 );
449 lcl_AddCalcPr( aRecList, *this );
452 // GUTS (count & size of outline icons)
453 aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_GUTS ) );
454 // DEFROWHEIGHT, created by the cell table
455 aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID2_DEFROWHEIGHT ) );
457 // COUNTRY - in BIFF5/7 in every worksheet
458 if( eBiff <= EXC_BIFF5 )
459 Add( new XclExpCountry( GetRoot() ) );
461 Add( new XclExpWsbool( bFitToPages ) );
463 // page settings (SETUP and various other records)
464 aRecList.AppendRecord( xPageSett );
466 const ScTableProtection* pTabProtect = rDoc.GetTabProtection(mnScTab);
467 if (pTabProtect && pTabProtect->isProtected())
469 Add( new XclExpProtection(true) );
470 Add( new XclExpBoolRecord(0x00DD, pTabProtect->isOptionEnabled(ScTableProtection::SCENARIOS)) );
471 Add( new XclExpBoolRecord(0x0063, pTabProtect->isOptionEnabled(ScTableProtection::OBJECTS)) );
472 Add( new XclExpPassHash(pTabProtect->getPasswordHash(PASSHASH_XL)) );
475 // local link table: EXTERNCOUNT, EXTERNSHEET
476 if( eBiff <= EXC_BIFF5 )
477 aRecList.AppendRecord( CreateRecord( EXC_ID_EXTERNSHEET ) );
479 if ( eBiff == EXC_BIFF8 )
480 lcl_AddScenariosAndFilters( aRecList, GetRoot(), mnScTab );
482 // cell table: DEFCOLWIDTH, COLINFO, DIMENSIONS, ROW, cell records
483 aRecList.AppendRecord( mxCellTable );
485 // MERGEDCELLS record, generated by the cell table
486 aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_MERGEDCELLS ) );
487 // label ranges
488 if( eBiff == EXC_BIFF8 )
489 Add( new XclExpLabelranges( GetRoot() ) );
490 // data validation (DVAL and list of DV records), generated by the cell table
491 aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_DVAL ) );
493 if( eBiff == EXC_BIFF8 )
495 // all MSODRAWING and OBJ stuff of this sheet goes here
496 aRecList.AppendRecord( GetObjectManager().ProcessDrawing( GetSdrPage( mnScTab ) ) );
497 // pivot tables
498 aRecList.AppendRecord( GetPivotTableManager().CreatePivotTablesRecord( mnScTab ) );
501 // list of NOTE records, generated by the cell table
502 aRecList.AppendRecord( mxNoteList );
504 // sheet view settings: WINDOW2, SCL, PANE, SELECTION
505 aRecList.AppendNewRecord( new XclExpTabViewSettings( GetRoot(), mnScTab ) );
507 if( eBiff == EXC_BIFF8 )
509 // sheet protection options
510 Add( new XclExpSheetProtectOptions( GetRoot(), mnScTab ) );
512 // web queries
513 Add( new XclExpWebQueryBuffer( GetRoot() ) );
515 // conditional formats
516 Add( new XclExpCondFormatBuffer( GetRoot(), XclExtLstRef() ) );
518 if( HasVbaStorage() )
519 if( nCodeNameIdx < GetExtDocOptions().GetCodeNameCount() )
520 Add( new XclCodename( GetExtDocOptions().GetCodeName( nCodeNameIdx ) ) );
523 // list of HLINK records, generated by the cell table
524 aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_HLINK ) );
526 // change tracking
527 if( rR.pUserBViewList )
529 XclExpUserBViewList::const_iterator iter;
530 for ( iter = rR.pUserBViewList->begin(); iter != rR.pUserBViewList->end(); ++iter)
532 Add( new XclExpUsersViewBegin( (*iter)->GetGUID(), nExcTab ) );
533 Add( new XclExpUsersViewEnd );
537 // EOF
538 Add( new ExcEof );
541 void ExcTable::FillAsXmlTable( SCTAB nCodeNameIdx )
543 RootData& rR = GetOldRoot();
545 // WSBOOL needs data from page settings, create it here, add it later
546 boost::shared_ptr< XclExpPageSettings > xPageSett( new XclExpPageSettings( GetRoot() ) );
547 XclExtLstRef xExtLst( new XclExtLst( GetRoot() ) );
548 bool bFitToPages = xPageSett->GetPageData().mbFitToPages;
550 Add( new ExcBof8 );
552 Add( new XclExpWsbool( bFitToPages, mnScTab, &GetFilterManager() ) );
554 // GUTS (count & size of outline icons)
555 aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_GUTS ) );
556 // DEFROWHEIGHT, created by the cell table
557 aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID2_DEFROWHEIGHT ) );
559 aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID3_DIMENSIONS ) );
561 // sheet view settings: WINDOW2, SCL, PANE, SELECTION
562 aRecList.AppendNewRecord( new XclExpTabViewSettings( GetRoot(), mnScTab ) );
564 // cell table: DEFCOLWIDTH, COLINFO, DIMENSIONS, ROW, cell records
565 aRecList.AppendRecord( mxCellTable );
567 // label ranges
568 Add( new XclExpLabelranges( GetRoot() ) );
570 // DFF not needed in MSOOXML export
571 // GetObjectManager().AddSdrPage();
572 // //! close Escher group shape and ESCHER_DgContainer
573 // //! opened by XclExpObjList ctor MSODRAWING
574 // rR.pObjRecs->EndSheet();
575 // // all MSODRAWING and OBJ stuff of this sheet goes here
576 // Add( rR.pObjRecs );
578 // pivot tables
579 aRecList.AppendRecord( GetPivotTableManager().CreatePivotTablesRecord( mnScTab ) );
581 // list of NOTE records, generated by the cell table
582 if( mxNoteList != NULL && !mxNoteList->IsEmpty() )
583 aRecList.AppendNewRecord( new XclExpComments( mnScTab, *mxNoteList ) );
585 // web queries
586 Add( new XclExpWebQueryBuffer( GetRoot() ) );
588 lcl_AddScenariosAndFilters( aRecList, GetRoot(), 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(), xExtLst ) );
596 ScDocument& rDoc = GetDoc();
597 const ScTableProtection* pTabProtect = rDoc.GetTabProtection(mnScTab);
598 if (pTabProtect && pTabProtect->isProtected())
599 Add( new XclExpSheetProtection(true, mnScTab) );
601 if( HasVbaStorage() )
602 if( nCodeNameIdx < GetExtDocOptions().GetCodeNameCount() )
603 Add( new XclCodename( GetExtDocOptions().GetCodeName( nCodeNameIdx ) ) );
605 // data validation (DVAL and list of DV records), generated by the cell table
606 aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_DVAL ) );
608 // list of HLINK records, generated by the cell table
609 XclExpRecordRef xHyperlinks = mxCellTable->CreateRecord( EXC_ID_HLINK );
610 XclExpHyperlinkList* xHyperlinkList = dynamic_cast<XclExpHyperlinkList*>(xHyperlinks.get());
611 if( xHyperlinkList != NULL && !xHyperlinkList->IsEmpty() )
613 aRecList.AppendNewRecord( new XclExpXmlStartElementRecord( XML_hyperlinks ) );
614 aRecList.AppendRecord( xHyperlinks );
615 aRecList.AppendNewRecord( new XclExpXmlEndElementRecord( XML_hyperlinks ) );
618 aRecList.AppendRecord( xPageSett );
620 // change tracking
621 if( rR.pUserBViewList )
623 XclExpUserBViewList::const_iterator iter;
624 for ( iter = rR.pUserBViewList->begin(); iter != rR.pUserBViewList->end(); ++iter )
626 Add( new XclExpUsersViewBegin( (*iter)->GetGUID(), nExcTab ) );
627 Add( new XclExpUsersViewEnd );
631 // all MSODRAWING and OBJ stuff of this sheet goes here
632 aRecList.AppendRecord( GetObjectManager().ProcessDrawing( GetSdrPage( mnScTab ) ) );
634 aRecList.AppendRecord( xExtLst );
636 // EOF
637 Add( new ExcEof );
641 void ExcTable::FillAsEmptyTable( SCTAB nCodeNameIdx )
643 InitializeTable( mnScTab );
645 if( HasVbaStorage() && (nCodeNameIdx < GetExtDocOptions().GetCodeNameCount()) )
647 if( GetBiff() <= EXC_BIFF5 )
649 Add( new ExcBof );
651 else
653 Add( new ExcBof8 );
654 Add( new XclCodename( GetExtDocOptions().GetCodeName( nCodeNameIdx ) ) );
656 // sheet view settings: WINDOW2, SCL, PANE, SELECTION
657 aRecList.AppendNewRecord( new XclExpTabViewSettings( GetRoot(), mnScTab ) );
658 Add( new ExcEof );
663 void ExcTable::Write( XclExpStream& rStrm )
665 SetCurrScTab( mnScTab );
666 if( mxCellTable.get() )
667 mxCellTable->Finalize();
668 aRecList.Save( rStrm );
672 void ExcTable::WriteXml( XclExpXmlStream& rStrm )
674 if (GetTabInfo().IsExportTab( mnScTab ) )
676 // worksheet export
677 String sSheetName = XclXmlUtils::GetStreamName( "xl/", "worksheets/sheet", mnScTab+1 );
679 sax_fastparser::FSHelperPtr pWorksheet = rStrm.GetStreamForPath( sSheetName );
681 rStrm.PushStream( pWorksheet );
683 pWorksheet->startElement( XML_worksheet,
684 XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
685 FSNS( XML_xmlns, XML_r ), "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
686 FSEND );
689 SetCurrScTab( mnScTab );
690 if( mxCellTable.get() )
691 mxCellTable->Finalize();
692 aRecList.SaveXml( rStrm );
694 if (GetTabInfo().IsExportTab( mnScTab ) )
696 rStrm.GetCurrentStream()->endElement( XML_worksheet );
697 rStrm.PopStream();
702 ExcDocument::ExcDocument( const XclExpRoot& rRoot ) :
703 XclExpRoot( rRoot ),
704 aHeader( rRoot ),
705 pExpChangeTrack( NULL )
710 ExcDocument::~ExcDocument()
712 maTableList.RemoveAllRecords(); //! for the following assertion
713 delete pExpChangeTrack;
717 void ExcDocument::ReadDoc( void )
719 InitializeConvert();
721 aHeader.FillAsHeader( maBoundsheetList );
723 SCTAB nScTab = 0, nScTabCount = GetTabInfo().GetScTabCount();
724 SCTAB nCodeNameIdx = 0, nCodeNameCount = GetExtDocOptions().GetCodeNameCount();
726 for( ; nScTab < nScTabCount; ++nScTab )
728 if( GetTabInfo().IsExportTab( nScTab ) )
730 ExcTableList::RecordRefType xTab( new ExcTable( GetRoot(), nScTab ) );
731 maTableList.AppendRecord( xTab );
732 xTab->FillAsTable( nCodeNameIdx );
733 ++nCodeNameIdx;
736 for( ; nCodeNameIdx < nCodeNameCount; ++nScTab, ++nCodeNameIdx )
738 ExcTableList::RecordRefType xTab( new ExcTable( GetRoot(), nScTab ) );
739 maTableList.AppendRecord( xTab );
740 xTab->FillAsEmptyTable( nCodeNameIdx );
743 if ( GetBiff() == EXC_BIFF8 )
745 // complete temporary Escher stream
746 GetObjectManager().EndDocument();
748 // change tracking
749 if ( GetDoc().GetChangeTrack() )
750 pExpChangeTrack = new XclExpChangeTrack( GetRoot() );
755 void ExcDocument::Write( SvStream& rSvStrm )
757 if( !maTableList.IsEmpty() )
759 InitializeSave();
761 XclExpStream aXclStrm( rSvStrm, GetRoot() );
763 aHeader.Write( aXclStrm );
765 OSL_ENSURE( maTableList.GetSize() == maBoundsheetList.GetSize(),
766 "ExcDocument::Write - different number of sheets and BOUNDSHEET records" );
768 for( size_t nTab = 0, nTabCount = maTableList.GetSize(); nTab < nTabCount; ++nTab )
770 // set current stream position in BOUNDSHEET record
771 ExcBoundsheetRef xBoundsheet = maBoundsheetList.GetRecord( nTab );
772 if( xBoundsheet.get() )
773 xBoundsheet->SetStreamPos( aXclStrm.GetSvStreamPos() );
774 // write the table
775 maTableList.GetRecord( nTab )->Write( aXclStrm );
778 // write the table stream positions into the BOUNDSHEET records
779 for( size_t nBSheet = 0, nBSheetCount = maBoundsheetList.GetSize(); nBSheet < nBSheetCount; ++nBSheet )
780 maBoundsheetList.GetRecord( nBSheet )->UpdateStreamPos( aXclStrm );
782 if( pExpChangeTrack )
783 pExpChangeTrack->Write();
786 void ExcDocument::WriteXml( XclExpXmlStream& rStrm )
788 SfxObjectShell* pDocShell = GetDocShell();
790 using namespace ::com::sun::star;
791 uno::Reference<document::XDocumentPropertiesSupplier> xDPS( pDocShell->GetModel(), uno::UNO_QUERY_THROW );
792 uno::Reference<document::XDocumentProperties> xDocProps = xDPS->getDocumentProperties();
794 rStrm.exportDocumentProperties( xDocProps );
796 sax_fastparser::FSHelperPtr& rWorkbook = rStrm.GetCurrentStream();
797 rWorkbook->startElement( XML_workbook,
798 XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
799 FSNS(XML_xmlns, XML_r), "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
800 FSEND );
801 rWorkbook->singleElement( XML_fileVersion,
802 XML_appName, "Calc",
803 // OOXTODO: XML_codeName
804 // OOXTODO: XML_lastEdited
805 // OOXTODO: XML_lowestEdited
806 // OOXTODO: XML_rupBuild
807 FSEND );
809 if( !maTableList.IsEmpty() )
811 InitializeSave();
813 aHeader.WriteXml( rStrm );
815 for( size_t nTab = 0, nTabCount = maTableList.GetSize(); nTab < nTabCount; ++nTab )
817 // write the table
818 maTableList.GetRecord( nTab )->WriteXml( rStrm );
822 if( pExpChangeTrack )
823 pExpChangeTrack->WriteXml( rStrm );
825 rWorkbook->endElement( XML_workbook );
826 rWorkbook.reset();
828 rStrm.commitStorage();
831 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */