diff options
author | Ivo Hinkelmann <ihi@openoffice.org> | 2009-04-22 10:06:26 +0000 |
---|---|---|
committer | Ivo Hinkelmann <ihi@openoffice.org> | 2009-04-22 10:06:26 +0000 |
commit | 0554b3bf93e56f8304529a93d961fa3fa60c199d (patch) | |
tree | 9f72e55aa3310502de84f74c4db5764559338d53 /oox/source/xls/pivotcachefragment.cxx | |
parent | f9ce9a1d243d8a4e550b8f9aea92246c21ad6a73 (diff) |
CWS-TOOLING: integrate CWS dr67
2009-04-08 13:23:56 +0200 dr r270638 : #i100534# reverted
2009-04-08 10:14:55 +0200 dr r270621 : CWS-TOOLING: rebase CWS dr67 to trunk@270033 (milestone: DEV300:m45)
2009-04-07 21:06:33 +0200 dr r270610 : #i100534# sc does not link in debug mode
2009-03-12 11:20:09 +0100 dr r269375 : #i10000# wae
2009-03-11 19:43:55 +0100 dr r269351 : #i10000# adjust oox namespace ids according to oox/inc/oox/core/namespaces.hxx
2009-03-11 15:38:52 +0100 dr r269339 : CWS-TOOLING: rebase CWS dr67 to trunk@269297 (milestone: DEV300:m43)
2009-02-27 15:20:21 +0100 dr r268598 : CWS-TOOLING: rebase CWS dr67 to trunk@268395 (milestone: DEV300:m42)
2009-02-19 13:32:17 +0100 dr r268277 : moved hf parser into page settings
2009-02-19 12:25:15 +0100 dr r268272 : renamed some structs according to chart filter
2009-02-16 15:51:31 +0100 dr r267823 : #i97873# import autosort settings from BIFF8/OOBIN/OOXML
2009-02-06 17:09:29 +0100 dr r267477 : #i97873# minor changes
2009-02-06 16:38:56 +0100 dr r267473 : #i97873# import date grouping settings from BIFF5/BIFF8/OOBIN/OOXML
2009-02-06 16:38:11 +0100 dr r267472 : #i97873# check min/max/step of passed GroupInfo
2009-02-06 16:35:13 +0100 dr r267471 : #i97873# more doc for createDategroup()
2009-02-06 13:53:42 +0100 dr r267459 : #i97873# make XDataPilotGrouping::createDateGroup() implementation working and robust against wrong input data
2009-02-06 13:52:16 +0100 dr r267458 : #i97873# fix and extend IDL doc for datapilot grouping
2009-02-06 12:35:49 +0100 dr r267453 : fix other IDLC warnings in sheet module
2009-02-06 12:05:19 +0100 dr r267448 : #i97873# fix and extend IDL doc for datapilot grouping
2009-02-02 17:58:46 +0100 dr r267284 : #i10000# rebase errors
2009-02-02 17:52:21 +0100 dr r267282 : #i10000# rebase errors
2009-02-02 17:35:58 +0100 dr r267280 : #i10000# rebase errors
2009-02-02 15:58:04 +0100 dr r267274 : CWS-TOOLING: rebase CWS dr67 to trunk@267171 (milestone: DEV300:m41)
2009-02-02 09:16:32 +0100 dr r267247 : #i97873# typo
2009-01-30 17:09:09 +0100 dr r267215 : #i97873# import numeric grouping settings for datapilot fields from BIFF5/BIFF8/OOBIN/OOXML
2009-01-29 16:36:24 +0100 dr r267154 : #i97873# import datapilot discrete grouping from BIFF5/BIFF8/OOBIN/OOXLS
2009-01-29 16:33:37 +0100 dr r267152 : #i97873# do not kill _all_ the other group fields when writing back DataPilotField::GroupInfo property
2009-01-29 14:15:45 +0100 dr r267133 : #i93839# remove ScChengeTrack::Load and ::Store, adapt xls export filter
2009-01-28 13:30:37 +0100 dr r267056 : #i98397# enhance DataPilot API: allow to rename groups and items in a group field
2009-01-28 12:09:05 +0100 dr r267051 : #i98397# enhance DataPilot API: allow to rename groups and items in a group field
2009-01-27 16:13:58 +0100 dr r267005 : #i97873# minor changes in DataPilot API implementation as preparation for additional changes needed for OOX import filter
2009-01-27 10:08:01 +0100 dr r266961 : #i97873# changing orientation of a DP field moves it to last position in new dimension
2009-01-27 10:06:50 +0100 dr r266960 : #i97873# changing orientation of a DP field moves it to last position in new dimension
2009-01-23 12:52:31 +0100 dr r266808 : #i97873# DP documentation extended
2009-01-21 20:07:15 +0100 dr r266702 : #i97873# this trivial patch adds BIFF5/BIFF8 pivot table import to the oox filter
2009-01-20 16:06:23 +0100 dr r266592 : select BIFF filter via env.var
2009-01-16 18:51:01 +0100 dr r266452 : #i97873# import page fields
2009-01-16 15:05:36 +0100 dr r266420 : #i97873# field item settings (collapsed/hidden), settings of hidden fields
2009-01-15 16:01:17 +0100 dr r266377 : #i97873# import OOXML7/OOBIN7 autoshow settings
2009-01-14 15:24:27 +0100 dr r266310 : #i97873# import auto show settings generated by MSO2003
2009-01-14 12:29:44 +0100 dr r266281 : #i97873# set global dp settings
2009-01-13 15:04:30 +0100 dr r266229 : #i98029# SdrGroupObj does not remember predefined bounding rectangle anymore
2009-01-13 14:46:50 +0100 dr r266225 : #i98029# SdrGroupObj does not remember predefined bounding rectangle anymore
2009-01-12 15:04:22 +0100 dr r266161 : #i97873# remove misleading hasDataLayoutField()
2009-01-12 15:03:42 +0100 dr r266160 : #i97873# remove misleading hasDataLayoutField()
2009-01-12 14:57:33 +0100 dr r266159 : #i97900# reverted previous change, adjusted code to new EnableRTL() behaviour
2009-01-12 14:52:43 +0100 dr r266158 : #i97900# reverted previous change, adjusted code to new EnableRTL() behaviour
2009-01-09 16:34:55 +0100 dr r266098 : #i97900# RTL handling in TabBar changed with CWS rtlcontrols
2009-01-09 16:32:16 +0100 dr r266097 : #i97900# RTL handling in TabBar changed with CWS rtlcontrols
2009-01-09 12:02:39 +0100 dr r266072 : #i97623# RTL handling changed after CWS rtlcontrols
2009-01-09 09:48:53 +0100 dr r266050 : #i158444# SXLI must be filled completely before starting CONTINUE
2009-01-08 18:50:08 +0100 dr r266032 : #158444# allow to disable dump of record positions
2009-01-08 15:46:45 +0100 dr r266020 : #i97873# data layout field handling
2009-01-08 15:45:45 +0100 dr r266019 : #i97873# data layout field handling
2009-01-08 15:42:25 +0100 dr r266018 : #i97873# data layout field handling
2009-01-02 17:28:32 +0100 dr r265844 : #i10000# unxmacxi warning
2009-01-02 16:59:13 +0100 dr r265842 : #i10000# rebase corrections
2009-01-02 16:44:44 +0100 dr r265838 : #i10000# rebase corrections
2009-01-02 11:32:44 +0100 dr r265834 : CWS-TOOLING: rebase CWS dr67 to trunk@265758 (milestone: DEV300:m38)
2008-12-29 16:55:40 +0100 dr r265822 : more pivot table import, field layout settings
2008-12-29 14:27:35 +0100 dr r265817 : more pivot table import, additions for data field settings
2008-12-26 14:39:21 +0100 dr r265805 : updates
2008-12-19 16:31:39 +0100 dr r265734 : typo
2008-12-19 16:30:00 +0100 dr r265733 : add API for sequence of DP field subtotal functions
2008-12-19 16:29:43 +0100 dr r265732 : add API for sequence of DP field subtotal functions
2008-12-19 16:29:07 +0100 dr r265731 : add API for sequence of DP field subtotal functions
2008-12-18 18:07:58 +0100 dr r265710 : #i96758# try to cache row default formatting and apply it at row ranges instead of single rows
2008-12-18 16:00:25 +0100 dr r265698 : more additions to pivot import
2008-12-17 13:38:19 +0100 dr r265599 : do not assert HIDDEN orientation
2008-12-12 13:51:29 +0100 dr r265415 : minor typos
2008-12-12 10:15:04 +0100 dr r265394 : pivot cache import extended to XLSB, added creation of cache data for missing/external sheets
2008-12-04 13:16:16 +0100 dr r264837 : #i96860# remove old dumper files
2008-12-04 12:17:38 +0100 dr r264834 : #i96858# XTO broken, if textbox is empty but contains formatting
2008-12-04 12:16:38 +0100 dr r264833 : #i96858# XTO broken, if textbox is empty but contains formatting
2008-12-03 14:51:05 +0100 dr r264784 : #i10000# warnings
2008-12-03 14:32:46 +0100 dr r264778 : #i10000# warning
2008-12-03 11:28:38 +0100 dr r264758 : #i96758# ignore zero-sized objects
2008-12-03 10:09:34 +0100 dr r264748 : #i96758# change ::oox::Property(Set|Map) keys to sal_Int32 property identifiers, to save construction of property names
2008-12-01 16:09:02 +0100 dr r264615 : #i96758# headerdoc
2008-12-01 14:49:04 +0100 dr r264607 : #i96758# import performance of formatted documents
2008-11-26 17:08:15 +0100 dr r264424 : make it more simple
2008-11-26 16:31:41 +0100 dr r264419 : c:crossesAt is for crossing axis, not for own axis. This is different to BIFF
2008-11-26 13:55:55 +0100 dr r264382 : #i86346# import of MissingValueTreatment from XLSX
2008-11-26 12:49:38 +0100 dr r264370 : #i86346# import/export of MissingValueTreatment from/to XLS
2008-11-25 17:48:59 +0100 dr r264320 : update row height with single progress bar when using 'IsAdjustHeightEnabled' document property
2008-11-25 17:24:26 +0100 dr r264319 : #i96438# disable importing comment text until API is fixed
2008-11-25 17:11:30 +0100 dr r264318 : #i90124# set control tooltips, patch from npower
2008-11-25 15:09:28 +0100 dr r264309 : #i94028# #i94991# update drawing objects when changing row height
2008-11-24 15:21:35 +0100 dr r264224 : prevent ::rtl::OUString::copy assertion
2008-11-24 15:19:39 +0100 dr r264223 : #i95183# #158573# handle non-ascii characters in sheet names in OOXML import
2008-11-24 12:54:30 +0100 dr r264221 : #i94157# support ESC key to leave full-screen in page preview
2008-11-21 18:15:17 +0100 dr r264165 : #i90360# disable chart perspective if it is set to 0
2008-11-21 18:14:41 +0100 dr r264164 : #i90360# disable chart perspective if it is set to 0
2008-11-21 17:43:26 +0100 dr r264155 : #i96140# missing parenth
2008-11-21 17:36:35 +0100 dr r264154 : #i96438# first steps of note import
2008-11-20 15:15:03 +0100 dr r264059 : get rid of ContextWrapper
2008-11-18 11:39:52 +0100 dr r263755 : #i78476# moved to CWS dr67
Diffstat (limited to 'oox/source/xls/pivotcachefragment.cxx')
-rw-r--r-- | oox/source/xls/pivotcachefragment.cxx | 453 |
1 files changed, 380 insertions, 73 deletions
diff --git a/oox/source/xls/pivotcachefragment.cxx b/oox/source/xls/pivotcachefragment.cxx index a41405a4a7be..713e0ed3ac39 100644 --- a/oox/source/xls/pivotcachefragment.cxx +++ b/oox/source/xls/pivotcachefragment.cxx @@ -30,132 +30,439 @@ #include "oox/xls/pivotcachefragment.hxx" #include "oox/helper/attributelist.hxx" +#include "oox/helper/recordinputstream.hxx" #include "oox/xls/addressconverter.hxx" +#include "oox/xls/biffinputstream.hxx" +#include "oox/xls/pivotcachebuffer.hxx" using ::rtl::OUString; -using ::com::sun::star::uno::Reference; -using ::com::sun::star::uno::Exception; -using ::com::sun::star::uno::RuntimeException; -using ::com::sun::star::uno::UNO_QUERY; -using ::com::sun::star::uno::UNO_QUERY_THROW; -using ::com::sun::star::sheet::XSpreadsheet; -using ::com::sun::star::table::CellRangeAddress; -using ::com::sun::star::xml::sax::SAXException; +using ::com::sun::star::uno::Any; +using ::oox::core::ContextHandlerRef; +using ::oox::core::RecordInfo; namespace oox { namespace xls { -OoxPivotCacheFragment::OoxPivotCacheFragment( const WorkbookHelper& rHelper, - const OUString& rFragmentPath, - sal_uInt32 nCacheId ) : - OoxWorkbookFragmentBase( rHelper, rFragmentPath ), - mnCacheId( nCacheId ), - mbValidSource( false ) +// ============================================================================ + +OoxPivotCacheFieldContext::OoxPivotCacheFieldContext( OoxWorkbookFragmentBase& rFragment, PivotCacheField& rCacheField ) : + OoxWorkbookContextBase( rFragment ), + mrCacheField( rCacheField ) { } -ContextWrapper OoxPivotCacheFragment::onCreateContext( sal_Int32 nElement, const AttributeList& ) +ContextHandlerRef OoxPivotCacheFieldContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) { switch( getCurrentElement() ) { - case XML_ROOT_CONTEXT: - return (nElement == XLS_TOKEN( pivotCacheDefinition )); - case XLS_TOKEN( pivotCacheDefinition ): - return (nElement == XLS_TOKEN( cacheSource )) || - (nElement == XLS_TOKEN( cacheFields )); - case XLS_TOKEN( cacheSource ): - return (nElement == XLS_TOKEN( worksheetSource )); - case XLS_TOKEN( cacheFields ): - return (nElement == XLS_TOKEN( cacheField )); case XLS_TOKEN( cacheField ): - return (nElement == XLS_TOKEN( sharedItems )); - case XLS_TOKEN( sharedItems ): - return (nElement == XLS_TOKEN( s )); + if( nElement == XLS_TOKEN( sharedItems ) ) { mrCacheField.importSharedItems( rAttribs ); return this; } + if( nElement == XLS_TOKEN( fieldGroup ) ) { mrCacheField.importFieldGroup( rAttribs ); return this; } + break; + + case XLS_TOKEN( fieldGroup ): + switch( nElement ) + { + case XLS_TOKEN( rangePr ): mrCacheField.importRangePr( rAttribs ); break; + case XLS_TOKEN( discretePr ): return this; + case XLS_TOKEN( groupItems ): return this; + } + break; + + case XLS_TOKEN( sharedItems ): mrCacheField.importSharedItem( nElement, rAttribs ); break; + case XLS_TOKEN( discretePr ): mrCacheField.importDiscretePrItem( nElement, rAttribs ); break; + case XLS_TOKEN( groupItems ): mrCacheField.importGroupItem( nElement, rAttribs ); break; } - return false; + return 0; +} + +void OoxPivotCacheFieldContext::onStartElement( const AttributeList& rAttribs ) +{ + if( isRootElement() ) + mrCacheField.importCacheField( rAttribs ); } -void OoxPivotCacheFragment::onStartElement( const AttributeList& rAttribs ) +ContextHandlerRef OoxPivotCacheFieldContext::onCreateRecordContext( sal_Int32 nRecId, RecordInputStream& rStrm ) { - switch ( getCurrentElement() ) + switch( getCurrentElement() ) { + case OOBIN_ID_PCDFIELD: + switch( nRecId ) + { + case OOBIN_ID_PCDFSHAREDITEMS: mrCacheField.importPCDFSharedItems( rStrm ); return this; + case OOBIN_ID_PCDFIELDGROUP: mrCacheField.importPCDFieldGroup( rStrm ); return this; + } + break; + + case OOBIN_ID_PCDFIELDGROUP: + switch( nRecId ) + { + case OOBIN_ID_PCDFRANGEPR: mrCacheField.importPCDFRangePr( rStrm ); break; + case OOBIN_ID_PCDFDISCRETEPR: return this; + case OOBIN_ID_PCDFGROUPITEMS: return this; + } + break; + + case OOBIN_ID_PCDFSHAREDITEMS: mrCacheField.importPCDFSharedItem( nRecId, rStrm ); break; + case OOBIN_ID_PCDFDISCRETEPR: mrCacheField.importPCDFDiscretePrItem( nRecId, rStrm ); break; + case OOBIN_ID_PCDFGROUPITEMS: mrCacheField.importPCDFGroupItem( nRecId, rStrm ); break; + } + return 0; +} + +void OoxPivotCacheFieldContext::onStartRecord( RecordInputStream& rStrm ) +{ + if( isRootElement() ) + mrCacheField.importPCDField( rStrm ); +} + +// ============================================================================ + +OoxPivotCacheDefinitionFragment::OoxPivotCacheDefinitionFragment( + const WorkbookHelper& rHelper, const OUString& rFragmentPath, PivotCache& rPivotCache ) : + OoxWorkbookFragmentBase( rHelper, rFragmentPath ), + mrPivotCache( rPivotCache ) +{ +} + +ContextHandlerRef OoxPivotCacheDefinitionFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + switch( getCurrentElement() ) + { + case XML_ROOT_CONTEXT: + if( nElement == XLS_TOKEN( pivotCacheDefinition ) ) { mrPivotCache.importPivotCacheDefinition( rAttribs ); return this; } + break; + case XLS_TOKEN( pivotCacheDefinition ): - importPivotCacheDefinition( rAttribs ); + switch( nElement ) + { + case XLS_TOKEN( cacheSource ): mrPivotCache.importCacheSource( rAttribs ); return this; + case XLS_TOKEN( cacheFields ): return this; + } break; + case XLS_TOKEN( cacheSource ): - importCacheSource( rAttribs ); - break; - case XLS_TOKEN( worksheetSource ): - if ( mbValidSource ) - importWorksheetSource( rAttribs ); + if( nElement == XLS_TOKEN( worksheetSource ) ) mrPivotCache.importWorksheetSource( rAttribs, getRelations() ); break; + case XLS_TOKEN( cacheFields ): - if ( mbValidSource ) - maPCacheData.maFields.reserve( rAttribs.getUnsignedInteger(XML_count, 1) ); + if( nElement == XLS_TOKEN( cacheField ) ) return new OoxPivotCacheFieldContext( *this, mrPivotCache.createCacheField() ); break; - case XLS_TOKEN( cacheField ): - if ( mbValidSource ) - importCacheField( rAttribs ); + } + return 0; +} + +ContextHandlerRef OoxPivotCacheDefinitionFragment::onCreateRecordContext( sal_Int32 nRecId, RecordInputStream& rStrm ) +{ + switch( getCurrentElement() ) + { + case XML_ROOT_CONTEXT: + if( nRecId == OOBIN_ID_PCDEFINITION ) { mrPivotCache.importPCDefinition( rStrm ); return this; } break; - case XLS_TOKEN( sharedItems ): - if ( mbValidSource ) - maPCacheData.maFields.back().maItems.reserve( rAttribs.getUnsignedInteger(XML_count, 1) ); + + case OOBIN_ID_PCDEFINITION: + switch( nRecId ) + { + case OOBIN_ID_PCDSOURCE: mrPivotCache.importPCDSource( rStrm ); return this; + case OOBIN_ID_PCDFIELDS: return this; + } break; - case XLS_TOKEN( s ): - if ( mbValidSource ) - maPCacheData.maFields.back().maItems.push_back( rAttribs.getString( XML_v, OUString() ) ); + + case OOBIN_ID_PCDSOURCE: + if( nRecId == OOBIN_ID_PCDSHEETSOURCE ) mrPivotCache.importPCDSheetSource( rStrm, getRelations() ); + break; + + case OOBIN_ID_PCDFIELDS: + if( nRecId == OOBIN_ID_PCDFIELD ) return new OoxPivotCacheFieldContext( *this, mrPivotCache.createCacheField() ); break; } + return 0; } -void OoxPivotCacheFragment::finalizeImport() +const RecordInfo* OoxPivotCacheDefinitionFragment::getRecordInfos() const { - if( mbValidSource ) - getPivotTables().setPivotCache( mnCacheId, maPCacheData ); + static const RecordInfo spRecInfos[] = + { + { OOBIN_ID_PCDEFINITION, OOBIN_ID_PCDEFINITION + 1 }, + { OOBIN_ID_PCDFDISCRETEPR, OOBIN_ID_PCDFDISCRETEPR + 1 }, + { OOBIN_ID_PCDFGROUPITEMS, OOBIN_ID_PCDFGROUPITEMS + 1 }, + { OOBIN_ID_PCDFIELD, OOBIN_ID_PCDFIELD + 1 }, + { OOBIN_ID_PCDFIELDGROUP, OOBIN_ID_PCDFIELDGROUP + 1 }, + { OOBIN_ID_PCDFIELDS, OOBIN_ID_PCDFIELDS + 1 }, + { OOBIN_ID_PCDFRANGEPR, OOBIN_ID_PCDFRANGEPR + 1 }, + { OOBIN_ID_PCDFSHAREDITEMS, OOBIN_ID_PCDFSHAREDITEMS + 1 }, + { OOBIN_ID_PCITEM_ARRAY, OOBIN_ID_PCITEM_ARRAY + 1 }, + { OOBIN_ID_PCDSHEETSOURCE, OOBIN_ID_PCDSHEETSOURCE + 1 }, + { OOBIN_ID_PCDSOURCE, OOBIN_ID_PCDSOURCE + 1 }, + { -1, -1 } + }; + return spRecInfos; } -void OoxPivotCacheFragment::importPivotCacheDefinition( const AttributeList& /*rAttribs*/ ) +void OoxPivotCacheDefinitionFragment::finalizeImport() { + // finalize the cache (check source range etc.) + mrPivotCache.finalizeImport(); + + // load the cache records, if the cache is based on a deleted or an external worksheet + if( mrPivotCache.isValidDataSource() && mrPivotCache.isBasedOnDummySheet() ) + { + OUString aRecFragmentPath = getRelations().getFragmentPathFromRelId( mrPivotCache.getRecordsRelId() ); + if( aRecFragmentPath.getLength() > 0 ) + importOoxFragment( new OoxPivotCacheRecordsFragment( *this, aRecFragmentPath, mrPivotCache ) ); + } } -void OoxPivotCacheFragment::importCacheSource( const AttributeList& rAttribs ) +// ============================================================================ + +OoxPivotCacheRecordsFragment::OoxPivotCacheRecordsFragment( const WorkbookHelper& rHelper, + const OUString& rFragmentPath, const PivotCache& rPivotCache ) : + OoxWorksheetFragmentBase( rHelper, rFragmentPath, ISegmentProgressBarRef(), SHEETTYPE_WORKSHEET, rPivotCache.getSourceRange().Sheet ), + mrPivotCache( rPivotCache ), + mnCol( 0 ), + mnRow( 0 ), + mbInRecord( false ) { - switch ( rAttribs.getToken(XML_type, XML_TOKEN_INVALID) ) + // prepare sheet: insert column header names into top row + rPivotCache.writeSourceHeaderCells( *this ); +} + +ContextHandlerRef OoxPivotCacheRecordsFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + switch( getCurrentElement() ) { - case XML_worksheet: - maPCacheData.meSourceType = PivotCacheData::WORKSHEET; - maPCacheData.mpSourceProp.reset( new PivotCacheData::WorksheetSource ); - mbValidSource = true; + case XML_ROOT_CONTEXT: + if( nElement == XLS_TOKEN( pivotCacheRecords ) ) return this; break; - case XML_external: - maPCacheData.meSourceType = PivotCacheData::EXTERNAL; - maPCacheData.mpSourceProp.reset( new PivotCacheData::ExternalSource ); - mbValidSource = true; + + case XLS_TOKEN( pivotCacheRecords ): + if( nElement == XLS_TOKEN( r ) ) { startCacheRecord(); return this; } break; - default: - // unsupported case source type. + + case XLS_TOKEN( r ): + { + PivotCacheItem aItem; + switch( nElement ) + { + case XLS_TOKEN( m ): break; + case XLS_TOKEN( s ): aItem.readString( rAttribs ); break; + case XLS_TOKEN( n ): aItem.readNumeric( rAttribs ); break; + case XLS_TOKEN( d ): aItem.readDate( rAttribs ); break; + case XLS_TOKEN( b ): aItem.readBool( rAttribs ); break; + case XLS_TOKEN( e ): aItem.readError( rAttribs, getUnitConverter() ); break; + case XLS_TOKEN( x ): aItem.readIndex( rAttribs ); break; + default: OSL_ENSURE( false, "OoxPivotCacheRecordsFragment::onCreateContext - unexpected element" ); + } + mrPivotCache.writeSourceDataCell( *this, mnCol, mnRow, aItem ); + ++mnCol; + } break; } + return 0; } -void OoxPivotCacheFragment::importWorksheetSource( const AttributeList& rAttribs ) +ContextHandlerRef OoxPivotCacheRecordsFragment::onCreateRecordContext( sal_Int32 nRecId, RecordInputStream& rStrm ) { - if ( maPCacheData.meSourceType != PivotCacheData::WORKSHEET ) + switch( getCurrentElement() ) + { + case XML_ROOT_CONTEXT: + if( nRecId == OOBIN_ID_PCRECORDS ) return this; + break; + + case OOBIN_ID_PCRECORDS: + switch( nRecId ) + { + case OOBIN_ID_PCRECORD: importPCRecord( rStrm ); break; + case OOBIN_ID_PCRECORDDT: startCacheRecord(); break; + default: importPCRecordItem( nRecId, rStrm ); break; + } + break; + } + return 0; +} + +const RecordInfo* OoxPivotCacheRecordsFragment::getRecordInfos() const +{ + static const RecordInfo spRecInfos[] = + { + { OOBIN_ID_PCRECORDS, OOBIN_ID_PCRECORDS + 1 }, + { -1, -1 } + }; + return spRecInfos; +} + +// private -------------------------------------------------------------------- + +void OoxPivotCacheRecordsFragment::startCacheRecord() +{ + mnCol = 0; + ++mnRow; + mbInRecord = true; +} + +void OoxPivotCacheRecordsFragment::importPCRecord( RecordInputStream& rStrm ) +{ + startCacheRecord(); + mrPivotCache.importPCRecord( rStrm, *this, mnRow ); + mbInRecord = false; +} + +void OoxPivotCacheRecordsFragment::importPCRecordItem( sal_Int32 nRecId, RecordInputStream& rStrm ) +{ + if( mbInRecord ) + { + PivotCacheItem aItem; + switch( nRecId ) + { + case OOBIN_ID_PCITEM_MISSING: break; + case OOBIN_ID_PCITEM_STRING: aItem.readString( rStrm ); break; + case OOBIN_ID_PCITEM_DOUBLE: aItem.readDouble( rStrm ); break; + case OOBIN_ID_PCITEM_DATE: aItem.readDate( rStrm ); break; + case OOBIN_ID_PCITEM_BOOL: aItem.readBool( rStrm ); break; + case OOBIN_ID_PCITEM_ERROR: aItem.readError( rStrm ); break; + case OOBIN_ID_PCITEM_INDEX: aItem.readIndex( rStrm ); break; + default: OSL_ENSURE( false, "OoxPivotCacheRecordsFragment::importPCRecordItem - unexpected record" ); + } + mrPivotCache.writeSourceDataCell( *this, mnCol, mnRow, aItem ); + ++mnCol; + } +} + +// ============================================================================ +// ============================================================================ + +namespace { + +bool lclSeekToPCDField( BiffInputStream& rStrm ) +{ + sal_Int64 nRecHandle = rStrm.getRecHandle(); + while( rStrm.startNextRecord() ) + if( rStrm.getRecId() == BIFF_ID_PCDFIELD ) + return true; + rStrm.startRecordByHandle( nRecHandle ); + return false; +} + +} // namespace + +// ---------------------------------------------------------------------------- + +BiffPivotCacheFragment::BiffPivotCacheFragment( + const WorkbookHelper& rHelper, const ::rtl::OUString& rStrmName, PivotCache& rPivotCache ) : + BiffWorkbookFragmentBase( rHelper, rStrmName, true ), + mrPivotCache( rPivotCache ) +{ +} + +bool BiffPivotCacheFragment::importFragment() +{ + if( mrStrm.startNextRecord() && (mrStrm.getRecId() == BIFF_ID_PCDEFINITION) ) + { + // read PCDEFINITION and optional PCDEFINITION2 records + mrPivotCache.importPCDefinition( mrStrm ); + + // read cache fields as long as another PCDFIELD record can be found + while( lclSeekToPCDField( mrStrm ) ) + mrPivotCache.createCacheField( true ).importPCDField( mrStrm ); + + // finalize the cache (check source range etc.) + mrPivotCache.finalizeImport(); + + // load the cache records, if the cache is based on a deleted or an external worksheet + if( mrPivotCache.isValidDataSource() && mrPivotCache.isBasedOnDummySheet() ) + { + /* Last call of lclSeekToPCDField() failed and kept stream position + unchanged. Stream should point to source data table now. */ + BiffPivotCacheRecordsContext aContext( *this, mrPivotCache ); + if( aContext.isValidSheet() ) + while( mrStrm.startNextRecord() && (mrStrm.getRecId() != BIFF_ID_EOF) ) + aContext.importRecord(); + } + } + + return mrStrm.getRecId() == BIFF_ID_EOF; +} + +// ============================================================================ + +BiffPivotCacheRecordsContext::BiffPivotCacheRecordsContext( + const BiffWorkbookFragmentBase& rFragment, const PivotCache& rPivotCache ) : + BiffWorksheetContextBase( rFragment, ISegmentProgressBarRef(), SHEETTYPE_WORKSHEET, rPivotCache.getSourceRange().Sheet ), + mrPivotCache( rPivotCache ), + mnColIdx( 0 ), + mnRow( 0 ), + mbHasShared( false ), + mbInRow( false ) +{ + // prepare sheet: insert column header names into top row + mrPivotCache.writeSourceHeaderCells( *this ); + + // find all fields without shared items, remember column indexes in source data + for( sal_Int32 nFieldIdx = 0, nFieldCount = mrPivotCache.getCacheFieldCount(), nCol = 0; nFieldIdx < nFieldCount; ++nFieldIdx ) + { + const PivotCacheField* pCacheField = mrPivotCache.getCacheField( nFieldIdx ); + if( pCacheField && pCacheField->isDatabaseField() ) + { + if( pCacheField->hasSharedItems() ) + mbHasShared = true; + else + maUnsharedCols.push_back( nCol ); + ++nCol; + } + } +} + +void BiffPivotCacheRecordsContext::importRecord() +{ + if( mrStrm.getRecId() == BIFF_ID_PCITEM_INDEXLIST ) + { + OSL_ENSURE( mbHasShared, "BiffPivotCacheRecordsContext::importRecord - unexpected PCITEM_INDEXLIST record" ); + // PCITEM_INDEXLIST record always in front of a new data row + startNextRow(); + mrPivotCache.importPCItemIndexList( mrStrm, *this, mnRow ); + mbInRow = !maUnsharedCols.empty(); // mbInRow remains true, if unshared items are expected return; + } - PivotCacheData::WorksheetSource* pSrc = static_cast<PivotCacheData::WorksheetSource*>( - maPCacheData.mpSourceProp.get() ); + PivotCacheItem aItem; + switch( mrStrm.getRecId() ) + { + case BIFF_ID_PCITEM_MISSING: break; + case BIFF_ID_PCITEM_STRING: aItem.readString( mrStrm, *this ); break; + case BIFF_ID_PCITEM_DOUBLE: aItem.readDouble( mrStrm ); break; + case BIFF_ID_PCITEM_INTEGER: aItem.readInteger( mrStrm ); break; + case BIFF_ID_PCITEM_DATE: aItem.readDate( mrStrm ); break; + case BIFF_ID_PCITEM_BOOL: aItem.readBool( mrStrm ); break; + case BIFF_ID_PCITEM_ERROR: aItem.readError( mrStrm ); break; + default: return; // unknown record, ignore + } - pSrc->maSrcRange = rAttribs.getString( XML_ref, OUString() ); - pSrc->maSheetName = rAttribs.getString( XML_sheet, OUString() ); + // find next column index, might start new row if no fields with shared items exist + if( mbInRow && (mnColIdx == maUnsharedCols.size()) ) + { + OSL_ENSURE( !mbHasShared, "BiffPivotCacheRecordsContext::importRecord - PCITEM_INDEXLIST record missing" ); + mbInRow = mbHasShared; // do not leave current row if PCITEM_INDEXLIST is expected + } + // start next row on first call, or on row wrap without shared items + if( !mbInRow ) + startNextRow(); + + // write the item data to the sheet cell + OSL_ENSURE( mnColIdx < maUnsharedCols.size(), "BiffPivotCacheRecordsContext::importRecord - invalid column index" ); + if( mnColIdx < maUnsharedCols.size() ) + mrPivotCache.writeSourceDataCell( *this, maUnsharedCols[ mnColIdx ], mnRow, aItem ); + ++mnColIdx; } -void OoxPivotCacheFragment::importCacheField( const AttributeList& rAttribs ) +void BiffPivotCacheRecordsContext::startNextRow() { - PivotCacheField aField; - aField.maName = rAttribs.getString( XML_name, OUString() ); - maPCacheData.maFields.push_back(aField); + mnColIdx = 0; + ++mnRow; + mbInRow = true; } +// ============================================================================ + } // namespace xls } // namespace oox + |