1*e3508121SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*e3508121SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*e3508121SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*e3508121SAndrew Rist * distributed with this work for additional information 6*e3508121SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*e3508121SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*e3508121SAndrew Rist * "License"); you may not use this file except in compliance 9*e3508121SAndrew Rist * with the License. You may obtain a copy of the License at 10*e3508121SAndrew Rist * 11*e3508121SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*e3508121SAndrew Rist * 13*e3508121SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*e3508121SAndrew Rist * software distributed under the License is distributed on an 15*e3508121SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*e3508121SAndrew Rist * KIND, either express or implied. See the License for the 17*e3508121SAndrew Rist * specific language governing permissions and limitations 18*e3508121SAndrew Rist * under the License. 19*e3508121SAndrew Rist * 20*e3508121SAndrew Rist *************************************************************/ 21*e3508121SAndrew Rist 22*e3508121SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef OOX_XLS_PIVOTCACHEBUFFER_HXX 25cdf0e10cSrcweir #define OOX_XLS_PIVOTCACHEBUFFER_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <com/sun/star/table/CellAddress.hpp> 28cdf0e10cSrcweir #include <com/sun/star/table/CellRangeAddress.hpp> 29cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp> 30cdf0e10cSrcweir #include "oox/helper/containerhelper.hxx" 31cdf0e10cSrcweir #include "oox/helper/refvector.hxx" 32cdf0e10cSrcweir #include "oox/xls/workbookhelper.hxx" 33cdf0e10cSrcweir 34cdf0e10cSrcweir namespace com { namespace sun { namespace star { 35cdf0e10cSrcweir namespace sheet { class XDataPilotField; } 36cdf0e10cSrcweir } } } 37cdf0e10cSrcweir 38cdf0e10cSrcweir namespace oox { namespace core { class Relations; } } 39cdf0e10cSrcweir 40cdf0e10cSrcweir namespace oox { 41cdf0e10cSrcweir namespace xls { 42cdf0e10cSrcweir 43cdf0e10cSrcweir class WorksheetHelper; 44cdf0e10cSrcweir 45cdf0e10cSrcweir // ============================================================================ 46cdf0e10cSrcweir 47cdf0e10cSrcweir class PivotCacheItem 48cdf0e10cSrcweir { 49cdf0e10cSrcweir public: 50cdf0e10cSrcweir explicit PivotCacheItem(); 51cdf0e10cSrcweir 52cdf0e10cSrcweir /** Reads the string value from a pivot cache item. */ 53cdf0e10cSrcweir void readString( const AttributeList& rAttribs ); 54cdf0e10cSrcweir /** Reads the double value from a pivot cache item. */ 55cdf0e10cSrcweir void readNumeric( const AttributeList& rAttribs ); 56cdf0e10cSrcweir /** Reads the date/time value from a pivot cache item. */ 57cdf0e10cSrcweir void readDate( const AttributeList& rAttribs ); 58cdf0e10cSrcweir /** Reads the boolean value from a pivot cache item. */ 59cdf0e10cSrcweir void readBool( const AttributeList& rAttribs ); 60cdf0e10cSrcweir /** Reads the error code value from a pivot cache item. */ 61cdf0e10cSrcweir void readError( const AttributeList& rAttribs, const UnitConverter& rUnitConverter ); 62cdf0e10cSrcweir /** Reads the index of a shared item. */ 63cdf0e10cSrcweir void readIndex( const AttributeList& rAttribs ); 64cdf0e10cSrcweir 65cdf0e10cSrcweir /** Reads the string value from a pivot cache item. */ 66cdf0e10cSrcweir void readString( SequenceInputStream& rStrm ); 67cdf0e10cSrcweir /** Reads the double value from a pivot cache item. */ 68cdf0e10cSrcweir void readDouble( SequenceInputStream& rStrm ); 69cdf0e10cSrcweir /** Reads the date/time value from a pivot cache item. */ 70cdf0e10cSrcweir void readDate( SequenceInputStream& rStrm ); 71cdf0e10cSrcweir /** Reads the boolean value from a pivot cache item. */ 72cdf0e10cSrcweir void readBool( SequenceInputStream& rStrm ); 73cdf0e10cSrcweir /** Reads the error code value from a pivot cache item. */ 74cdf0e10cSrcweir void readError( SequenceInputStream& rStrm ); 75cdf0e10cSrcweir /** Reads the index of a shared item. */ 76cdf0e10cSrcweir void readIndex( SequenceInputStream& rStrm ); 77cdf0e10cSrcweir 78cdf0e10cSrcweir /** Reads the string value from a pivot cache item. */ 79cdf0e10cSrcweir void readString( BiffInputStream& rStrm, const WorkbookHelper& rHelper ); 80cdf0e10cSrcweir /** Reads the double value from a pivot cache item. */ 81cdf0e10cSrcweir void readDouble( BiffInputStream& rStrm ); 82cdf0e10cSrcweir /** Reads the integer value from a pivot cache item. */ 83cdf0e10cSrcweir void readInteger( BiffInputStream& rStrm ); 84cdf0e10cSrcweir /** Reads the date/time value from a pivot cache item. */ 85cdf0e10cSrcweir void readDate( BiffInputStream& rStrm ); 86cdf0e10cSrcweir /** Reads the boolean value from a pivot cache item. */ 87cdf0e10cSrcweir void readBool( BiffInputStream& rStrm ); 88cdf0e10cSrcweir /** Reads the error code value from a pivot cache item. */ 89cdf0e10cSrcweir void readError( BiffInputStream& rStrm ); 90cdf0e10cSrcweir 91cdf0e10cSrcweir /** Returns the type of the item. */ getType() const92cdf0e10cSrcweir inline sal_Int32 getType() const { return mnType; } 93cdf0e10cSrcweir /** Returns the value of the item. */ getValue() const94cdf0e10cSrcweir inline const ::com::sun::star::uno::Any& getValue() const { return maValue; } 95cdf0e10cSrcweir /** Returns the string representation of the item. */ 96cdf0e10cSrcweir ::rtl::OUString getName() const; 97cdf0e10cSrcweir 98cdf0e10cSrcweir private: 99cdf0e10cSrcweir ::com::sun::star::uno::Any maValue; /// Value of the item. 100cdf0e10cSrcweir sal_Int32 mnType; /// Value type (OOXML token identifier). 101cdf0e10cSrcweir }; 102cdf0e10cSrcweir 103cdf0e10cSrcweir // ---------------------------------------------------------------------------- 104cdf0e10cSrcweir 105cdf0e10cSrcweir class PivotCacheItemList : public WorkbookHelper 106cdf0e10cSrcweir { 107cdf0e10cSrcweir public: 108cdf0e10cSrcweir explicit PivotCacheItemList( const WorkbookHelper& rHelper ); 109cdf0e10cSrcweir 110cdf0e10cSrcweir /** Imports the item from the passed attribute list. */ 111cdf0e10cSrcweir void importItem( sal_Int32 nElement, const AttributeList& rAttribs ); 112cdf0e10cSrcweir /** Imports the item from the passed stream and record. */ 113cdf0e10cSrcweir void importItem( sal_Int32 nRecId, SequenceInputStream& rStrm ); 114cdf0e10cSrcweir /** Imports a complete item list from the passed stream. */ 115cdf0e10cSrcweir void importItemList( BiffInputStream& rStrm, sal_uInt16 nCount ); 116cdf0e10cSrcweir 117cdf0e10cSrcweir /** Returns true, if this item list is empty. */ empty() const118cdf0e10cSrcweir inline bool empty() const { return maItems.empty(); } 119cdf0e10cSrcweir /** Returns the size of the item list. */ size() const120cdf0e10cSrcweir inline size_t size() const { return maItems.size(); } 121cdf0e10cSrcweir 122cdf0e10cSrcweir /** Returns the specified item. */ 123cdf0e10cSrcweir const PivotCacheItem* getCacheItem( sal_Int32 nItemIdx ) const; 124cdf0e10cSrcweir /** Returns the names of all items. */ 125cdf0e10cSrcweir void getCacheItemNames( ::std::vector< ::rtl::OUString >& orItemNames ) const; 126cdf0e10cSrcweir 127cdf0e10cSrcweir private: 128cdf0e10cSrcweir /** Creates and returns a new item at the end of the items list. */ 129cdf0e10cSrcweir PivotCacheItem& createItem(); 130cdf0e10cSrcweir /** Imports an array of items from the PCITEM_ARRAY record */ 131cdf0e10cSrcweir void importArray( SequenceInputStream& rStrm ); 132cdf0e10cSrcweir 133cdf0e10cSrcweir private: 134cdf0e10cSrcweir typedef ::std::vector< PivotCacheItem > CacheItemVector; 135cdf0e10cSrcweir CacheItemVector maItems; /// All items of this list. 136cdf0e10cSrcweir }; 137cdf0e10cSrcweir 138cdf0e10cSrcweir // ============================================================================ 139cdf0e10cSrcweir 140cdf0e10cSrcweir struct PCFieldModel 141cdf0e10cSrcweir { 142cdf0e10cSrcweir ::rtl::OUString maName; /// Fixed name of the cache field. 143cdf0e10cSrcweir ::rtl::OUString maCaption; /// Caption of the ccahe field. 144cdf0e10cSrcweir ::rtl::OUString maPropertyName; /// OLAP property name. 145cdf0e10cSrcweir ::rtl::OUString maFormula; /// Formula of a calculated field. 146cdf0e10cSrcweir sal_Int32 mnNumFmtId; /// Number format for all items. 147cdf0e10cSrcweir sal_Int32 mnSqlType; /// Data type from ODBC data source. 148cdf0e10cSrcweir sal_Int32 mnHierarchy; /// Hierarchy this field is part of. 149cdf0e10cSrcweir sal_Int32 mnLevel; /// Hierarchy level this field is part of. 150cdf0e10cSrcweir sal_Int32 mnMappingCount; /// Number of property mappings. 151cdf0e10cSrcweir bool mbDatabaseField; /// True = field from source data; false = calculated field. 152cdf0e10cSrcweir bool mbServerField; /// True = ODBC server-based page field. 153cdf0e10cSrcweir bool mbUniqueList; /// True = list of unique ODBC items exists. 154cdf0e10cSrcweir bool mbMemberPropField; /// True = contains OLAP member properties. 155cdf0e10cSrcweir 156cdf0e10cSrcweir explicit PCFieldModel(); 157cdf0e10cSrcweir }; 158cdf0e10cSrcweir 159cdf0e10cSrcweir // ---------------------------------------------------------------------------- 160cdf0e10cSrcweir 161cdf0e10cSrcweir struct PCSharedItemsModel 162cdf0e10cSrcweir { 163cdf0e10cSrcweir bool mbHasSemiMixed; /// True = has (blank|string|bool|error) item(s), maybe other types. 164cdf0e10cSrcweir bool mbHasNonDate; /// True = has non-date item(s), maybe date items. 165cdf0e10cSrcweir bool mbHasDate; /// True = has date item(s), maybe other types. 166cdf0e10cSrcweir bool mbHasString; /// True = has (string|bool|error) item(s), maybe other types. 167cdf0e10cSrcweir bool mbHasBlank; /// True = has blank item(s), maybe other types. 168cdf0e10cSrcweir bool mbHasMixed; /// True = has [(string|bool|error) and (number|date)] or (number and date). 169cdf0e10cSrcweir bool mbIsNumeric; /// True = has numeric item(s), maybe other types except date. 170cdf0e10cSrcweir bool mbIsInteger; /// True = has numeric item(s) with only integers, maybe other types except date. 171cdf0e10cSrcweir bool mbHasLongText; /// True = contains strings with >255 charascters. 172cdf0e10cSrcweir bool mbHasLongIndexes; /// True = indexes to shared items are 16-bit (BIFF only). 173cdf0e10cSrcweir 174cdf0e10cSrcweir explicit PCSharedItemsModel(); 175cdf0e10cSrcweir }; 176cdf0e10cSrcweir 177cdf0e10cSrcweir // ---------------------------------------------------------------------------- 178cdf0e10cSrcweir 179cdf0e10cSrcweir struct PCFieldGroupModel 180cdf0e10cSrcweir { 181cdf0e10cSrcweir ::com::sun::star::util::DateTime maStartDate; /// Manual or calculated start date for range grouping. 182cdf0e10cSrcweir ::com::sun::star::util::DateTime maEndDate; /// Manual or calculated end date for range grouping. 183cdf0e10cSrcweir double mfStartValue; /// Manual or calculated start value for range grouping. 184cdf0e10cSrcweir double mfEndValue; /// Manual or calculated end value for range grouping. 185cdf0e10cSrcweir double mfInterval; /// Interval for numeric range grouping. 186cdf0e10cSrcweir sal_Int32 mnParentField; /// Index of cache field that contains item groups based on this field. 187cdf0e10cSrcweir sal_Int32 mnBaseField; /// Index of cache field this grouped field is based on. 188cdf0e10cSrcweir sal_Int32 mnGroupBy; /// Type of numeric or date range grouping. 189cdf0e10cSrcweir bool mbRangeGroup; /// True = items are grouped by numeric ranges or date ranges. 190cdf0e10cSrcweir bool mbDateGroup; /// True = items are grouped by date ranges or by item names. 191cdf0e10cSrcweir bool mbAutoStart; /// True = start value for range groups is calculated from source data. 192cdf0e10cSrcweir bool mbAutoEnd; /// True = end value for range groups is calculated from source data. 193cdf0e10cSrcweir 194cdf0e10cSrcweir explicit PCFieldGroupModel(); 195cdf0e10cSrcweir 196cdf0e10cSrcweir /** Sets the group-by value for BIFF import. */ 197cdf0e10cSrcweir void setBiffGroupBy( sal_uInt8 nGroupBy ); 198cdf0e10cSrcweir }; 199cdf0e10cSrcweir 200cdf0e10cSrcweir // ---------------------------------------------------------------------------- 201cdf0e10cSrcweir 202cdf0e10cSrcweir /** Helper struct for mapping original item names from/to group item names. */ 203cdf0e10cSrcweir struct PivotCacheGroupItem 204cdf0e10cSrcweir { 205cdf0e10cSrcweir ::rtl::OUString maOrigName; 206cdf0e10cSrcweir ::rtl::OUString maGroupName; 207cdf0e10cSrcweir PivotCacheGroupItemoox::xls::PivotCacheGroupItem208cdf0e10cSrcweir inline explicit PivotCacheGroupItem( const ::rtl::OUString& rItemName ) : 209cdf0e10cSrcweir maOrigName( rItemName ), maGroupName( rItemName ) {} 210cdf0e10cSrcweir }; 211cdf0e10cSrcweir 212cdf0e10cSrcweir typedef ::std::vector< PivotCacheGroupItem > PivotCacheGroupItemVector; 213cdf0e10cSrcweir 214cdf0e10cSrcweir // ---------------------------------------------------------------------------- 215cdf0e10cSrcweir 216cdf0e10cSrcweir class PivotCacheField : public WorkbookHelper 217cdf0e10cSrcweir { 218cdf0e10cSrcweir public: 219cdf0e10cSrcweir explicit PivotCacheField( const WorkbookHelper& rHelper, bool bIsDatabaseField ); 220cdf0e10cSrcweir 221cdf0e10cSrcweir /** Imports pivot cache field settings from the cacheField element. */ 222cdf0e10cSrcweir void importCacheField( const AttributeList& rAttribs ); 223cdf0e10cSrcweir /** Imports shared items settings from the sharedItems element. */ 224cdf0e10cSrcweir void importSharedItems( const AttributeList& rAttribs ); 225cdf0e10cSrcweir /** Imports a shared item from the passed element. */ 226cdf0e10cSrcweir void importSharedItem( sal_Int32 nElement, const AttributeList& rAttribs ); 227cdf0e10cSrcweir /** Imports grouping settings from the fieldGroup element. */ 228cdf0e10cSrcweir void importFieldGroup( const AttributeList& rAttribs ); 229cdf0e10cSrcweir /** Imports numeric grouping settings from the rangePr element. */ 230cdf0e10cSrcweir void importRangePr( const AttributeList& rAttribs ); 231cdf0e10cSrcweir /** Imports an item of the mapping between group items and base items from the passed element. */ 232cdf0e10cSrcweir void importDiscretePrItem( sal_Int32 nElement, const AttributeList& rAttribs ); 233cdf0e10cSrcweir /** Imports a group item from the passed element. */ 234cdf0e10cSrcweir void importGroupItem( sal_Int32 nElement, const AttributeList& rAttribs ); 235cdf0e10cSrcweir 236cdf0e10cSrcweir /** Imports pivot cache field settings from the PCDFIELD record. */ 237cdf0e10cSrcweir void importPCDField( SequenceInputStream& rStrm ); 238cdf0e10cSrcweir /** Imports shared items settings from the PCDFSHAREDITEMS record. */ 239cdf0e10cSrcweir void importPCDFSharedItems( SequenceInputStream& rStrm ); 240cdf0e10cSrcweir /** Imports one or more shared items from the passed record. */ 241cdf0e10cSrcweir void importPCDFSharedItem( sal_Int32 nRecId, SequenceInputStream& rStrm ); 242cdf0e10cSrcweir /** Imports grouping settings from the PCDFIELDGROUP record. */ 243cdf0e10cSrcweir void importPCDFieldGroup( SequenceInputStream& rStrm ); 244cdf0e10cSrcweir /** Imports numeric grouping settings from the PCDFRANGEPR record. */ 245cdf0e10cSrcweir void importPCDFRangePr( SequenceInputStream& rStrm ); 246cdf0e10cSrcweir /** Imports an item of the mapping between group items and base items from the passed record. */ 247cdf0e10cSrcweir void importPCDFDiscretePrItem( sal_Int32 nRecId, SequenceInputStream& rStrm ); 248cdf0e10cSrcweir /** Imports one or more group items from the passed record. */ 249cdf0e10cSrcweir void importPCDFGroupItem( sal_Int32 nRecId, SequenceInputStream& rStrm ); 250cdf0e10cSrcweir 251cdf0e10cSrcweir /** Imports pivot cache field settings from the PCDFIELD record. */ 252cdf0e10cSrcweir void importPCDField( BiffInputStream& rStrm ); 253cdf0e10cSrcweir /** Imports numeric grouping settings from the PCDFRANGEPR record. */ 254cdf0e10cSrcweir void importPCDFRangePr( BiffInputStream& rStrm ); 255cdf0e10cSrcweir /** Imports the mapping between group items and base items from the PCDFDISCRETEPR record. */ 256cdf0e10cSrcweir void importPCDFDiscretePr( BiffInputStream& rStrm ); 257cdf0e10cSrcweir 258cdf0e10cSrcweir /** Returns true, if the field is based on source data, or false if it is grouped or calculated. */ isDatabaseField() const259cdf0e10cSrcweir inline bool isDatabaseField() const { return maFieldModel.mbDatabaseField; } 260cdf0e10cSrcweir 261cdf0e10cSrcweir /** Returns true, if the field contains a list of shared items. */ hasSharedItems() const262cdf0e10cSrcweir inline bool hasSharedItems() const { return !maSharedItems.empty(); } 263cdf0e10cSrcweir /** Returns true, if the field contains a list of grouping items. */ hasGroupItems() const264cdf0e10cSrcweir inline bool hasGroupItems() const { return !maGroupItems.empty(); } 265cdf0e10cSrcweir /** Returns true, if the field has inplace numeric grouping settings. */ hasNumericGrouping() const266cdf0e10cSrcweir inline bool hasNumericGrouping() const { return maFieldGroupModel.mbRangeGroup && !maFieldGroupModel.mbDateGroup; } 267cdf0e10cSrcweir /** Returns true, if the field has inplace date grouping settings. */ hasDateGrouping() const268cdf0e10cSrcweir inline bool hasDateGrouping() const { return maFieldGroupModel.mbRangeGroup && maFieldGroupModel.mbDateGroup; } 269cdf0e10cSrcweir /** Returns true, if the field has a parent group field that groups the items of this field. */ hasParentGrouping() const270cdf0e10cSrcweir inline bool hasParentGrouping() const { return maFieldGroupModel.mnParentField >= 0; } 271cdf0e10cSrcweir 272cdf0e10cSrcweir /** Returns the name of the cache field. */ getName() const273cdf0e10cSrcweir inline const ::rtl::OUString& getName() const { return maFieldModel.maName; } 274cdf0e10cSrcweir /** Returns the index of the parent group field that groups the items of this field. */ getParentGroupField() const275cdf0e10cSrcweir inline sal_Int32 getParentGroupField() const { return maFieldGroupModel.mnParentField; } 276cdf0e10cSrcweir /** Returns the index of the base field grouping is based on. */ getGroupBaseField() const277cdf0e10cSrcweir inline sal_Int32 getGroupBaseField() const { return maFieldGroupModel.mnBaseField; } 278cdf0e10cSrcweir 279cdf0e10cSrcweir /** Returns the shared or group item with the specified index. */ 280cdf0e10cSrcweir const PivotCacheItem* getCacheItem( sal_Int32 nItemIdx ) const; 281cdf0e10cSrcweir /** Returns the names of all shared or group items. */ 282cdf0e10cSrcweir void getCacheItemNames( ::std::vector< ::rtl::OUString >& orItemNames ) const; 283cdf0e10cSrcweir 284cdf0e10cSrcweir /** Creates inplace numeric grouping settings. */ 285cdf0e10cSrcweir void convertNumericGrouping( 286cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotField >& rxDPField ) const; 287cdf0e10cSrcweir /** Creates inplace date grouping settings or a new date group field. */ 288cdf0e10cSrcweir ::rtl::OUString createDateGroupField( 289cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotField >& rxBaseDPField ) const; 290cdf0e10cSrcweir /** Creates a new grouped DataPilot field and returns its name. */ 291cdf0e10cSrcweir ::rtl::OUString createParentGroupField( 292cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotField >& rxBaseDPField, 293cdf0e10cSrcweir PivotCacheGroupItemVector& orItemNames ) const; 294cdf0e10cSrcweir 295cdf0e10cSrcweir /** Writes the title of the field into the passed sheet at the passed address. */ 296cdf0e10cSrcweir void writeSourceHeaderCell( WorksheetHelper& rSheetHelper, 297cdf0e10cSrcweir sal_Int32 nCol, sal_Int32 nRow ) const; 298cdf0e10cSrcweir /** Writes a source field item value into the passed sheet. */ 299cdf0e10cSrcweir void writeSourceDataCell( WorksheetHelper& rSheetHelper, 300cdf0e10cSrcweir sal_Int32 nCol, sal_Int32 nRow, 301cdf0e10cSrcweir const PivotCacheItem& rItem ) const; 302cdf0e10cSrcweir 303cdf0e10cSrcweir /** Reads an item from the PCRECORD record and writes it to the passed sheet. */ 304cdf0e10cSrcweir void importPCRecordItem( SequenceInputStream& rStrm, 305cdf0e10cSrcweir WorksheetHelper& rSheetHelper, sal_Int32 nCol, sal_Int32 nRow ) const; 306cdf0e10cSrcweir /** Reads an item index from the PCITEM_INDEXLIST record and writes the item to the passed sheet. */ 307cdf0e10cSrcweir void importPCItemIndex( BiffInputStream& rStrm, 308cdf0e10cSrcweir WorksheetHelper& rSheetHelper, sal_Int32 nCol, sal_Int32 nRow ) const; 309cdf0e10cSrcweir 310cdf0e10cSrcweir 311cdf0e10cSrcweir private: 312cdf0e10cSrcweir /** Tries to write the passed value to the passed sheet position. */ 313cdf0e10cSrcweir void writeItemToSourceDataCell( WorksheetHelper& rSheetHelper, 314cdf0e10cSrcweir sal_Int32 nCol, sal_Int32 nRow, const PivotCacheItem& rItem ) const; 315cdf0e10cSrcweir /** Tries to write the value of a shared item to the passed sheet position. */ 316cdf0e10cSrcweir void writeSharedItemToSourceDataCell( WorksheetHelper& rSheetHelper, 317cdf0e10cSrcweir sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nItemIdx ) const; 318cdf0e10cSrcweir 319cdf0e10cSrcweir private: 320cdf0e10cSrcweir typedef ::std::vector< sal_Int32 > IndexVector; 321cdf0e10cSrcweir 322cdf0e10cSrcweir PivotCacheItemList maSharedItems; /// All shared items of this field. 323cdf0e10cSrcweir PivotCacheItemList maGroupItems; /// All group items of this field. 324cdf0e10cSrcweir IndexVector maDiscreteItems; /// Mapping between group and base items. 325cdf0e10cSrcweir PCFieldModel maFieldModel; /// Settings for this cache field. 326cdf0e10cSrcweir PCSharedItemsModel maSharedItemsModel; /// Settings for shared items. 327cdf0e10cSrcweir PCFieldGroupModel maFieldGroupModel; /// Settings for item grouping. 328cdf0e10cSrcweir }; 329cdf0e10cSrcweir 330cdf0e10cSrcweir // ============================================================================ 331cdf0e10cSrcweir 332cdf0e10cSrcweir struct PCDefinitionModel 333cdf0e10cSrcweir { 334cdf0e10cSrcweir ::rtl::OUString maRelId; /// Relation identifier for cache records fragment. 335cdf0e10cSrcweir ::rtl::OUString maRefreshedBy; /// Name of user who last refreshed the cache. 336cdf0e10cSrcweir double mfRefreshedDate; /// Date/time of last refresh. 337cdf0e10cSrcweir sal_Int32 mnRecords; /// Number of data records in the cache. 338cdf0e10cSrcweir sal_Int32 mnMissItemsLimit; /// Limit for discarding unused items. 339cdf0e10cSrcweir sal_uInt16 mnDatabaseFields; /// Number of database (source data) fields (BIFF only). 340cdf0e10cSrcweir bool mbInvalid; /// True = cache needs refresh. 341cdf0e10cSrcweir bool mbSaveData; /// True = cached item values are present. 342cdf0e10cSrcweir bool mbRefreshOnLoad; /// True = try to refresh cache on load. 343cdf0e10cSrcweir bool mbOptimizeMemory; /// True = application may optimize memory usage. 344cdf0e10cSrcweir bool mbEnableRefresh; /// True = refreshing cache is enabled in UI. 345cdf0e10cSrcweir bool mbBackgroundQuery; /// True = application queries data asynchonously. 346cdf0e10cSrcweir bool mbUpgradeOnRefresh; /// True = application may upgrade cache version. 347cdf0e10cSrcweir bool mbTupleCache; /// True = cache stores OLAP functions. 348cdf0e10cSrcweir bool mbSupportSubquery; /// True = data source supports subqueries. 349cdf0e10cSrcweir bool mbSupportDrill; /// True = data source supports drilldown. 350cdf0e10cSrcweir 351cdf0e10cSrcweir explicit PCDefinitionModel(); 352cdf0e10cSrcweir }; 353cdf0e10cSrcweir 354cdf0e10cSrcweir // ---------------------------------------------------------------------------- 355cdf0e10cSrcweir 356cdf0e10cSrcweir struct PCSourceModel 357cdf0e10cSrcweir { 358cdf0e10cSrcweir sal_Int32 mnSourceType; /// Type of the source data (sheet, consolidation, scenario, external). 359cdf0e10cSrcweir sal_Int32 mnConnectionId; /// Connection identifier for external data source. 360cdf0e10cSrcweir 361cdf0e10cSrcweir explicit PCSourceModel(); 362cdf0e10cSrcweir }; 363cdf0e10cSrcweir 364cdf0e10cSrcweir // ---------------------------------------------------------------------------- 365cdf0e10cSrcweir 366cdf0e10cSrcweir struct PCWorksheetSourceModel 367cdf0e10cSrcweir { 368cdf0e10cSrcweir ::rtl::OUString maRelId; /// Relation identifier for an external document URL. 369cdf0e10cSrcweir ::rtl::OUString maSheet; /// Sheet name for cell range or sheet-local defined names. 370cdf0e10cSrcweir ::rtl::OUString maDefName; /// Defined name containing a cell range if present. 371cdf0e10cSrcweir ::com::sun::star::table::CellRangeAddress 372cdf0e10cSrcweir maRange; /// Source cell range of the data. 373cdf0e10cSrcweir 374cdf0e10cSrcweir explicit PCWorksheetSourceModel(); 375cdf0e10cSrcweir }; 376cdf0e10cSrcweir 377cdf0e10cSrcweir // ---------------------------------------------------------------------------- 378cdf0e10cSrcweir 379cdf0e10cSrcweir class PivotCache : public WorkbookHelper 380cdf0e10cSrcweir { 381cdf0e10cSrcweir public: 382cdf0e10cSrcweir explicit PivotCache( const WorkbookHelper& rHelper ); 383cdf0e10cSrcweir 384cdf0e10cSrcweir /** Reads pivot cache global settings from the pivotCacheDefinition element. */ 385cdf0e10cSrcweir void importPivotCacheDefinition( const AttributeList& rAttribs ); 386cdf0e10cSrcweir /** Reads cache source settings from the cacheSource element. */ 387cdf0e10cSrcweir void importCacheSource( const AttributeList& rAttribs ); 388cdf0e10cSrcweir /** Reads sheet source settings from the worksheetSource element. */ 389cdf0e10cSrcweir void importWorksheetSource( const AttributeList& rAttribs, const ::oox::core::Relations& rRelations ); 390cdf0e10cSrcweir 391cdf0e10cSrcweir /** Reads pivot cache global settings from the PCDEFINITION record. */ 392cdf0e10cSrcweir void importPCDefinition( SequenceInputStream& rStrm ); 393cdf0e10cSrcweir /** Reads cache source settings from the PCDSOURCE record. */ 394cdf0e10cSrcweir void importPCDSource( SequenceInputStream& rStrm ); 395cdf0e10cSrcweir /** Reads sheet source settings from the PCDSHEETSOURCE record. */ 396cdf0e10cSrcweir void importPCDSheetSource( SequenceInputStream& rStrm, const ::oox::core::Relations& rRelations ); 397cdf0e10cSrcweir 398cdf0e10cSrcweir /** Reads cache source settings from the PCDSOURCE record. */ 399cdf0e10cSrcweir void importPCDSource( BiffInputStream& rStrm ); 400cdf0e10cSrcweir /** Reads pivot cache global settings from the PCDEFINITION record. */ 401cdf0e10cSrcweir void importPCDefinition( BiffInputStream& rStrm ); 402cdf0e10cSrcweir 403cdf0e10cSrcweir /** Creates and returns a new pivot cache field. */ 404cdf0e10cSrcweir PivotCacheField& createCacheField( bool bInitDatabaseField = false ); 405cdf0e10cSrcweir /** Checks validity of source data and creates a dummy data sheet for external sheet sources. */ 406cdf0e10cSrcweir void finalizeImport(); 407cdf0e10cSrcweir 408cdf0e10cSrcweir /** Returns true, if the pivot cache is based on a valid data source, so 409cdf0e10cSrcweir that pivot tables can be created based on this pivot cache. */ isValidDataSource() const410cdf0e10cSrcweir inline bool isValidDataSource() const { return mbValidSource; } 411cdf0e10cSrcweir /** Returns true, if the pivot cache is based on a dummy sheet created in finalizeImport. */ isBasedOnDummySheet() const412cdf0e10cSrcweir inline bool isBasedOnDummySheet() const { return mbDummySheet; } 413cdf0e10cSrcweir /** Returns the internal cell range the cache is based on. */ 414cdf0e10cSrcweir inline const ::com::sun::star::table::CellRangeAddress& getSourceRange() const415cdf0e10cSrcweir getSourceRange() const { return maSheetSrcModel.maRange; } 416cdf0e10cSrcweir /** Returns the relation identifier of the pivot cache records fragment. */ getRecordsRelId() const417cdf0e10cSrcweir inline const ::rtl::OUString& getRecordsRelId() const { return maDefModel.maRelId; } 418cdf0e10cSrcweir 419cdf0e10cSrcweir /** Returns the number of pivot cache fields. */ 420cdf0e10cSrcweir sal_Int32 getCacheFieldCount() const; 421cdf0e10cSrcweir /** Returns the cache field with the specified index. */ 422cdf0e10cSrcweir const PivotCacheField* getCacheField( sal_Int32 nFieldIdx ) const; 423cdf0e10cSrcweir /** Returns the source column index of the field with the passed index. */ 424cdf0e10cSrcweir sal_Int32 getCacheDatabaseIndex( sal_Int32 nFieldIdx ) const; 425cdf0e10cSrcweir 426cdf0e10cSrcweir /** Writes the titles of all source fields into the passed sheet. */ 427cdf0e10cSrcweir void writeSourceHeaderCells( WorksheetHelper& rSheetHelper ) const; 428cdf0e10cSrcweir /** Writes a source field item value into the passed sheet. */ 429cdf0e10cSrcweir void writeSourceDataCell( WorksheetHelper& rSheetHelper, 430cdf0e10cSrcweir sal_Int32 nColIdx, sal_Int32 nRowIdx, 431cdf0e10cSrcweir const PivotCacheItem& rItem ) const; 432cdf0e10cSrcweir 433cdf0e10cSrcweir /** Reads a PCRECORD record and writes all item values to the passed sheet. */ 434cdf0e10cSrcweir void importPCRecord( SequenceInputStream& rStrm, 435cdf0e10cSrcweir WorksheetHelper& rSheetHelper, sal_Int32 nRowIdx ) const; 436cdf0e10cSrcweir /** Reads a PCITEM_INDEXLIST record and writes all item values to the passed sheet. */ 437cdf0e10cSrcweir void importPCItemIndexList( BiffInputStream& rStrm, 438cdf0e10cSrcweir WorksheetHelper& rSheetHelper, sal_Int32 nRowIdx ) const; 439cdf0e10cSrcweir 440cdf0e10cSrcweir private: 441cdf0e10cSrcweir /** Reads the worksheet source range from the DCONREF record. */ 442cdf0e10cSrcweir void importDConRef( BiffInputStream& rStrm ); 443cdf0e10cSrcweir /** Reads the defined name used for source data from the DCONNAME record. */ 444cdf0e10cSrcweir void importDConName( BiffInputStream& rStrm ); 445cdf0e10cSrcweir /** Reads the built-in defined name used for source data from the DCONBINAME record. */ 446cdf0e10cSrcweir void importDConBIName( BiffInputStream& rStrm ); 447cdf0e10cSrcweir /** Reads the sheet name and URL from the DCONREF, DCONNAME, or DCONBINAME records. */ 448cdf0e10cSrcweir void importDConUrl( BiffInputStream& rStrm ); 449cdf0e10cSrcweir 450cdf0e10cSrcweir /** Finalizes the pivot cache if it is based on internal sheet data. */ 451cdf0e10cSrcweir void finalizeInternalSheetSource(); 452cdf0e10cSrcweir /** Finalizes the pivot cache if it is based on sheet data of an external spreadsheet document. */ 453cdf0e10cSrcweir void finalizeExternalSheetSource(); 454cdf0e10cSrcweir /** Creates a dummy sheet that will be filled with the pivot cache data. */ 455cdf0e10cSrcweir void prepareSourceDataSheet(); 456cdf0e10cSrcweir /** Checks, if the row index has changed since last call, and initializes the sheet data buffer. */ 457cdf0e10cSrcweir void updateSourceDataRow( WorksheetHelper& rSheetHelper, sal_Int32 nRow ) const; 458cdf0e10cSrcweir 459cdf0e10cSrcweir private: 460cdf0e10cSrcweir typedef RefVector< PivotCacheField > PivotCacheFieldVector; 461cdf0e10cSrcweir typedef ::std::vector< sal_Int32 > IndexVector; 462cdf0e10cSrcweir 463cdf0e10cSrcweir PivotCacheFieldVector maFields; /// All pivot cache fields. 464cdf0e10cSrcweir PivotCacheFieldVector maDatabaseFields; /// All cache fields that are based on source data. 465cdf0e10cSrcweir IndexVector maDatabaseIndexes; /// Database field index for all fields. 466cdf0e10cSrcweir PCDefinitionModel maDefModel; /// Global pivot cache settings. 467cdf0e10cSrcweir PCSourceModel maSourceModel; /// Pivot cache source settings. 468cdf0e10cSrcweir PCWorksheetSourceModel maSheetSrcModel; /// Sheet source data if cache type is sheet. 469cdf0e10cSrcweir ValueRangeSet maColSpans; /// Column spans used by SheetDataBuffer for optimized cell import. 470cdf0e10cSrcweir ::rtl::OUString maTargetUrl; /// URL of an external source document. 471cdf0e10cSrcweir mutable sal_Int32 mnCurrRow; /// Current row index in dummy sheet. 472cdf0e10cSrcweir bool mbValidSource; /// True = pivot cache is based on supported data source. 473cdf0e10cSrcweir bool mbDummySheet; /// True = pivot cache is based on a dummy sheet. 474cdf0e10cSrcweir }; 475cdf0e10cSrcweir 476cdf0e10cSrcweir // ============================================================================ 477cdf0e10cSrcweir 478cdf0e10cSrcweir class PivotCacheBuffer : public WorkbookHelper 479cdf0e10cSrcweir { 480cdf0e10cSrcweir public: 481cdf0e10cSrcweir explicit PivotCacheBuffer( const WorkbookHelper& rHelper ); 482cdf0e10cSrcweir 483cdf0e10cSrcweir /** Registers a pivot cache definition fragment. The fragment will be loaded on demand (OOXML/BIFF12 only). */ 484cdf0e10cSrcweir void registerPivotCacheFragment( sal_Int32 nCacheId, const ::rtl::OUString& rFragmentPath ); 485cdf0e10cSrcweir /** Reads the reference to a pivot cache stream. The stream will be loaded on demand (BIFF2-BIFF8 only). */ 486cdf0e10cSrcweir void importPivotCacheRef( BiffInputStream& rStrm ); 487cdf0e10cSrcweir 488cdf0e10cSrcweir /** Imports and stores a pivot cache definition fragment on first call, 489cdf0e10cSrcweir returns the imported cache on subsequent calls with the same identifier. */ 490cdf0e10cSrcweir PivotCache* importPivotCacheFragment( sal_Int32 nCacheId ); 491cdf0e10cSrcweir 492cdf0e10cSrcweir private: 493cdf0e10cSrcweir /** Creates and returns a new pivot cache object with the passed identifier. */ 494cdf0e10cSrcweir PivotCache& createPivotCache( sal_Int32 nCacheId ); 495cdf0e10cSrcweir 496cdf0e10cSrcweir private: 497cdf0e10cSrcweir typedef ::std::map< sal_Int32, ::rtl::OUString > FragmentPathMap; 498cdf0e10cSrcweir typedef RefMap< sal_Int32, PivotCache > PivotCacheMap; 499cdf0e10cSrcweir typedef ::std::vector< sal_Int32 > PivotCacheIdVector; 500cdf0e10cSrcweir 501cdf0e10cSrcweir FragmentPathMap maFragmentPaths; 502cdf0e10cSrcweir PivotCacheMap maCaches; 503cdf0e10cSrcweir PivotCacheIdVector maCacheIds; 504cdf0e10cSrcweir }; 505cdf0e10cSrcweir 506cdf0e10cSrcweir // ============================================================================ 507cdf0e10cSrcweir 508cdf0e10cSrcweir } // namespace xls 509cdf0e10cSrcweir } // namespace oox 510cdf0e10cSrcweir 511cdf0e10cSrcweir #endif 512