Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "scitems.hxx"
21 :
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>
33 :
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"
55 :
56 : #include "excdoc.hxx"
57 : #include "namebuff.hxx"
58 : #include "xeextlst.hxx"
59 :
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"
71 : #include <xepivotxml.hxx>
72 :
73 : #include <math.h>
74 :
75 : #include <com/sun/star/document/XDocumentProperties.hpp>
76 : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
77 : #include <oox/token/tokens.hxx>
78 : #include <boost/shared_ptr.hpp>
79 :
80 : using namespace oox;
81 :
82 0 : static OUString lcl_GetVbaTabName( SCTAB n )
83 : {
84 0 : OUString aRet = "__VBA__" + OUString::number( static_cast<sal_uInt16>(n) );
85 0 : return aRet;
86 : }
87 :
88 64 : static void lcl_AddBookviews( XclExpRecordList<>& aRecList, ExcTable& self )
89 : {
90 64 : aRecList.AppendNewRecord( new XclExpXmlStartElementRecord( XML_bookViews ) );
91 64 : aRecList.AppendNewRecord( new XclExpWindow1( self.GetRoot() ) );
92 64 : aRecList.AppendNewRecord( new XclExpXmlEndElementRecord( XML_bookViews ) );
93 64 : }
94 :
95 88 : static void lcl_AddCalcPr( XclExpRecordList<>& aRecList, ExcTable& self )
96 : {
97 88 : ScDocument& rDoc = self.GetDoc();
98 :
99 88 : aRecList.AppendNewRecord( new XclExpXmlStartSingleElementRecord( XML_calcPr ) );
100 : // OOXTODO: calcCompleted, calcId, calcMode, calcOnSave,
101 : // concurrentCalc, concurrentManualCount,
102 : // forceFullCalc, fullCalcOnLoad, fullPrecision
103 88 : aRecList.AppendNewRecord( new XclCalccount( rDoc ) );
104 88 : aRecList.AppendNewRecord( new XclRefmode( rDoc ) );
105 88 : aRecList.AppendNewRecord( new XclIteration( rDoc ) );
106 88 : aRecList.AppendNewRecord( new XclDelta( rDoc ) );
107 88 : aRecList.AppendNewRecord( new XclExpBoolRecord(0x005F, true) ); // SAVERECALC
108 88 : aRecList.AppendNewRecord( new XclExpXmlEndSingleElementRecord() ); // XML_calcPr
109 88 : }
110 :
111 64 : static void lcl_AddWorkbookProtection( XclExpRecordList<>& aRecList, ExcTable& self )
112 : {
113 64 : aRecList.AppendNewRecord( new XclExpXmlStartSingleElementRecord( XML_workbookProtection ) );
114 :
115 64 : const ScDocProtection* pProtect = self.GetDoc().GetDocProtection();
116 64 : if (pProtect && pProtect->isProtected())
117 : {
118 0 : aRecList.AppendNewRecord( new XclExpWindowProtection(pProtect->isOptionEnabled(ScDocProtection::WINDOWS)) );
119 0 : aRecList.AppendNewRecord( new XclExpProtection(pProtect->isOptionEnabled(ScDocProtection::STRUCTURE)) );
120 0 : aRecList.AppendNewRecord( new XclExpPassHash(pProtect->getPasswordHash(PASSHASH_XL)) );
121 : }
122 :
123 64 : aRecList.AppendNewRecord( new XclExpXmlEndSingleElementRecord() ); // XML_workbookProtection
124 64 : }
125 :
126 124 : static void lcl_AddScenariosAndFilters( XclExpRecordList<>& aRecList, const XclExpRoot& rRoot, SCTAB nScTab )
127 : {
128 : // Scenarios
129 124 : aRecList.AppendNewRecord( new ExcEScenarioManager( rRoot, nScTab ) );
130 : // filter
131 124 : aRecList.AppendRecord( rRoot.GetFilterManager().CreateRecord( nScTab ) );
132 124 : }
133 :
134 64 : ExcTable::ExcTable( const XclExpRoot& rRoot ) :
135 : XclExpRoot( rRoot ),
136 : mnScTab( SCTAB_GLOBAL ),
137 : nExcTab( EXC_NOTAB ),
138 64 : pTabNames( new NameBuffer( 0, 16 ) ),
139 128 : mxNoteList( new XclExpNoteList )
140 : {
141 64 : }
142 :
143 124 : ExcTable::ExcTable( const XclExpRoot& rRoot, SCTAB nScTab ) :
144 : XclExpRoot( rRoot ),
145 : mnScTab( nScTab ),
146 124 : nExcTab( rRoot.GetTabInfo().GetXclTab( nScTab ) ),
147 124 : pTabNames( new NameBuffer( 0, 16 ) ),
148 372 : mxNoteList( new XclExpNoteList )
149 : {
150 124 : }
151 :
152 500 : ExcTable::~ExcTable()
153 : {
154 188 : delete pTabNames;
155 312 : }
156 :
157 1380 : void ExcTable::Add( XclExpRecordBase* pRec )
158 : {
159 : OSL_ENSURE( pRec, "-ExcTable::Add(): pRec is NULL!" );
160 1380 : aRecList.AppendNewRecord( pRec );
161 1380 : }
162 :
163 26 : void ExcTable::FillAsHeaderBinary( ExcBoundsheetList& rBoundsheetList )
164 : {
165 26 : InitializeGlobals();
166 :
167 26 : RootData& rR = GetOldRoot();
168 26 : ScDocument& rDoc = GetDoc();
169 26 : XclExpTabInfo& rTabInfo = GetTabInfo();
170 :
171 26 : if ( GetBiff() <= EXC_BIFF5 )
172 0 : Add( new ExcBofW );
173 : else
174 26 : Add( new ExcBofW8 );
175 :
176 : SCTAB nC;
177 26 : OUString aTmpString;
178 26 : SCTAB nScTabCount = rTabInfo.GetScTabCount();
179 26 : sal_uInt16 nExcTabCount = rTabInfo.GetXclTabCount();
180 26 : sal_uInt16 nCodenames = static_cast< sal_uInt16 >( GetExtDocOptions().GetCodeNameCount() );
181 :
182 26 : SfxObjectShell* pShell = GetDocShell();
183 26 : sal_uInt16 nWriteProtHash = pShell ? pShell->GetModifyPasswordHash() : 0;
184 26 : bool bRecommendReadOnly = pShell && pShell->IsLoadReadonly();
185 :
186 26 : if( (nWriteProtHash > 0) || bRecommendReadOnly )
187 0 : Add( new XclExpEmptyRecord( EXC_ID_WRITEPROT ) );
188 :
189 : // TODO: correct codepage for BIFF5?
190 26 : sal_uInt16 nCodePage = XclTools::GetXclCodePage( (GetBiff() <= EXC_BIFF5) ? RTL_TEXTENCODING_MS_1252 : RTL_TEXTENCODING_UNICODE );
191 :
192 26 : if( GetBiff() <= EXC_BIFF5 )
193 : {
194 0 : Add( new XclExpEmptyRecord( EXC_ID_INTERFACEHDR ) );
195 0 : Add( new XclExpUInt16Record( EXC_ID_MMS, 0 ) );
196 0 : Add( new XclExpEmptyRecord( EXC_ID_TOOLBARHDR ) );
197 0 : Add( new XclExpEmptyRecord( EXC_ID_TOOLBAREND ) );
198 0 : Add( new XclExpEmptyRecord( EXC_ID_INTERFACEEND ) );
199 0 : Add( new ExcDummy_00 );
200 : }
201 : else
202 : {
203 26 : if( IsDocumentEncrypted() )
204 0 : Add( new XclExpFileEncryption( GetRoot() ) );
205 26 : Add( new XclExpInterfaceHdr( nCodePage ) );
206 26 : Add( new XclExpUInt16Record( EXC_ID_MMS, 0 ) );
207 26 : Add( new XclExpInterfaceEnd );
208 26 : Add( new XclExpWriteAccess );
209 : }
210 :
211 26 : Add( new XclExpFileSharing( GetRoot(), nWriteProtHash, bRecommendReadOnly ) );
212 26 : Add( new XclExpUInt16Record( EXC_ID_CODEPAGE, nCodePage ) );
213 :
214 26 : if( GetBiff() == EXC_BIFF8 )
215 : {
216 26 : Add( new XclExpBoolRecord( EXC_ID_DSF, false ) );
217 26 : Add( new XclExpEmptyRecord( EXC_ID_XL9FILE ) );
218 26 : rR.pTabId = new XclExpChTrTabId( std::max( nExcTabCount, nCodenames ) );
219 26 : Add( rR.pTabId );
220 26 : if( HasVbaStorage() )
221 : {
222 0 : Add( new XclObproj );
223 0 : const OUString& rCodeName = GetExtDocOptions().GetDocSettings().maGlobCodeName;
224 0 : if( !rCodeName.isEmpty() )
225 0 : Add( new XclCodename( rCodeName ) );
226 : }
227 : }
228 :
229 26 : Add( new XclExpUInt16Record( EXC_ID_FNGROUPCOUNT, 14 ) );
230 :
231 : // first setup table names and contents
232 :
233 76 : for( nC = 0 ; nC < nScTabCount ; nC++ )
234 50 : if( rTabInfo.IsExportTab( nC ) )
235 : {
236 50 : rDoc.GetName( nC, aTmpString );
237 50 : *pTabNames << aTmpString;
238 : }
239 :
240 26 : if ( GetBiff() <= EXC_BIFF5 )
241 : {
242 : // global link table: EXTERNCOUNT, EXTERNSHEET, NAME
243 0 : aRecList.AppendRecord( CreateRecord( EXC_ID_EXTERNSHEET ) );
244 0 : aRecList.AppendRecord( CreateRecord( EXC_ID_NAME ) );
245 : }
246 :
247 : // document protection options
248 26 : lcl_AddWorkbookProtection( aRecList, *this );
249 :
250 26 : if( GetBiff() == EXC_BIFF8 )
251 : {
252 26 : Add( new XclExpProt4Rev );
253 26 : Add( new XclExpProt4RevPass );
254 : }
255 :
256 26 : lcl_AddBookviews( aRecList, *this );
257 :
258 26 : Add( new XclExpXmlStartSingleElementRecord( XML_workbookPr ) );
259 26 : if ( GetBiff() == EXC_BIFF8 && GetOutput() != EXC_OUTPUT_BINARY )
260 : {
261 0 : Add( new XclExpBoolRecord(0x0040, false, XML_backupFile ) ); // BACKUP
262 0 : Add( new XclExpBoolRecord(0x008D, false, XML_showObjects ) ); // HIDEOBJ
263 : }
264 :
265 26 : if ( GetBiff() == EXC_BIFF8 )
266 : {
267 26 : Add( new XclExpBoolRecord(0x0040, false) ); // BACKUP
268 26 : Add( new XclExpBoolRecord(0x008D, false) ); // HIDEOBJ
269 : }
270 :
271 26 : if( GetBiff() <= EXC_BIFF5 )
272 : {
273 0 : Add( new ExcDummy_040 );
274 0 : Add( new Exc1904( rDoc ) );
275 0 : Add( new ExcDummy_041 );
276 : }
277 : else
278 : {
279 : // BIFF8
280 26 : Add( new Exc1904( rDoc ) );
281 26 : Add( new XclExpBoolRecord( 0x000E, !rDoc.GetDocOptions().IsCalcAsShown() ) );
282 26 : Add( new XclExpBoolRecord(0x01B7, false) ); // REFRESHALL
283 26 : Add( new XclExpBoolRecord(0x00DA, false) ); // BOOKBOOL
284 : }
285 :
286 : // Formatting: FONT, FORMAT, XF, STYLE, PALETTE
287 26 : aRecList.AppendRecord( CreateRecord( EXC_ID_FONTLIST ) );
288 26 : aRecList.AppendRecord( CreateRecord( EXC_ID_FORMATLIST ) );
289 26 : aRecList.AppendRecord( CreateRecord( EXC_ID_XFLIST ) );
290 26 : aRecList.AppendRecord( CreateRecord( EXC_ID_PALETTE ) );
291 :
292 26 : if( GetBiff() <= EXC_BIFF5 )
293 : {
294 : // Bundlesheet
295 0 : for( nC = 0 ; nC < nScTabCount ; nC++ )
296 0 : if( rTabInfo.IsExportTab( nC ) )
297 : {
298 0 : ExcBoundsheetList::RecordRefType xBoundsheet( new ExcBundlesheet( rR, nC ) );
299 0 : aRecList.AppendRecord( xBoundsheet );
300 0 : rBoundsheetList.AppendRecord( xBoundsheet );
301 : }
302 : }
303 : else
304 : {
305 : // Pivot Cache
306 26 : GetPivotTableManager().CreatePivotTables();
307 26 : aRecList.AppendRecord( GetPivotTableManager().CreatePivotCachesRecord() );
308 :
309 : // Change tracking
310 26 : if( rDoc.GetChangeTrack() )
311 : {
312 2 : rR.pUserBViewList = new XclExpUserBViewList( *rDoc.GetChangeTrack() );
313 2 : Add( rR.pUserBViewList );
314 : }
315 :
316 : // Natural Language Formulas Flag
317 26 : aRecList.AppendNewRecord( new XclExpBoolRecord( EXC_ID_USESELFS, GetDoc().GetDocOptions().IsLookUpColRowNames() ) );
318 :
319 : // Bundlesheet
320 76 : for( nC = 0 ; nC < nScTabCount ; nC++ )
321 50 : if( rTabInfo.IsExportTab( nC ) )
322 : {
323 50 : ExcBoundsheetList::RecordRefType xBoundsheet( new ExcBundlesheet8( rR, nC ) );
324 50 : aRecList.AppendRecord( xBoundsheet );
325 50 : rBoundsheetList.AppendRecord( xBoundsheet );
326 : }
327 :
328 26 : for( SCTAB nAdd = 0; nC < static_cast<SCTAB>(nCodenames) ; nC++, nAdd++ )
329 : {
330 0 : aTmpString = lcl_GetVbaTabName( nAdd );
331 0 : ExcBoundsheetList::RecordRefType xBoundsheet( new ExcBundlesheet8( aTmpString ) );
332 0 : aRecList.AppendRecord( xBoundsheet );
333 0 : rBoundsheetList.AppendRecord( xBoundsheet );
334 0 : }
335 :
336 : // COUNTRY - in BIFF8 in workbook globals
337 26 : Add( new XclExpCountry( GetRoot() ) );
338 :
339 : // link table: SUPBOOK, XCT, CRN, EXTERNNAME, EXTERNSHEET, NAME
340 26 : aRecList.AppendRecord( CreateRecord( EXC_ID_EXTERNSHEET ) );
341 26 : aRecList.AppendRecord( CreateRecord( EXC_ID_NAME ) );
342 :
343 26 : Add( new XclExpRecalcId );
344 :
345 : // MSODRAWINGGROUP per-document data
346 26 : aRecList.AppendRecord( GetObjectManager().CreateDrawingGroup() );
347 : // Shared string table: SST, EXTSST
348 26 : aRecList.AppendRecord( CreateRecord( EXC_ID_SST ) );
349 :
350 26 : Add( new XclExpBookExt );
351 : }
352 :
353 26 : Add( new ExcEof );
354 26 : }
355 :
356 38 : void ExcTable::FillAsHeaderXml( ExcBoundsheetList& rBoundsheetList )
357 : {
358 38 : InitializeGlobals();
359 :
360 38 : RootData& rR = GetOldRoot();
361 38 : ScDocument& rDoc = GetDoc();
362 38 : XclExpTabInfo& rTabInfo = GetTabInfo();
363 :
364 : SCTAB nC;
365 38 : OUString aTmpString;
366 38 : SCTAB nScTabCount = rTabInfo.GetScTabCount();
367 38 : sal_uInt16 nExcTabCount = rTabInfo.GetXclTabCount();
368 38 : sal_uInt16 nCodenames = static_cast< sal_uInt16 >( GetExtDocOptions().GetCodeNameCount() );
369 :
370 38 : rR.pTabId = new XclExpChTrTabId( std::max( nExcTabCount, nCodenames ) );
371 38 : Add( rR.pTabId );
372 :
373 : // first setup table names and contents
374 :
375 112 : for( nC = 0 ; nC < nScTabCount ; nC++ )
376 74 : if( rTabInfo.IsExportTab( nC ) )
377 : {
378 74 : rDoc.GetName( nC, aTmpString );
379 74 : *pTabNames << aTmpString;
380 : }
381 :
382 38 : Add( new XclExpXmlStartSingleElementRecord( XML_workbookPr ) );
383 38 : Add( new XclExpBoolRecord(0x0040, false, XML_backupFile ) ); // BACKUP
384 38 : Add( new XclExpBoolRecord(0x008D, false, XML_showObjects ) ); // HIDEOBJ
385 :
386 38 : Add( new Exc1904( rDoc ) );
387 : // OOXTODO: The following /workbook/workbookPr attributes are mapped
388 : // to various BIFF records that are not currently supported:
389 : //
390 : // XML_allowRefreshQuery: QSISTAG 802h: fEnableRefresh
391 : // XML_autoCompressPictures: COMPRESSPICTURES 89Bh: fAutoCompressPictures
392 : // XML_checkCompatibility: COMPAT12 88Ch: fNoCompatChk
393 : // XML_codeName: "Calc"
394 : // XML_defaultThemeVersion: ???
395 : // XML_filterPrivacy: BOOKEXT 863h: fFilterPrivacy
396 : // XML_hidePivotFieldList: BOOKBOOL DAh: fHidePivotTableFList
397 : // XML_promptedSolutions: BOOKEXT 863h: fBuggedUserAboutSolution
398 : // XML_publishItems: NAMEPUBLISH 893h: fPublished
399 : // XML_saveExternalLinkValues: BOOKBOOL DAh: fNoSavSupp
400 : // XML_showBorderUnselectedTables: BOOKBOOL DAh: fHideBorderUnsels
401 : // XML_showInkAnnotation: BOOKEXT 863h: fShowInkAnnotation
402 : // XML_showPivotChart: PIVOTCHARTBITS 859h: fGXHide??
403 : // XML_updateLinks: BOOKBOOL DAh: grbitUpdateLinks
404 38 : Add( new XclExpXmlEndSingleElementRecord() ); // XML_workbookPr
405 :
406 : // Formatting: FONT, FORMAT, XF, STYLE, PALETTE
407 38 : aRecList.AppendNewRecord( new XclExpXmlStyleSheet( *this ) );
408 :
409 : // Change tracking
410 38 : if( rDoc.GetChangeTrack() )
411 : {
412 2 : rR.pUserBViewList = new XclExpUserBViewList( *rDoc.GetChangeTrack() );
413 2 : Add( rR.pUserBViewList );
414 : }
415 :
416 38 : lcl_AddWorkbookProtection( aRecList, *this );
417 38 : lcl_AddBookviews( aRecList, *this );
418 :
419 : // Bundlesheet
420 38 : aRecList.AppendNewRecord( new XclExpXmlStartElementRecord( XML_sheets ) );
421 112 : for( nC = 0 ; nC < nScTabCount ; nC++ )
422 74 : if( rTabInfo.IsExportTab( nC ) )
423 : {
424 74 : ExcBoundsheetList::RecordRefType xBoundsheet( new ExcBundlesheet8( rR, nC ) );
425 74 : aRecList.AppendRecord( xBoundsheet );
426 74 : rBoundsheetList.AppendRecord( xBoundsheet );
427 : }
428 38 : aRecList.AppendNewRecord( new XclExpXmlEndElementRecord( XML_sheets ) );
429 :
430 38 : for( SCTAB nAdd = 0; nC < static_cast<SCTAB>(nCodenames) ; nC++, nAdd++ )
431 : {
432 0 : aTmpString = lcl_GetVbaTabName( nAdd );
433 0 : ExcBoundsheetList::RecordRefType xBoundsheet( new ExcBundlesheet8( aTmpString ) );
434 0 : aRecList.AppendRecord( xBoundsheet );
435 0 : rBoundsheetList.AppendRecord( xBoundsheet );
436 0 : }
437 :
438 : // link table: SUPBOOK, XCT, CRN, EXTERNNAME, EXTERNSHEET, NAME
439 38 : aRecList.AppendRecord( CreateRecord( EXC_ID_EXTERNSHEET ) );
440 38 : aRecList.AppendRecord( CreateRecord( EXC_ID_NAME ) );
441 :
442 38 : lcl_AddCalcPr( aRecList, *this );
443 :
444 : // MSODRAWINGGROUP per-document data
445 38 : aRecList.AppendRecord( GetObjectManager().CreateDrawingGroup() );
446 : // Shared string table: SST, EXTSST
447 38 : aRecList.AppendRecord( CreateRecord( EXC_ID_SST ) );
448 38 : }
449 :
450 50 : void ExcTable::FillAsTableBinary( SCTAB nCodeNameIdx )
451 : {
452 50 : InitializeTable( mnScTab );
453 :
454 50 : RootData& rR = GetOldRoot();
455 50 : XclBiff eBiff = GetBiff();
456 50 : ScDocument& rDoc = GetDoc();
457 :
458 : OSL_ENSURE( (mnScTab >= 0L) && (mnScTab <= MAXTAB), "-ExcTable::Table(): mnScTab - no ordinary table!" );
459 : OSL_ENSURE( nExcTab <= static_cast<sal_uInt16>(MAXTAB), "-ExcTable::Table(): nExcTab - no ordinary table!" );
460 :
461 : // create a new OBJ list for this sheet (may be used by notes, autofilter, data validation)
462 50 : if( eBiff == EXC_BIFF8 )
463 50 : GetObjectManager().StartSheet();
464 :
465 : // cell table: DEFROWHEIGHT, DEFCOLWIDTH, COLINFO, DIMENSIONS, ROW, cell records
466 50 : mxCellTable.reset( new XclExpCellTable( GetRoot() ) );
467 :
468 : //export cell notes
469 50 : std::vector<sc::NoteEntry> aNotes;
470 50 : rDoc.GetAllNoteEntries(aNotes);
471 68 : for (std::vector<sc::NoteEntry>::const_iterator it = aNotes.begin(), itEnd = aNotes.end(); it != itEnd; ++it)
472 : {
473 18 : if (it->maPos.Tab() != mnScTab)
474 12 : continue;
475 :
476 6 : mxNoteList->AppendNewRecord(new XclExpNote(GetRoot(), it->maPos, it->mpNote, OUString()));
477 : }
478 :
479 : // WSBOOL needs data from page settings, create it here, add it later
480 100 : boost::shared_ptr< XclExpPageSettings > xPageSett( new XclExpPageSettings( GetRoot() ) );
481 50 : bool bFitToPages = xPageSett->GetPageData().mbFitToPages;
482 :
483 50 : if( eBiff <= EXC_BIFF5 )
484 : {
485 0 : Add( new ExcBof );
486 0 : Add( new ExcDummy_02a );
487 : }
488 : else
489 : {
490 50 : Add( new ExcBof8 );
491 50 : lcl_AddCalcPr( aRecList, *this );
492 : }
493 :
494 : // GUTS (count & size of outline icons)
495 50 : aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_GUTS ) );
496 : // DEFROWHEIGHT, created by the cell table
497 50 : aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID2_DEFROWHEIGHT ) );
498 :
499 : // COUNTRY - in BIFF5/7 in every worksheet
500 50 : if( eBiff <= EXC_BIFF5 )
501 0 : Add( new XclExpCountry( GetRoot() ) );
502 :
503 50 : Add( new XclExpWsbool( bFitToPages ) );
504 :
505 : // page settings (SETUP and various other records)
506 50 : aRecList.AppendRecord( xPageSett );
507 :
508 50 : const ScTableProtection* pTabProtect = rDoc.GetTabProtection(mnScTab);
509 50 : if (pTabProtect && pTabProtect->isProtected())
510 : {
511 0 : Add( new XclExpProtection(true) );
512 0 : Add( new XclExpBoolRecord(0x00DD, pTabProtect->isOptionEnabled(ScTableProtection::SCENARIOS)) );
513 0 : Add( new XclExpBoolRecord(0x0063, pTabProtect->isOptionEnabled(ScTableProtection::OBJECTS)) );
514 0 : Add( new XclExpPassHash(pTabProtect->getPasswordHash(PASSHASH_XL)) );
515 : }
516 :
517 : // local link table: EXTERNCOUNT, EXTERNSHEET
518 50 : if( eBiff <= EXC_BIFF5 )
519 0 : aRecList.AppendRecord( CreateRecord( EXC_ID_EXTERNSHEET ) );
520 :
521 50 : if ( eBiff == EXC_BIFF8 )
522 50 : lcl_AddScenariosAndFilters( aRecList, GetRoot(), mnScTab );
523 :
524 : // cell table: DEFCOLWIDTH, COLINFO, DIMENSIONS, ROW, cell records
525 50 : aRecList.AppendRecord( mxCellTable );
526 :
527 : // MERGEDCELLS record, generated by the cell table
528 50 : aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_MERGEDCELLS ) );
529 : // label ranges
530 50 : if( eBiff == EXC_BIFF8 )
531 50 : Add( new XclExpLabelranges( GetRoot() ) );
532 : // data validation (DVAL and list of DV records), generated by the cell table
533 50 : aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_DVAL ) );
534 :
535 50 : if( eBiff == EXC_BIFF8 )
536 : {
537 : // all MSODRAWING and OBJ stuff of this sheet goes here
538 50 : aRecList.AppendRecord( GetObjectManager().ProcessDrawing( GetSdrPage( mnScTab ) ) );
539 : // pivot tables
540 50 : aRecList.AppendRecord( GetPivotTableManager().CreatePivotTablesRecord( mnScTab ) );
541 : }
542 :
543 : // list of NOTE records, generated by the cell table
544 50 : aRecList.AppendRecord( mxNoteList );
545 :
546 : // sheet view settings: WINDOW2, SCL, PANE, SELECTION
547 50 : aRecList.AppendNewRecord( new XclExpTabViewSettings( GetRoot(), mnScTab ) );
548 :
549 50 : if( eBiff == EXC_BIFF8 )
550 : {
551 : // sheet protection options
552 50 : Add( new XclExpSheetProtectOptions( GetRoot(), mnScTab ) );
553 :
554 : // enhanced protections if there are
555 50 : if (pTabProtect)
556 : {
557 0 : const ::std::vector<ScEnhancedProtection>& rProts( pTabProtect->getEnhancedProtection());
558 0 : for (::std::vector<ScEnhancedProtection>::const_iterator it( rProts.begin()), itEnd( rProts.end());
559 : it != itEnd; ++it)
560 : {
561 0 : Add( new XclExpSheetEnhancedProtection( GetRoot(), *it));
562 : }
563 : }
564 :
565 : // web queries
566 50 : Add( new XclExpWebQueryBuffer( GetRoot() ) );
567 :
568 : // conditional formats
569 50 : Add( new XclExpCondFormatBuffer( GetRoot(), XclExtLstRef() ) );
570 :
571 50 : if( HasVbaStorage() )
572 0 : if( nCodeNameIdx < GetExtDocOptions().GetCodeNameCount() )
573 0 : Add( new XclCodename( GetExtDocOptions().GetCodeName( nCodeNameIdx ) ) );
574 : }
575 :
576 : // list of HLINK records, generated by the cell table
577 50 : aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_HLINK ) );
578 :
579 : // change tracking
580 50 : if( rR.pUserBViewList )
581 : {
582 6 : XclExpUserBViewList::const_iterator iter;
583 18 : for ( iter = rR.pUserBViewList->begin(); iter != rR.pUserBViewList->end(); ++iter)
584 : {
585 12 : Add( new XclExpUsersViewBegin( (*iter)->GetGUID(), nExcTab ) );
586 12 : Add( new XclExpUsersViewEnd );
587 : }
588 : }
589 :
590 : // EOF
591 100 : Add( new ExcEof );
592 50 : }
593 :
594 74 : void ExcTable::FillAsTableXml()
595 : {
596 74 : InitializeTable( mnScTab );
597 :
598 74 : ScDocument& rDoc = GetDoc();
599 :
600 : OSL_ENSURE( (mnScTab >= 0L) && (mnScTab <= MAXTAB), "-ExcTable::Table(): mnScTab - no ordinary table!" );
601 : OSL_ENSURE( nExcTab <= static_cast<sal_uInt16>(MAXTAB), "-ExcTable::Table(): nExcTab - no ordinary table!" );
602 :
603 : // create a new OBJ list for this sheet (may be used by notes, autofilter, data validation)
604 74 : GetObjectManager().StartSheet();
605 :
606 : // cell table: DEFROWHEIGHT, DEFCOLWIDTH, COLINFO, DIMENSIONS, ROW, cell records
607 74 : mxCellTable.reset( new XclExpCellTable( GetRoot() ) );
608 :
609 : //export cell notes
610 74 : std::vector<sc::NoteEntry> aNotes;
611 74 : rDoc.GetAllNoteEntries(aNotes);
612 74 : for (std::vector<sc::NoteEntry>::const_iterator it = aNotes.begin(), itEnd = aNotes.end(); it != itEnd; ++it)
613 : {
614 0 : if (it->maPos.Tab() != mnScTab)
615 0 : continue;
616 :
617 0 : mxNoteList->AppendNewRecord(new XclExpNote(GetRoot(), it->maPos, it->mpNote, OUString()));
618 : }
619 :
620 : // WSBOOL needs data from page settings, create it here, add it later
621 148 : boost::shared_ptr< XclExpPageSettings > xPageSett( new XclExpPageSettings( GetRoot() ) );
622 148 : XclExtLstRef xExtLst( new XclExtLst( GetRoot() ) );
623 74 : bool bFitToPages = xPageSett->GetPageData().mbFitToPages;
624 :
625 74 : Color aTabColor = GetRoot().GetDoc().GetTabBgColor(mnScTab);
626 74 : Add(new XclExpXmlSheetPr(bFitToPages, mnScTab, aTabColor, &GetFilterManager()));
627 :
628 : // GUTS (count & size of outline icons)
629 74 : aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_GUTS ) );
630 : // DEFROWHEIGHT, created by the cell table
631 74 : aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID2_DEFROWHEIGHT ) );
632 :
633 74 : aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID3_DIMENSIONS ) );
634 :
635 : // sheet view settings: WINDOW2, SCL, PANE, SELECTION
636 74 : aRecList.AppendNewRecord( new XclExpTabViewSettings( GetRoot(), mnScTab ) );
637 :
638 : // cell table: DEFCOLWIDTH, COLINFO, DIMENSIONS, ROW, cell records
639 74 : aRecList.AppendRecord( mxCellTable );
640 :
641 : // list of NOTE records, generated by the cell table
642 : // not in the worksheet file
643 74 : if( mxNoteList != 0 && !mxNoteList->IsEmpty() )
644 0 : aRecList.AppendNewRecord( new XclExpComments( mnScTab, *mxNoteList ) );
645 :
646 74 : const ScTableProtection* pTabProtect = rDoc.GetTabProtection(mnScTab);
647 74 : if (pTabProtect && pTabProtect->isProtected())
648 2 : Add( new XclExpSheetProtection(true, mnScTab) );
649 :
650 74 : lcl_AddScenariosAndFilters( aRecList, GetRoot(), mnScTab );
651 :
652 : // MERGEDCELLS record, generated by the cell table
653 74 : aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_MERGEDCELLS ) );
654 :
655 : // conditional formats
656 74 : Add( new XclExpCondFormatBuffer( GetRoot(), xExtLst ) );
657 :
658 : // data validation (DVAL and list of DV records), generated by the cell table
659 74 : aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_DVAL ) );
660 :
661 : // list of HLINK records, generated by the cell table
662 148 : XclExpRecordRef xHyperlinks = mxCellTable->CreateRecord( EXC_ID_HLINK );
663 74 : XclExpHyperlinkList* xHyperlinkList = dynamic_cast<XclExpHyperlinkList*>(xHyperlinks.get());
664 74 : if( xHyperlinkList != NULL && !xHyperlinkList->IsEmpty() )
665 : {
666 0 : aRecList.AppendNewRecord( new XclExpXmlStartElementRecord( XML_hyperlinks ) );
667 0 : aRecList.AppendRecord( xHyperlinks );
668 0 : aRecList.AppendNewRecord( new XclExpXmlEndElementRecord( XML_hyperlinks ) );
669 : }
670 :
671 74 : aRecList.AppendRecord( xPageSett );
672 :
673 : // all MSODRAWING and OBJ stuff of this sheet goes here
674 74 : aRecList.AppendRecord( GetObjectManager().ProcessDrawing( GetSdrPage( mnScTab ) ) );
675 :
676 148 : aRecList.AppendRecord( xExtLst );
677 74 : }
678 :
679 0 : void ExcTable::FillAsEmptyTable( SCTAB nCodeNameIdx )
680 : {
681 0 : InitializeTable( mnScTab );
682 :
683 0 : if( HasVbaStorage() && (nCodeNameIdx < GetExtDocOptions().GetCodeNameCount()) )
684 : {
685 0 : if( GetBiff() <= EXC_BIFF5 )
686 : {
687 0 : Add( new ExcBof );
688 : }
689 : else
690 : {
691 0 : Add( new ExcBof8 );
692 0 : Add( new XclCodename( GetExtDocOptions().GetCodeName( nCodeNameIdx ) ) );
693 : }
694 : // sheet view settings: WINDOW2, SCL, PANE, SELECTION
695 0 : aRecList.AppendNewRecord( new XclExpTabViewSettings( GetRoot(), mnScTab ) );
696 0 : Add( new ExcEof );
697 : }
698 0 : }
699 :
700 76 : void ExcTable::Write( XclExpStream& rStrm )
701 : {
702 76 : SetCurrScTab( mnScTab );
703 76 : if( mxCellTable.get() )
704 50 : mxCellTable->Finalize();
705 76 : aRecList.Save( rStrm );
706 76 : }
707 :
708 112 : void ExcTable::WriteXml( XclExpXmlStream& rStrm )
709 : {
710 112 : if (!GetTabInfo().IsExportTab(mnScTab))
711 : {
712 : // header export.
713 38 : SetCurrScTab(mnScTab);
714 38 : if (mxCellTable)
715 0 : mxCellTable->Finalize();
716 38 : aRecList.SaveXml(rStrm);
717 :
718 150 : return;
719 : }
720 :
721 : // worksheet export
722 74 : OUString sSheetName = XclXmlUtils::GetStreamName( "xl/", "worksheets/sheet", mnScTab+1 );
723 :
724 148 : sax_fastparser::FSHelperPtr pWorksheet = rStrm.GetStreamForPath( sSheetName );
725 :
726 74 : rStrm.PushStream( pWorksheet );
727 :
728 : pWorksheet->startElement( XML_worksheet,
729 : XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
730 : FSNS( XML_xmlns, XML_r ), "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
731 74 : FSEND );
732 :
733 74 : SetCurrScTab( mnScTab );
734 74 : if (mxCellTable)
735 74 : mxCellTable->Finalize();
736 74 : aRecList.SaveXml( rStrm );
737 :
738 74 : XclExpXmlPivotTables* pPT = GetXmlPivotTableManager().GetTablesBySheet(mnScTab);
739 74 : if (pPT)
740 4 : pPT->SaveXml(rStrm);
741 :
742 74 : rStrm.GetCurrentStream()->endElement( XML_worksheet );
743 148 : rStrm.PopStream();
744 : }
745 :
746 64 : ExcDocument::ExcDocument( const XclExpRoot& rRoot ) :
747 : XclExpRoot( rRoot ),
748 : aHeader( rRoot ),
749 64 : pExpChangeTrack( NULL )
750 : {
751 64 : }
752 :
753 154 : ExcDocument::~ExcDocument()
754 : {
755 64 : maTableList.RemoveAllRecords(); //! for the following assertion
756 64 : delete pExpChangeTrack;
757 90 : }
758 :
759 64 : void ExcDocument::ReadDoc( void )
760 : {
761 64 : InitializeConvert();
762 :
763 64 : if (GetOutput() == EXC_OUTPUT_BINARY)
764 26 : aHeader.FillAsHeaderBinary(maBoundsheetList);
765 : else
766 : {
767 38 : aHeader.FillAsHeaderXml(maBoundsheetList);
768 38 : GetXmlPivotTableManager().Initialize();
769 : }
770 :
771 64 : SCTAB nScTab = 0, nScTabCount = GetTabInfo().GetScTabCount();
772 64 : SCTAB nCodeNameIdx = 0, nCodeNameCount = GetExtDocOptions().GetCodeNameCount();
773 :
774 188 : for( ; nScTab < nScTabCount; ++nScTab )
775 : {
776 124 : if( GetTabInfo().IsExportTab( nScTab ) )
777 : {
778 124 : ExcTableList::RecordRefType xTab( new ExcTable( GetRoot(), nScTab ) );
779 124 : maTableList.AppendRecord( xTab );
780 124 : if (GetOutput() == EXC_OUTPUT_BINARY)
781 50 : xTab->FillAsTableBinary(nCodeNameIdx);
782 : else
783 74 : xTab->FillAsTableXml();
784 :
785 124 : ++nCodeNameIdx;
786 : }
787 : }
788 64 : for( ; nCodeNameIdx < nCodeNameCount; ++nScTab, ++nCodeNameIdx )
789 : {
790 0 : ExcTableList::RecordRefType xTab( new ExcTable( GetRoot(), nScTab ) );
791 0 : maTableList.AppendRecord( xTab );
792 0 : xTab->FillAsEmptyTable( nCodeNameIdx );
793 0 : }
794 :
795 64 : if ( GetBiff() == EXC_BIFF8 )
796 : {
797 : // complete temporary Escher stream
798 64 : GetObjectManager().EndDocument();
799 :
800 : // change tracking
801 64 : if ( GetDoc().GetChangeTrack() )
802 4 : pExpChangeTrack = new XclExpChangeTrack( GetRoot() );
803 : }
804 64 : }
805 :
806 26 : void ExcDocument::Write( SvStream& rSvStrm )
807 : {
808 26 : if( !maTableList.IsEmpty() )
809 : {
810 26 : InitializeSave();
811 :
812 26 : XclExpStream aXclStrm( rSvStrm, GetRoot() );
813 :
814 26 : aHeader.Write( aXclStrm );
815 :
816 : OSL_ENSURE( maTableList.GetSize() == maBoundsheetList.GetSize(),
817 : "ExcDocument::Write - different number of sheets and BOUNDSHEET records" );
818 :
819 76 : for( size_t nTab = 0, nTabCount = maTableList.GetSize(); nTab < nTabCount; ++nTab )
820 : {
821 : // set current stream position in BOUNDSHEET record
822 50 : ExcBoundsheetRef xBoundsheet = maBoundsheetList.GetRecord( nTab );
823 50 : if( xBoundsheet.get() )
824 50 : xBoundsheet->SetStreamPos( aXclStrm.GetSvStreamPos() );
825 : // write the table
826 50 : maTableList.GetRecord( nTab )->Write( aXclStrm );
827 50 : }
828 :
829 : // write the table stream positions into the BOUNDSHEET records
830 76 : for( size_t nBSheet = 0, nBSheetCount = maBoundsheetList.GetSize(); nBSheet < nBSheetCount; ++nBSheet )
831 76 : maBoundsheetList.GetRecord( nBSheet )->UpdateStreamPos( aXclStrm );
832 : }
833 26 : if( pExpChangeTrack )
834 2 : pExpChangeTrack->Write();
835 26 : }
836 :
837 38 : void ExcDocument::WriteXml( XclExpXmlStream& rStrm )
838 : {
839 38 : SfxObjectShell* pDocShell = GetDocShell();
840 :
841 : using namespace ::com::sun::star;
842 38 : uno::Reference<document::XDocumentPropertiesSupplier> xDPS( pDocShell->GetModel(), uno::UNO_QUERY_THROW );
843 76 : uno::Reference<document::XDocumentProperties> xDocProps = xDPS->getDocumentProperties();
844 :
845 38 : rStrm.exportDocumentProperties( xDocProps );
846 :
847 38 : sax_fastparser::FSHelperPtr& rWorkbook = rStrm.GetCurrentStream();
848 : rWorkbook->startElement( XML_workbook,
849 : XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
850 : FSNS(XML_xmlns, XML_r), "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
851 38 : FSEND );
852 : rWorkbook->singleElement( XML_fileVersion,
853 : XML_appName, "Calc",
854 : // OOXTODO: XML_codeName
855 : // OOXTODO: XML_lastEdited
856 : // OOXTODO: XML_lowestEdited
857 : // OOXTODO: XML_rupBuild
858 38 : FSEND );
859 :
860 38 : if( !maTableList.IsEmpty() )
861 : {
862 38 : InitializeSave();
863 :
864 38 : aHeader.WriteXml( rStrm );
865 :
866 112 : for( size_t nTab = 0, nTabCount = maTableList.GetSize(); nTab < nTabCount; ++nTab )
867 : {
868 : // write the table
869 74 : maTableList.GetRecord( nTab )->WriteXml( rStrm );
870 : }
871 : }
872 :
873 38 : if( pExpChangeTrack )
874 2 : pExpChangeTrack->WriteXml( rStrm );
875 :
876 38 : XclExpXmlPivotCaches& rCaches = GetXmlPivotTableManager().GetCaches();
877 38 : if (rCaches.HasCaches())
878 4 : rCaches.SaveXml(rStrm);
879 :
880 38 : rWorkbook->endElement( XML_workbook );
881 76 : rWorkbook.reset();
882 86 : }
883 :
884 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|