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 "workbookfragment.hxx"
21 :
22 : #include <com/sun/star/table/CellAddress.hpp>
23 : #include <oox/core/filterbase.hxx>
24 : #include <oox/drawingml/themefragmenthandler.hxx>
25 : #include <oox/helper/attributelist.hxx>
26 : #include <oox/helper/progressbar.hxx>
27 : #include <oox/helper/propertyset.hxx>
28 : #include <oox/ole/olestorage.hxx>
29 :
30 : #include "biffinputstream.hxx"
31 : #include "chartsheetfragment.hxx"
32 : #include "connectionsfragment.hxx"
33 : #include "externallinkbuffer.hxx"
34 : #include "externallinkfragment.hxx"
35 : #include "formulabuffer.hxx"
36 : #include "pivotcachebuffer.hxx"
37 : #include "sharedstringsbuffer.hxx"
38 : #include "sharedstringsfragment.hxx"
39 : #include "revisionfragment.hxx"
40 : #include "stylesfragment.hxx"
41 : #include "tablebuffer.hxx"
42 : #include "themebuffer.hxx"
43 : #include "viewsettings.hxx"
44 : #include "workbooksettings.hxx"
45 : #include "worksheetbuffer.hxx"
46 : #include "worksheethelper.hxx"
47 : #include "worksheetfragment.hxx"
48 : #include "sheetdatacontext.hxx"
49 : #include "officecfg/Office/Common.hxx"
50 :
51 : #include "document.hxx"
52 : #include "docsh.hxx"
53 : #include "calcconfig.hxx"
54 :
55 : #include <vcl/svapp.hxx>
56 : #include <vcl/timer.hxx>
57 :
58 : #include <oox/core/fastparser.hxx>
59 : #include <salhelper/thread.hxx>
60 : #include <comphelper/threadpool.hxx>
61 : #include <osl/conditn.hxx>
62 :
63 : #include <algorithm>
64 : #include <queue>
65 : #include <thread>
66 : #include <boost/scoped_ptr.hpp>
67 :
68 : #include <oox/ole/vbaproject.hxx>
69 :
70 : namespace oox {
71 : namespace xls {
72 :
73 : using namespace ::com::sun::star::io;
74 : using namespace ::com::sun::star::table;
75 : using namespace ::com::sun::star::uno;
76 : using namespace ::com::sun::star::sheet;
77 : using namespace ::oox::core;
78 :
79 : using ::oox::drawingml::ThemeFragmentHandler;
80 :
81 : namespace {
82 :
83 : const double PROGRESS_LENGTH_GLOBALS = 0.1; /// 10% of progress bar for globals import.
84 :
85 : } // namespace
86 :
87 128 : WorkbookFragment::WorkbookFragment( const WorkbookHelper& rHelper, const OUString& rFragmentPath ) :
88 128 : WorkbookFragmentBase( rHelper, rFragmentPath )
89 : {
90 128 : }
91 :
92 1288 : ContextHandlerRef WorkbookFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
93 : {
94 1288 : switch( getCurrentElement() )
95 : {
96 : case XML_ROOT_CONTEXT:
97 128 : if( nElement == XLS_TOKEN( workbook ) ) return this;
98 0 : break;
99 :
100 : case XLS_TOKEN( workbook ):
101 740 : switch( nElement )
102 : {
103 : case XLS_TOKEN( sheets ):
104 : case XLS_TOKEN( bookViews ):
105 : case XLS_TOKEN( externalReferences ):
106 : case XLS_TOKEN( definedNames ):
107 272 : case XLS_TOKEN( pivotCaches ): return this;
108 :
109 0 : case XLS_TOKEN( fileSharing ): getWorkbookSettings().importFileSharing( rAttribs ); break;
110 128 : case XLS_TOKEN( workbookPr ): getWorkbookSettings().importWorkbookPr( rAttribs ); break;
111 128 : case XLS_TOKEN( calcPr ): getWorkbookSettings().importCalcPr( rAttribs ); break;
112 0 : case XLS_TOKEN( oleSize ): getViewSettings().importOleSize( rAttribs ); break;
113 : }
114 468 : break;
115 :
116 : case XLS_TOKEN( sheets ):
117 260 : if( nElement == XLS_TOKEN( sheet ) ) getWorksheets().importSheet( rAttribs );
118 260 : break;
119 : case XLS_TOKEN( bookViews ):
120 128 : if( nElement == XLS_TOKEN( workbookView ) ) getViewSettings().importWorkbookView( rAttribs );
121 128 : break;
122 : case XLS_TOKEN( externalReferences ):
123 2 : if( nElement == XLS_TOKEN( externalReference ) ) importExternalReference( rAttribs );
124 2 : break;
125 : case XLS_TOKEN( definedNames ):
126 22 : if( nElement == XLS_TOKEN( definedName ) ) { importDefinedName( rAttribs ); return this; } // collect formula
127 0 : break;
128 : case XLS_TOKEN( pivotCaches ):
129 8 : if( nElement == XLS_TOKEN( pivotCache ) ) importPivotCache( rAttribs );
130 8 : break;
131 : }
132 866 : return 0;
133 : }
134 :
135 22 : void WorkbookFragment::onCharacters( const OUString& rChars )
136 : {
137 22 : if( isCurrentElement( XLS_TOKEN( definedName ) ) && mxCurrName.get() )
138 22 : mxCurrName->setFormula( rChars );
139 22 : }
140 :
141 0 : ContextHandlerRef WorkbookFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
142 : {
143 0 : switch( getCurrentElement() )
144 : {
145 : case XML_ROOT_CONTEXT:
146 0 : if( nRecId == BIFF12_ID_WORKBOOK ) return this;
147 0 : break;
148 :
149 : case BIFF12_ID_WORKBOOK:
150 0 : switch( nRecId )
151 : {
152 : case BIFF12_ID_SHEETS:
153 : case BIFF12_ID_BOOKVIEWS:
154 : case BIFF12_ID_EXTERNALREFS:
155 0 : case BIFF12_ID_PIVOTCACHES: return this;
156 :
157 0 : case BIFF12_ID_FILESHARING: getWorkbookSettings().importFileSharing( rStrm ); break;
158 0 : case BIFF12_ID_WORKBOOKPR: getWorkbookSettings().importWorkbookPr( rStrm ); break;
159 0 : case BIFF12_ID_CALCPR: getWorkbookSettings().importCalcPr( rStrm ); break;
160 0 : case BIFF12_ID_OLESIZE: getViewSettings().importOleSize( rStrm ); break;
161 0 : case BIFF12_ID_DEFINEDNAME: getDefinedNames().importDefinedName( rStrm ); break;
162 : }
163 0 : break;
164 :
165 : case BIFF12_ID_SHEETS:
166 0 : if( nRecId == BIFF12_ID_SHEET ) getWorksheets().importSheet( rStrm );
167 0 : break;
168 : case BIFF12_ID_BOOKVIEWS:
169 0 : if( nRecId == BIFF12_ID_WORKBOOKVIEW ) getViewSettings().importWorkbookView( rStrm );
170 0 : break;
171 :
172 : case BIFF12_ID_EXTERNALREFS:
173 0 : switch( nRecId )
174 : {
175 0 : case BIFF12_ID_EXTERNALREF: importExternalRef( rStrm ); break;
176 0 : case BIFF12_ID_EXTERNALSELF: getExternalLinks().importExternalSelf( rStrm ); break;
177 0 : case BIFF12_ID_EXTERNALSAME: getExternalLinks().importExternalSame( rStrm ); break;
178 0 : case BIFF12_ID_EXTERNALADDIN: getExternalLinks().importExternalAddin( rStrm ); break;
179 0 : case BIFF12_ID_EXTERNALSHEETS: getExternalLinks().importExternalSheets( rStrm ); break;
180 : }
181 0 : break;
182 :
183 : case BIFF12_ID_PIVOTCACHES:
184 0 : if( nRecId == BIFF12_ID_PIVOTCACHE ) importPivotCache( rStrm );
185 : }
186 0 : return 0;
187 : }
188 :
189 0 : const RecordInfo* WorkbookFragment::getRecordInfos() const
190 : {
191 : static const RecordInfo spRecInfos[] =
192 : {
193 : { BIFF12_ID_BOOKVIEWS, BIFF12_ID_BOOKVIEWS + 1 },
194 : { BIFF12_ID_EXTERNALREFS, BIFF12_ID_EXTERNALREFS + 1 },
195 : { BIFF12_ID_FUNCTIONGROUPS, BIFF12_ID_FUNCTIONGROUPS + 2 },
196 : { BIFF12_ID_PIVOTCACHE, BIFF12_ID_PIVOTCACHE + 1 },
197 : { BIFF12_ID_PIVOTCACHES, BIFF12_ID_PIVOTCACHES + 1 },
198 : { BIFF12_ID_SHEETS, BIFF12_ID_SHEETS + 1 },
199 : { BIFF12_ID_WORKBOOK, BIFF12_ID_WORKBOOK + 1 },
200 : { -1, -1 }
201 : };
202 0 : return spRecInfos;
203 : }
204 :
205 : namespace {
206 :
207 : typedef std::pair<WorksheetGlobalsRef, FragmentHandlerRef> SheetFragmentHandler;
208 : typedef std::vector<SheetFragmentHandler> SheetFragmentVector;
209 :
210 520 : class WorkerThread : public comphelper::ThreadTask
211 : {
212 : sal_Int32 &mrSheetsLeft;
213 : WorkbookFragment& mrWorkbookHandler;
214 : rtl::Reference<FragmentHandler> mxHandler;
215 :
216 : public:
217 260 : WorkerThread( WorkbookFragment& rWorkbookHandler,
218 : const rtl::Reference<FragmentHandler>& xHandler,
219 : sal_Int32 &rSheetsLeft ) :
220 : mrSheetsLeft( rSheetsLeft ),
221 : mrWorkbookHandler( rWorkbookHandler ),
222 260 : mxHandler( xHandler )
223 : {
224 260 : }
225 :
226 260 : virtual void doWork() SAL_OVERRIDE
227 : {
228 : // We hold the solar mutex in all threads except for
229 : // the small safe section of the inner loop in
230 : // sheetdatacontext.cxx
231 : SAL_INFO( "sc.filter", "start wait on solar\n" );
232 260 : SolarMutexGuard maGuard;
233 : SAL_INFO( "sc.filter", "got solar\n" );
234 :
235 : boost::scoped_ptr<oox::core::FastParser> xParser(
236 520 : mrWorkbookHandler.getOoxFilter().createParser() );
237 :
238 : SAL_INFO( "sc.filter", "start import\n" );
239 260 : mrWorkbookHandler.importOoxFragment( mxHandler, *xParser );
240 : SAL_INFO( "sc.filter", "end import, release solar\n" );
241 260 : mrSheetsLeft--;
242 : assert( mrSheetsLeft >= 0 );
243 260 : if( mrSheetsLeft == 0 )
244 388 : Application::EndYield();
245 260 : }
246 : };
247 :
248 : class ProgressBarTimer : Timer
249 : {
250 : // FIXME: really we should unify all sheet loading
251 : // progress reporting into something pleasant.
252 : class ProgressWrapper : public ISegmentProgressBar
253 : {
254 : double mfPosition;
255 : ISegmentProgressBarRef mxWrapped;
256 : public:
257 260 : ProgressWrapper(const ISegmentProgressBarRef &xRef)
258 : : mfPosition(0.0)
259 260 : , mxWrapped(xRef)
260 : {
261 260 : }
262 520 : virtual ~ProgressWrapper() {}
263 : // IProgressBar
264 0 : virtual double getPosition() const SAL_OVERRIDE { return mfPosition; }
265 2406 : virtual void setPosition( double fPosition ) SAL_OVERRIDE { mfPosition = fPosition; }
266 : // ISegmentProgressBar
267 0 : virtual double getFreeLength() const SAL_OVERRIDE { return 0.0; }
268 0 : virtual ISegmentProgressBarRef createSegment( double /* fLength */ ) SAL_OVERRIDE
269 : {
270 0 : return ISegmentProgressBarRef();
271 : }
272 0 : void UpdateBar()
273 : {
274 0 : mxWrapped->setPosition( mfPosition );
275 0 : }
276 : };
277 : std::vector< ISegmentProgressBarRef > aSegments;
278 : public:
279 128 : ProgressBarTimer() : Timer()
280 : {
281 128 : SetTimeout( 500 );
282 128 : }
283 128 : virtual ~ProgressBarTimer()
284 256 : {
285 128 : aSegments.clear();
286 128 : }
287 260 : ISegmentProgressBarRef wrapProgress( const ISegmentProgressBarRef &xProgress )
288 : {
289 260 : aSegments.push_back( ISegmentProgressBarRef( new ProgressWrapper( xProgress ) ) );
290 260 : return aSegments.back();
291 : }
292 0 : virtual void Timeout() SAL_OVERRIDE
293 : {
294 0 : for( size_t i = 0; i < aSegments.size(); i++)
295 0 : static_cast< ProgressWrapper *>( aSegments[ i ].get() )->UpdateBar();
296 0 : }
297 : };
298 :
299 128 : void importSheetFragments( WorkbookFragment& rWorkbookHandler, SheetFragmentVector& rSheets )
300 : {
301 128 : sal_Int32 nThreads = std::min( rSheets.size(), (size_t) std::max(std::thread::hardware_concurrency(), 1U) );
302 :
303 128 : Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
304 :
305 : const char *pEnv;
306 128 : if( ( pEnv = getenv( "SC_IMPORT_THREADS" ) ) )
307 0 : nThreads = rtl_str_toInt32( pEnv, 10 );
308 :
309 128 : if( nThreads != 0 )
310 : {
311 : // test sequential read in this mode
312 128 : if( nThreads < 0)
313 0 : nThreads = 0;
314 128 : comphelper::ThreadPool aPool( nThreads );
315 :
316 128 : sal_Int32 nSheetsLeft = 0;
317 256 : ProgressBarTimer aProgressUpdater;
318 128 : SheetFragmentVector::iterator it = rSheets.begin(), itEnd = rSheets.end();
319 388 : for( ; it != itEnd; ++it )
320 : {
321 : // getting at the WorksheetGlobals is rather unpleasant
322 260 : IWorksheetProgress *pProgress = WorksheetHelper::getWorksheetInterface( it->first );
323 : pProgress->setCustomRowProgress(
324 : aProgressUpdater.wrapProgress(
325 260 : pProgress->getRowProgress() ) );
326 260 : aPool.pushTask( new WorkerThread( rWorkbookHandler, it->second,
327 260 : /* ref */ nSheetsLeft ) );
328 260 : nSheetsLeft++;
329 : }
330 :
331 : // coverity[infinite_loop]
332 635 : while( nSheetsLeft > 0)
333 : {
334 : // This is a much more controlled re-enterancy hazard than
335 : // allowing a yield deeper inside the filter code for progress
336 : // bar updating.
337 379 : Application::Yield();
338 : }
339 256 : aPool.waitUntilEmpty();
340 :
341 : // threads joined in ThreadPool destructor
342 : }
343 : else // single threaded iteration
344 : {
345 0 : SheetFragmentVector::iterator it = rSheets.begin(), itEnd = rSheets.end();
346 0 : for( ; it != itEnd; ++it )
347 0 : rWorkbookHandler.importOoxFragment( it->second );
348 128 : }
349 128 : }
350 :
351 : }
352 :
353 128 : void WorkbookFragment::finalizeImport()
354 : {
355 128 : ISegmentProgressBarRef xGlobalSegment = getProgressBar().createSegment( PROGRESS_LENGTH_GLOBALS );
356 :
357 : // read the theme substream
358 256 : OUString aThemeFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( "theme" );
359 128 : if( !aThemeFragmentPath.isEmpty() )
360 68 : importOoxFragment( new ThemeFragmentHandler( getFilter(), aThemeFragmentPath, getTheme() ) );
361 128 : xGlobalSegment->setPosition( 0.25 );
362 :
363 : // read the styles substream (requires finalized theme buffer)
364 256 : OUString aStylesFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( "styles" );
365 128 : if( !aStylesFragmentPath.isEmpty() )
366 128 : importOoxFragment( new StylesFragment( *this, aStylesFragmentPath ) );
367 128 : xGlobalSegment->setPosition( 0.5 );
368 :
369 : // read the shared string table substream (requires finalized styles buffer)
370 256 : OUString aSstFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( "sharedStrings" );
371 128 : if( !aSstFragmentPath.isEmpty() )
372 90 : if (!importOoxFragment( new SharedStringsFragment( *this, aSstFragmentPath ) ))
373 0 : importOoxFragment(new SharedStringsFragment(*this, aSstFragmentPath.replaceFirst("sharedStrings","SharedStrings")));
374 128 : xGlobalSegment->setPosition( 0.75 );
375 :
376 : // read the connections substream
377 256 : OUString aConnFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( "connections" );
378 128 : if( !aConnFragmentPath.isEmpty() )
379 0 : importOoxFragment( new ConnectionsFragment( *this, aConnFragmentPath ) );
380 128 : xGlobalSegment->setPosition( 1.0 );
381 :
382 : /* Create fragments for all sheets, before importing them. Needed to do
383 : some preprocessing in the fragment constructors, e.g. loading the table
384 : fragments for all sheets that are needed before the cell formulas are
385 : loaded. Additionally, the instances of the WorkbookGlobals structures
386 : have to be stored for every sheet. */
387 256 : SheetFragmentVector aSheetFragments;
388 256 : std::vector<WorksheetHelper*> maHelpers;
389 128 : WorksheetBuffer& rWorksheets = getWorksheets();
390 128 : sal_Int32 nWorksheetCount = rWorksheets.getWorksheetCount();
391 388 : for( sal_Int32 nWorksheet = 0; nWorksheet < nWorksheetCount; ++nWorksheet )
392 : {
393 260 : sal_Int16 nCalcSheet = rWorksheets.getCalcSheetIndex( nWorksheet );
394 260 : const Relation* pRelation = getRelations().getRelationFromRelId( rWorksheets.getWorksheetRelId( nWorksheet ) );
395 260 : if( (nCalcSheet >= 0) && pRelation )
396 : {
397 : // get fragment path of the sheet
398 260 : OUString aFragmentPath = getFragmentPathFromRelation( *pRelation );
399 : OSL_ENSURE( !aFragmentPath.isEmpty(), "WorkbookFragment::finalizeImport - cannot access sheet fragment" );
400 260 : if( !aFragmentPath.isEmpty() )
401 : {
402 : // leave space for formula processing ( calcuate the segments as
403 : // if there is an extra sheet )
404 260 : double fSegmentLength = getProgressBar().getFreeLength() / (nWorksheetCount - ( nWorksheet - 1) );
405 260 : ISegmentProgressBarRef xSheetSegment = getProgressBar().createSegment( fSegmentLength );
406 :
407 : // get the sheet type according to the relations type
408 260 : WorksheetType eSheetType = SHEETTYPE_EMPTYSHEET;
409 264 : if( pRelation->maType == CREATE_OFFICEDOC_RELATION_TYPE( "worksheet" ) ||
410 4 : pRelation->maType == CREATE_OFFICEDOC_RELATION_TYPE_STRICT( "worksheet" ))
411 260 : eSheetType = SHEETTYPE_WORKSHEET;
412 0 : else if( pRelation->maType == CREATE_OFFICEDOC_RELATION_TYPE( "chartsheet" ) ||
413 0 : pRelation->maType == CREATE_OFFICEDOC_RELATION_TYPE_STRICT( "chartsheet" ))
414 0 : eSheetType = SHEETTYPE_CHARTSHEET;
415 0 : else if( (pRelation->maType == CREATE_MSOFFICE_RELATION_TYPE( "xlMacrosheet" )) ||
416 0 : (pRelation->maType == CREATE_MSOFFICE_RELATION_TYPE( "xlIntlMacrosheet" )) )
417 0 : eSheetType = SHEETTYPE_MACROSHEET;
418 0 : else if( pRelation->maType == CREATE_OFFICEDOC_RELATION_TYPE( "dialogsheet" ) ||
419 0 : pRelation->maType == CREATE_OFFICEDOC_RELATION_TYPE_STRICT(" dialogsheet" ))
420 0 : eSheetType = SHEETTYPE_DIALOGSHEET;
421 : OSL_ENSURE( eSheetType != SHEETTYPE_EMPTYSHEET, "WorkbookFragment::finalizeImport - unknown sheet type" );
422 260 : if( eSheetType != SHEETTYPE_EMPTYSHEET )
423 : {
424 : // create the WorksheetGlobals object
425 260 : WorksheetGlobalsRef xSheetGlob = WorksheetHelper::constructGlobals( *this, xSheetSegment, eSheetType, nCalcSheet );
426 : OSL_ENSURE( xSheetGlob.get(), "WorkbookFragment::finalizeImport - missing sheet in document" );
427 260 : if( xSheetGlob.get() )
428 : {
429 : // create the sheet fragment handler
430 260 : ::rtl::Reference< WorksheetFragmentBase > xFragment;
431 260 : switch( eSheetType )
432 : {
433 : case SHEETTYPE_WORKSHEET:
434 : case SHEETTYPE_MACROSHEET:
435 : case SHEETTYPE_DIALOGSHEET:
436 260 : xFragment.set( new WorksheetFragment( *xSheetGlob, aFragmentPath ) );
437 260 : break;
438 : case SHEETTYPE_CHARTSHEET:
439 0 : xFragment.set( new ChartsheetFragment( *xSheetGlob, aFragmentPath ) );
440 0 : break;
441 : case SHEETTYPE_EMPTYSHEET:
442 : case SHEETTYPE_MODULESHEET:
443 0 : break;
444 : }
445 :
446 : // insert the fragment into the map
447 260 : if( xFragment.is() )
448 : {
449 260 : aSheetFragments.push_back( SheetFragmentHandler( xSheetGlob, xFragment.get() ) );
450 260 : maHelpers.push_back(xFragment.get());
451 260 : }
452 260 : }
453 260 : }
454 260 : }
455 : }
456 : }
457 :
458 : // setup structure sizes for the number of sheets
459 128 : getFormulaBuffer().SetSheetCount( aSheetFragments.size() );
460 :
461 : // create all defined names and database ranges
462 128 : getDefinedNames().finalizeImport();
463 128 : getTables().finalizeImport();
464 : // open the VBA project storage
465 128 : OUString aVbaFragmentPath = getFragmentPathFromFirstType( CREATE_MSOFFICE_RELATION_TYPE( "vbaProject" ) );
466 128 : if( !aVbaFragmentPath.isEmpty() )
467 : {
468 2 : Reference< XInputStream > xInStrm = getBaseFilter().openInputStream( aVbaFragmentPath );
469 2 : if( xInStrm.is() )
470 : {
471 2 : StorageRef xPrjStrg( new ::oox::ole::OleStorage( getBaseFilter().getComponentContext(), xInStrm, false ) );
472 2 : setVbaProjectStorage( xPrjStrg );
473 2 : getBaseFilter().getVbaProject().readVbaModules( *xPrjStrg );
474 2 : }
475 : }
476 :
477 : // load all worksheets
478 128 : importSheetFragments(*this, aSheetFragments);
479 :
480 388 : for( std::vector<WorksheetHelper*>::iterator aIt = maHelpers.begin(), aEnd = maHelpers.end(); aIt != aEnd; ++aIt )
481 : {
482 260 : (*aIt)->finalizeDrawingImport();
483 : }
484 :
485 388 : for( SheetFragmentVector::iterator aIt = aSheetFragments.begin(), aEnd = aSheetFragments.end(); aIt != aEnd; ++aIt )
486 : {
487 : // delete fragment object and WorkbookGlobals object, will free all allocated sheet buffers
488 260 : aIt->second.clear();
489 260 : aIt->first.reset();
490 : }
491 :
492 : // final conversions, e.g. calculation settings and view settings
493 128 : finalizeWorkbookImport();
494 :
495 256 : OUString aRevHeadersPath = getFragmentPathFromFirstType(CREATE_OFFICEDOC_RELATION_TYPE("revisionHeaders"));
496 128 : if (!aRevHeadersPath.isEmpty())
497 : {
498 4 : boost::scoped_ptr<oox::core::FastParser> xParser(getOoxFilter().createParser());
499 8 : rtl::Reference<oox::core::FragmentHandler> xFragment(new RevisionHeadersFragment(*this, aRevHeadersPath));
500 8 : importOoxFragment(xFragment, *xParser);
501 256 : }
502 128 : }
503 :
504 : // private --------------------------------------------------------------------
505 :
506 2 : void WorkbookFragment::importExternalReference( const AttributeList& rAttribs )
507 : {
508 2 : if( ExternalLink* pExtLink = getExternalLinks().importExternalReference( rAttribs ).get() )
509 2 : importExternalLinkFragment( *pExtLink );
510 2 : }
511 :
512 22 : void WorkbookFragment::importDefinedName( const AttributeList& rAttribs )
513 : {
514 22 : mxCurrName = getDefinedNames().importDefinedName( rAttribs );
515 22 : }
516 :
517 8 : void WorkbookFragment::importPivotCache( const AttributeList& rAttribs )
518 : {
519 8 : sal_Int32 nCacheId = rAttribs.getInteger( XML_cacheId, -1 );
520 8 : OUString aRelId = rAttribs.getString( R_TOKEN( id ), OUString() );
521 8 : importPivotCacheDefFragment( aRelId, nCacheId );
522 8 : }
523 :
524 0 : void WorkbookFragment::importExternalRef( SequenceInputStream& rStrm )
525 : {
526 0 : if( ExternalLink* pExtLink = getExternalLinks().importExternalRef( rStrm ).get() )
527 0 : importExternalLinkFragment( *pExtLink );
528 0 : }
529 :
530 0 : void WorkbookFragment::importPivotCache( SequenceInputStream& rStrm )
531 : {
532 0 : sal_Int32 nCacheId = rStrm.readInt32();
533 0 : OUString aRelId = BiffHelper::readString( rStrm );
534 0 : importPivotCacheDefFragment( aRelId, nCacheId );
535 0 : }
536 :
537 2 : void WorkbookFragment::importExternalLinkFragment( ExternalLink& rExtLink )
538 : {
539 2 : OUString aFragmentPath = getFragmentPathFromRelId( rExtLink.getRelId() );
540 2 : if( !aFragmentPath.isEmpty() )
541 2 : importOoxFragment( new ExternalLinkFragment( *this, aFragmentPath, rExtLink ) );
542 2 : }
543 :
544 8 : void WorkbookFragment::importPivotCacheDefFragment( const OUString& rRelId, sal_Int32 nCacheId )
545 : {
546 : // pivot caches will be imported on demand, here we just store the fragment path in the buffer
547 8 : getPivotCaches().registerPivotCacheFragment( nCacheId, getFragmentPathFromRelId( rRelId ) );
548 8 : }
549 :
550 : } // namespace xls
551 48 : } // namespace oox
552 :
553 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|