1*38d50f7bSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*38d50f7bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*38d50f7bSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*38d50f7bSAndrew Rist * distributed with this work for additional information 6*38d50f7bSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*38d50f7bSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*38d50f7bSAndrew Rist * "License"); you may not use this file except in compliance 9*38d50f7bSAndrew Rist * with the License. You may obtain a copy of the License at 10*38d50f7bSAndrew Rist * 11*38d50f7bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*38d50f7bSAndrew Rist * 13*38d50f7bSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*38d50f7bSAndrew Rist * software distributed under the License is distributed on an 15*38d50f7bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*38d50f7bSAndrew Rist * KIND, either express or implied. See the License for the 17*38d50f7bSAndrew Rist * specific language governing permissions and limitations 18*38d50f7bSAndrew Rist * under the License. 19*38d50f7bSAndrew Rist * 20*38d50f7bSAndrew Rist *************************************************************/ 21*38d50f7bSAndrew Rist 22*38d50f7bSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SC_XEPIVOT_HXX 25cdf0e10cSrcweir #define SC_XEPIVOT_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <map> 28cdf0e10cSrcweir #include "xerecord.hxx" 29cdf0e10cSrcweir #include "xlpivot.hxx" 30cdf0e10cSrcweir #include "xeroot.hxx" 31cdf0e10cSrcweir 32cdf0e10cSrcweir class ScDPObject; 33cdf0e10cSrcweir class ScDPSaveData; 34cdf0e10cSrcweir class ScDPSaveDimension; 35cdf0e10cSrcweir class ScDPSaveMember; 36cdf0e10cSrcweir class ScDPDimensionSaveData; 37cdf0e10cSrcweir class ScDPSaveGroupDimension; 38cdf0e10cSrcweir class ScDPSaveNumGroupDimension; 39cdf0e10cSrcweir struct ScDPNumGroupInfo; 40cdf0e10cSrcweir 41cdf0e10cSrcweir // ============================================================================ 42cdf0e10cSrcweir // Pivot cache 43cdf0e10cSrcweir // ============================================================================ 44cdf0e10cSrcweir 45cdf0e10cSrcweir /** Represents a data item in a pivot cache containing data of any type. */ 46cdf0e10cSrcweir class XclExpPCItem : public XclExpRecord, public XclPCItem 47cdf0e10cSrcweir { 48cdf0e10cSrcweir public: 49cdf0e10cSrcweir explicit XclExpPCItem( const String& rText ); 50cdf0e10cSrcweir explicit XclExpPCItem( double fValue ); 51cdf0e10cSrcweir explicit XclExpPCItem( const DateTime& rDateTime ); 52cdf0e10cSrcweir explicit XclExpPCItem( sal_Int16 nValue ); 53cdf0e10cSrcweir explicit XclExpPCItem( bool bValue ); 54cdf0e10cSrcweir GetTypeFlag() const55cdf0e10cSrcweir inline sal_uInt16 GetTypeFlag() const { return mnTypeFlag; } 56cdf0e10cSrcweir 57cdf0e10cSrcweir bool EqualsText( const String& rText ) const; 58cdf0e10cSrcweir bool EqualsDouble( double fValue ) const; 59cdf0e10cSrcweir bool EqualsDateTime( const DateTime& rDateTime ) const; 60cdf0e10cSrcweir bool EqualsBool( bool bValue ) const; 61cdf0e10cSrcweir 62cdf0e10cSrcweir private: 63cdf0e10cSrcweir virtual void WriteBody( XclExpStream& rStrm ); 64cdf0e10cSrcweir 65cdf0e10cSrcweir private: 66cdf0e10cSrcweir sal_uInt16 mnTypeFlag; /// Data type flag. 67cdf0e10cSrcweir }; 68cdf0e10cSrcweir 69cdf0e10cSrcweir // ============================================================================ 70cdf0e10cSrcweir 71cdf0e10cSrcweir class XclExpPivotCache; 72cdf0e10cSrcweir 73cdf0e10cSrcweir class XclExpPCField : public XclExpRecord, public XclPCField, protected XclExpRoot 74cdf0e10cSrcweir { 75cdf0e10cSrcweir public: 76cdf0e10cSrcweir /** Creates a standard pivot cache field, filled from sheet source data. */ 77cdf0e10cSrcweir explicit XclExpPCField( const XclExpRoot& rRoot, 78cdf0e10cSrcweir const XclExpPivotCache& rPCache, sal_uInt16 nFieldIdx, 79cdf0e10cSrcweir const ScDPObject& rDPObj, const ScRange& rRange ); 80cdf0e10cSrcweir /** Creates a child grouping pivot cache field, filled from the passed grouping info. */ 81cdf0e10cSrcweir explicit XclExpPCField( const XclExpRoot& rRoot, 82cdf0e10cSrcweir const XclExpPivotCache& rPCache, sal_uInt16 nFieldIdx, 83cdf0e10cSrcweir const ScDPObject& rDPObj, const ScDPSaveGroupDimension& rGroupDim, 84cdf0e10cSrcweir const XclExpPCField& rBaseField ); 85cdf0e10cSrcweir virtual ~XclExpPCField(); 86cdf0e10cSrcweir 87cdf0e10cSrcweir /** Sets the passed field as direct grouping child field of this field. */ 88cdf0e10cSrcweir void SetGroupChildField( const XclExpPCField& rChildField ); 89cdf0e10cSrcweir /** Converts this standard field into a numeric grouping field. */ 90cdf0e10cSrcweir void ConvertToNumGroup( const ScDPObject& rDPObj, const ScDPSaveNumGroupDimension& rNumGroupDim ); 91cdf0e10cSrcweir 92cdf0e10cSrcweir /** Returns the name of this cache field. */ GetFieldName() const93cdf0e10cSrcweir inline const String& GetFieldName() const { return maFieldInfo.maName; } 94cdf0e10cSrcweir 95cdf0e10cSrcweir /** Returns the number of visible items of this field. */ 96cdf0e10cSrcweir sal_uInt16 GetItemCount() const; 97cdf0e10cSrcweir /** Returns the specified pivot cache item (returns visible items in groupings). */ 98cdf0e10cSrcweir const XclExpPCItem* GetItem( sal_uInt16 nItemIdx ) const; 99cdf0e10cSrcweir /** Returns the index of a pivot cache item, or EXC_PC_NOITEM on error. */ 100cdf0e10cSrcweir sal_uInt16 GetItemIndex( const String& rItemName ) const; 101cdf0e10cSrcweir 102cdf0e10cSrcweir /** Returns the size an item index needs to write out. */ 103cdf0e10cSrcweir sal_Size GetIndexSize() const; 104cdf0e10cSrcweir /** Writes the item index at the passed source row position as part of the SXINDEXLIST record. */ 105cdf0e10cSrcweir void WriteIndex( XclExpStream& rStrm, sal_uInt32 nSrcRow ) const; 106cdf0e10cSrcweir 107cdf0e10cSrcweir /** Writes the pivot cache field and all items and other related records. */ 108cdf0e10cSrcweir virtual void Save( XclExpStream& rStrm ); 109cdf0e10cSrcweir 110cdf0e10cSrcweir private: 111cdf0e10cSrcweir typedef XclExpRecordList< XclExpPCItem > XclExpPCItemList; 112cdf0e10cSrcweir 113cdf0e10cSrcweir /** Returns the item list that contains the visible items. 114cdf0e10cSrcweir @descr Visible items are equal to source items in standard fields, 115cdf0e10cSrcweir but are generated items in grouping and calculated fields. */ 116cdf0e10cSrcweir const XclExpPCItemList& GetVisItemList() const; 117cdf0e10cSrcweir 118cdf0e10cSrcweir /** Initializes a standard field. Inserts all original source items. */ 119cdf0e10cSrcweir void InitStandardField( const ScRange& rRange ); 120cdf0e10cSrcweir /** Initializes a standard grouping field. Inserts all visible grouping items. */ 121cdf0e10cSrcweir void InitStdGroupField( const XclExpPCField& rBaseField, const ScDPSaveGroupDimension& rGroupDim ); 122cdf0e10cSrcweir /** Initializes a numeric grouping field. Inserts all visible grouping items and the limit settings. */ 123cdf0e10cSrcweir void InitNumGroupField( const ScDPObject& rDPObj, const ScDPNumGroupInfo& rNumInfo ); 124cdf0e10cSrcweir /** Initializes a date grouping field. Inserts all visible grouping items and the limit settings. */ 125cdf0e10cSrcweir void InitDateGroupField( const ScDPObject& rDPObj, const ScDPNumGroupInfo& rDateInfo, sal_Int32 nDatePart ); 126cdf0e10cSrcweir 127cdf0e10cSrcweir /** Inserts the passed index into the item index array of original items. */ 128cdf0e10cSrcweir void InsertItemArrayIndex( size_t nListPos ); 129cdf0e10cSrcweir /** Inserts an original source item. Updates item index array. */ 130cdf0e10cSrcweir void InsertOrigItem( XclExpPCItem* pNewItem ); 131cdf0e10cSrcweir /** Inserts an original text item, if it is not contained already. */ 132cdf0e10cSrcweir void InsertOrigTextItem( const String& rText ); 133cdf0e10cSrcweir /** Inserts an original value item, if it is not contained already. */ 134cdf0e10cSrcweir void InsertOrigDoubleItem( double fValue ); 135cdf0e10cSrcweir /** Inserts an original date/time item, if it is not contained already. */ 136cdf0e10cSrcweir void InsertOrigDateTimeItem( const DateTime& rDateTime ); 137cdf0e10cSrcweir /** Inserts an original boolean item, if it is not contained already. */ 138cdf0e10cSrcweir void InsertOrigBoolItem( bool bValue ); 139cdf0e10cSrcweir 140cdf0e10cSrcweir /** Inserts an item into the grouping item list. Does not change anything else. 141cdf0e10cSrcweir @return The list index of the new item. */ 142cdf0e10cSrcweir sal_uInt16 InsertGroupItem( XclExpPCItem* pNewItem ); 143cdf0e10cSrcweir /** Generates and inserts all visible items for numeric or date grouping. */ 144cdf0e10cSrcweir void InsertNumDateGroupItems( const ScDPObject& rDPObj, const ScDPNumGroupInfo& rNumInfo, sal_Int32 nDatePart = 0 ); 145cdf0e10cSrcweir 146cdf0e10cSrcweir /** Inserts the SXDOUBLE items that specify the limits for a numeric grouping. */ 147cdf0e10cSrcweir void SetNumGroupLimit( const ScDPNumGroupInfo& rNumInfo ); 148cdf0e10cSrcweir /** Inserts the SXDATETIME/SXINTEGER items that specify the limits for a date grouping. 149cdf0e10cSrcweir @param bUseStep true = Insert the passed step value; false = always insert 1. */ 150cdf0e10cSrcweir void SetDateGroupLimit( const ScDPNumGroupInfo& rDateInfo, bool bUseStep ); 151cdf0e10cSrcweir 152cdf0e10cSrcweir /** Initializes flags and item count fields. */ 153cdf0e10cSrcweir void Finalize(); 154cdf0e10cSrcweir 155cdf0e10cSrcweir /** Writes an SXNUMGROUP record and the additional items for a numeric grouping field. */ 156cdf0e10cSrcweir void WriteSxnumgroup( XclExpStream& rStrm ); 157cdf0e10cSrcweir /** Writes an SXGROUPINFO record describing the item order in grouping fields. */ 158cdf0e10cSrcweir void WriteSxgroupinfo( XclExpStream& rStrm ); 159cdf0e10cSrcweir 160cdf0e10cSrcweir /** Writes the contents of the SXFIELD record for this field. */ 161cdf0e10cSrcweir virtual void WriteBody( XclExpStream& rStrm ); 162cdf0e10cSrcweir 163cdf0e10cSrcweir private: 164cdf0e10cSrcweir const XclExpPivotCache& mrPCache; /// Parent pivot cache containing this field. 165cdf0e10cSrcweir XclExpPCItemList maOrigItemList; /// List with original items. 166cdf0e10cSrcweir XclExpPCItemList maGroupItemList; /// List with grouping items. 167cdf0e10cSrcweir ScfUInt16Vec maIndexVec; /// Indexes into maItemList. 168cdf0e10cSrcweir XclExpPCItemList maNumGroupLimits; /// List with limit values for numeric grouping. 169cdf0e10cSrcweir sal_uInt16 mnTypeFlags; /// Collected item data type flags. 170cdf0e10cSrcweir }; 171cdf0e10cSrcweir 172cdf0e10cSrcweir // ============================================================================ 173cdf0e10cSrcweir 174cdf0e10cSrcweir class XclExpPivotCache : protected XclExpRoot 175cdf0e10cSrcweir { 176cdf0e10cSrcweir public: 177cdf0e10cSrcweir explicit XclExpPivotCache( const XclExpRoot& rRoot, 178cdf0e10cSrcweir const ScDPObject& rDPObj, sal_uInt16 nListIdx ); 179cdf0e10cSrcweir 180cdf0e10cSrcweir /** Returns true, if the cache has been constructed successfully. */ IsValid() const181cdf0e10cSrcweir inline bool IsValid() const { return mbValid; } 182cdf0e10cSrcweir /** Returns true, if the item index list will be written. */ 183cdf0e10cSrcweir bool HasItemIndexList() const; 184cdf0e10cSrcweir 185cdf0e10cSrcweir /** Returns the stream identifier used to create the cache stream. */ GetStreamId() const186cdf0e10cSrcweir inline sal_uInt16 GetStreamId() const { return maPCInfo.mnStrmId; } 187cdf0e10cSrcweir /** Returns the list index of the cache used in pivot table records. */ GetCacheIndex() const188cdf0e10cSrcweir inline sal_uInt16 GetCacheIndex() const { return mnListIdx; } 189cdf0e10cSrcweir 190cdf0e10cSrcweir /** Returns the number of pivot cache fields. */ 191cdf0e10cSrcweir sal_uInt16 GetFieldCount() const; 192cdf0e10cSrcweir /** Returns the specified pivot cache field. */ 193cdf0e10cSrcweir const XclExpPCField* GetField( sal_uInt16 nFieldIdx ) const; 194cdf0e10cSrcweir //UNUSED2009-05 /** Returns a pivot cache field by its name. */ 195cdf0e10cSrcweir //UNUSED2009-05 const XclExpPCField* GetField( const String& rFieldName ) const; 196cdf0e10cSrcweir /** Returns true, if this pivot cache contains non-standard fields (e.g. grouping fields). */ 197cdf0e10cSrcweir bool HasAddFields() const; 198cdf0e10cSrcweir 199cdf0e10cSrcweir /** Returns true, if the passed DP object has the same data source as this cache. */ 200cdf0e10cSrcweir bool HasEqualDataSource( const ScDPObject& rDPObj ) const; 201cdf0e10cSrcweir 202cdf0e10cSrcweir /** Writes related records into Workbook stream and creates the pivot cache storage stream. */ 203cdf0e10cSrcweir virtual void Save( XclExpStream& rStrm ); 204cdf0e10cSrcweir virtual void SaveXml( XclExpXmlStream& rStrm ); 205cdf0e10cSrcweir 206cdf0e10cSrcweir private: 207cdf0e10cSrcweir /** Returns read/write access to a pivot cache field. */ 208cdf0e10cSrcweir XclExpPCField* GetFieldAcc( sal_uInt16 nFieldIdx ); 209cdf0e10cSrcweir /** Returns read/write access to a pivot cache field. */ 210cdf0e10cSrcweir XclExpPCField* GetFieldAcc( const String& rFieldName ); 211cdf0e10cSrcweir 212cdf0e10cSrcweir /** Adds all pivot cache fields. */ 213cdf0e10cSrcweir void AddFields( const ScDPObject& rDPObj ); 214cdf0e10cSrcweir 215cdf0e10cSrcweir /** Adds all standard pivot cache fields based on source data. */ 216cdf0e10cSrcweir void AddStdFields( const ScDPObject& rDPObj ); 217cdf0e10cSrcweir /** Adds all grouping pivot cache fields. */ 218cdf0e10cSrcweir void AddGroupFields( const ScDPObject& rDPObj ); 219cdf0e10cSrcweir /** Adds all calculated pivot cache fields. */ 220cdf0e10cSrcweir void AddCalcFields( const ScDPObject& rDPObj ); 221cdf0e10cSrcweir 222cdf0e10cSrcweir /** Writes the DCONREF record containing the source range. */ 223cdf0e10cSrcweir void WriteDconref( XclExpStream& rStrm ) const; 224cdf0e10cSrcweir 225cdf0e10cSrcweir /** Creates the pivot cache storage stream and writes the cache. */ 226cdf0e10cSrcweir void WriteCacheStream(); 227cdf0e10cSrcweir /** Writes the SXDB record. */ 228cdf0e10cSrcweir void WriteSxdb( XclExpStream& rStrm ) const; 229cdf0e10cSrcweir /** Writes the SXDBEX record. */ 230cdf0e10cSrcweir void WriteSxdbex( XclExpStream& rStrm ) const; 231cdf0e10cSrcweir /** Writes the SXINDEXLIST record list containing the item index table. */ 232cdf0e10cSrcweir void WriteSxindexlistList( XclExpStream& rStrm ) const; 233cdf0e10cSrcweir 234cdf0e10cSrcweir private: 235cdf0e10cSrcweir typedef XclExpRecordList< XclExpPCField > XclExpPCFieldList; 236cdf0e10cSrcweir typedef XclExpPCFieldList::RecordRefType XclExpPCFieldRef; 237cdf0e10cSrcweir 238cdf0e10cSrcweir XclPCInfo maPCInfo; /// Pivot cache settings (SXDB record). 239cdf0e10cSrcweir XclExpPCFieldList maFieldList; /// List of all pivot cache fields. 240cdf0e10cSrcweir String maTabName; /// Name of source data sheet. 241cdf0e10cSrcweir ScRange maOrigSrcRange; /// The original sheet source range. 242cdf0e10cSrcweir ScRange maExpSrcRange; /// The exported sheet source range. 243cdf0e10cSrcweir ScRange maDocSrcRange; /// The range used to build the cache fields and items. 244cdf0e10cSrcweir sal_uInt16 mnListIdx; /// List index in pivot cache buffer. 245cdf0e10cSrcweir bool mbValid; /// true = The cache is valid for export. 246cdf0e10cSrcweir }; 247cdf0e10cSrcweir 248cdf0e10cSrcweir // ============================================================================ 249cdf0e10cSrcweir // Pivot table 250cdf0e10cSrcweir // ============================================================================ 251cdf0e10cSrcweir 252cdf0e10cSrcweir class XclExpPivotTable; 253cdf0e10cSrcweir 254cdf0e10cSrcweir /** Data field position specifying the pivot table field index (first) and data info index (second). */ 255cdf0e10cSrcweir typedef ::std::pair< sal_uInt16, sal_uInt16 > XclPTDataFieldPos; 256cdf0e10cSrcweir 257cdf0e10cSrcweir // ============================================================================ 258cdf0e10cSrcweir 259cdf0e10cSrcweir class XclExpPTItem : public XclExpRecord 260cdf0e10cSrcweir { 261cdf0e10cSrcweir public: 262cdf0e10cSrcweir explicit XclExpPTItem( const XclExpPCField& rCacheField, sal_uInt16 nCacheIdx ); 263cdf0e10cSrcweir explicit XclExpPTItem( sal_uInt16 nItemType, sal_uInt16 nCacheIdx, bool bUseCache ); 264cdf0e10cSrcweir 265cdf0e10cSrcweir /** Returns the internal name of this item. */ 266cdf0e10cSrcweir const String& GetItemName() const; 267cdf0e10cSrcweir 268cdf0e10cSrcweir /** Fills this item with properties from the passed save member. */ 269cdf0e10cSrcweir void SetPropertiesFromMember( const ScDPSaveMember& rSaveMem ); 270cdf0e10cSrcweir 271cdf0e10cSrcweir private: 272cdf0e10cSrcweir /** Writes the SXVI record body describing the pivot table item. */ 273cdf0e10cSrcweir virtual void WriteBody( XclExpStream& rStrm ); 274cdf0e10cSrcweir 275cdf0e10cSrcweir private: 276cdf0e10cSrcweir const XclExpPCItem* mpCacheItem; /// The referred pivot cache item. 277cdf0e10cSrcweir XclPTItemInfo maItemInfo; /// General data for this item. 278cdf0e10cSrcweir }; 279cdf0e10cSrcweir 280cdf0e10cSrcweir // ============================================================================ 281cdf0e10cSrcweir 282cdf0e10cSrcweir class XclExpPTField : public XclExpRecordBase 283cdf0e10cSrcweir { 284cdf0e10cSrcweir public: 285cdf0e10cSrcweir explicit XclExpPTField( const XclExpPivotTable& rPTable, sal_uInt16 nCacheIdx ); 286cdf0e10cSrcweir 287cdf0e10cSrcweir // data access ------------------------------------------------------------ 288cdf0e10cSrcweir 289cdf0e10cSrcweir /** Returns the name of this field. */ 290cdf0e10cSrcweir const String& GetFieldName() const; 291cdf0e10cSrcweir /** Returns the pivot table field list index of this field. */ 292cdf0e10cSrcweir sal_uInt16 GetFieldIndex() const; 293cdf0e10cSrcweir 294cdf0e10cSrcweir /** Returns the index of the last inserted data info struct. */ 295cdf0e10cSrcweir sal_uInt16 GetLastDataInfoIndex() const; 296cdf0e10cSrcweir 297cdf0e10cSrcweir //UNUSED2009-05 /** Returns an item by its name. */ 298cdf0e10cSrcweir //UNUSED2009-05 const XclExpPTItem* GetItem( const String& rName ) const; 299cdf0e10cSrcweir /** Returns the list index of an item by its name. 300cdf0e10cSrcweir @param nDefaultIdx This value will be returned, if the item could not be found. */ 301cdf0e10cSrcweir sal_uInt16 GetItemIndex( const String& rName, sal_uInt16 nDefaultIdx ) const; 302cdf0e10cSrcweir 303cdf0e10cSrcweir // fill data -------------------------------------------------------------- 304cdf0e10cSrcweir 305cdf0e10cSrcweir /** Fills this field with row/column/page properties from the passed save dimension. */ 306cdf0e10cSrcweir void SetPropertiesFromDim( const ScDPSaveDimension& rSaveDim ); 307cdf0e10cSrcweir /** Fills this field with data field properties from the passed save dimension. */ 308cdf0e10cSrcweir void SetDataPropertiesFromDim( const ScDPSaveDimension& rSaveDim ); 309cdf0e10cSrcweir 310cdf0e10cSrcweir /** Appends special items describing the field subtotal entries. */ 311cdf0e10cSrcweir void AppendSubtotalItems(); 312cdf0e10cSrcweir 313cdf0e10cSrcweir // records ---------------------------------------------------------------- 314cdf0e10cSrcweir 315cdf0e10cSrcweir /** Writes an entry for an SXPI record containing own page field info. */ 316cdf0e10cSrcweir void WriteSxpiEntry( XclExpStream& rStrm ) const; 317cdf0e10cSrcweir /** Writes an SXDI records containing info about a data field. */ 318cdf0e10cSrcweir void WriteSxdi( XclExpStream& rStrm, sal_uInt16 nDataInfoIdx ) const; 319cdf0e10cSrcweir 320cdf0e10cSrcweir /** Writes the entire pivot table field. */ 321cdf0e10cSrcweir virtual void Save( XclExpStream& rStrm ); 322cdf0e10cSrcweir 323cdf0e10cSrcweir // ------------------------------------------------------------------------ 324cdf0e10cSrcweir private: 325cdf0e10cSrcweir /** Returns an item by its name. */ 326cdf0e10cSrcweir XclExpPTItem* GetItemAcc( const String& rName ); 327cdf0e10cSrcweir 328cdf0e10cSrcweir /** Appends a special item describing a field subtotal entry. */ 329cdf0e10cSrcweir void AppendSubtotalItem( sal_uInt16 nItemType ); 330cdf0e10cSrcweir 331cdf0e10cSrcweir /** Writes the SXVD record introducing the field. */ 332cdf0e10cSrcweir void WriteSxvd( XclExpStream& rStrm ) const; 333cdf0e10cSrcweir /** Writes the SXVDEX record containing additional settings. */ 334cdf0e10cSrcweir void WriteSxvdex( XclExpStream& rStrm ) const; 335cdf0e10cSrcweir 336cdf0e10cSrcweir private: 337cdf0e10cSrcweir typedef ::std::vector< XclPTDataFieldInfo > XclPTDataFieldInfoVec; 338cdf0e10cSrcweir typedef XclExpRecordList< XclExpPTItem > XclExpPTItemList; 339cdf0e10cSrcweir 340cdf0e10cSrcweir const XclExpPivotTable& mrPTable; /// Parent pivot table containing this field. 341cdf0e10cSrcweir const XclExpPCField* mpCacheField; /// The referred pivot cache field. 342cdf0e10cSrcweir XclPTFieldInfo maFieldInfo; /// General field info (SXVD record). 343cdf0e10cSrcweir XclPTFieldExtInfo maFieldExtInfo; /// Extended field info (SXVDEX record). 344cdf0e10cSrcweir XclPTPageFieldInfo maPageInfo; /// Page field info (entry in SXPI record). 345cdf0e10cSrcweir XclPTDataFieldInfoVec maDataInfoVec; /// List of extended data field info (SXDI records). 346cdf0e10cSrcweir XclExpPTItemList maItemList; /// List of all items of this field. 347cdf0e10cSrcweir }; 348cdf0e10cSrcweir 349cdf0e10cSrcweir // ============================================================================ 350cdf0e10cSrcweir 351cdf0e10cSrcweir class XclExpPivotTable : public XclExpRecordBase, protected XclExpRoot 352cdf0e10cSrcweir { 353cdf0e10cSrcweir public: 354cdf0e10cSrcweir explicit XclExpPivotTable( const XclExpRoot& rRoot, 355cdf0e10cSrcweir const ScDPObject& rDPObj, const XclExpPivotCache& rPCache ); 356cdf0e10cSrcweir 357cdf0e10cSrcweir /** Returns a pivot cache field. */ 358cdf0e10cSrcweir const XclExpPCField* GetCacheField( sal_uInt16 nCacheIdx ) const; 359cdf0e10cSrcweir 360cdf0e10cSrcweir /** Returns the output range of the pivot table. */ GetScTab() const361cdf0e10cSrcweir inline SCTAB GetScTab() const { return mnOutScTab; } 362cdf0e10cSrcweir 363cdf0e10cSrcweir /** Returns a pivot table field by its name. */ 364cdf0e10cSrcweir const XclExpPTField* GetField( sal_uInt16 nFieldIdx ) const; 365cdf0e10cSrcweir /** Returns a pivot table field by its name. */ 366cdf0e10cSrcweir const XclExpPTField* GetField( const String& rName ) const; 367cdf0e10cSrcweir 368cdf0e10cSrcweir /** Returns the data-field-only index of the first data field with the passed name. 369cdf0e10cSrcweir @param nDefaultIdx This value will be returned, if the field could not be found. */ 370cdf0e10cSrcweir sal_uInt16 GetDataFieldIndex( const String& rName, sal_uInt16 nDefaultIdx ) const; 371cdf0e10cSrcweir 372cdf0e10cSrcweir /** Writes the entire pivot table. */ 373cdf0e10cSrcweir virtual void Save( XclExpStream& rStrm ); 374cdf0e10cSrcweir 375cdf0e10cSrcweir // ------------------------------------------------------------------------ 376cdf0e10cSrcweir private: 377cdf0e10cSrcweir /** Returns a pivot table field by its name. */ 378cdf0e10cSrcweir XclExpPTField* GetFieldAcc( const String& rName ); 379cdf0e10cSrcweir /** Returns a pivot table field corresponding to the passed save dimension. */ 380cdf0e10cSrcweir XclExpPTField* GetFieldAcc( const ScDPSaveDimension& rSaveDim ); 381cdf0e10cSrcweir 382cdf0e10cSrcweir // fill data -------------------------------------------------------------- 383cdf0e10cSrcweir 384cdf0e10cSrcweir /** Fills internal members with all properties from the passed save data. */ 385cdf0e10cSrcweir void SetPropertiesFromDP( const ScDPSaveData& rSaveData ); 386cdf0e10cSrcweir /** Fills a pivot table field with all properties from the passed save dimension. */ 387cdf0e10cSrcweir void SetFieldPropertiesFromDim( const ScDPSaveDimension& rSaveDim ); 388cdf0e10cSrcweir /** Fills a pivot table data field with all properties from the passed save dimension. */ 389cdf0e10cSrcweir void SetDataFieldPropertiesFromDim( const ScDPSaveDimension& rSaveDim ); 390cdf0e10cSrcweir 391cdf0e10cSrcweir /** Initializes any data after processing the entire source DataPilot. */ 392cdf0e10cSrcweir void Finalize(); 393cdf0e10cSrcweir 394cdf0e10cSrcweir // records ---------------------------------------------------------------- 395cdf0e10cSrcweir 396cdf0e10cSrcweir /** Writes the SXVIEW record starting the pivot table. */ 397cdf0e10cSrcweir void WriteSxview( XclExpStream& rStrm ) const; 398cdf0e10cSrcweir /** Writes an SXIVD record for row field or column field order. */ 399cdf0e10cSrcweir void WriteSxivd( XclExpStream& rStrm, const ScfUInt16Vec& rFields ) const; 400cdf0e10cSrcweir /** Writes the SXPI record containing page field info. */ 401cdf0e10cSrcweir void WriteSxpi( XclExpStream& rStrm ) const; 402cdf0e10cSrcweir /** Writes all SXDI records containing info about the data fields. */ 403cdf0e10cSrcweir void WriteSxdiList( XclExpStream& rStrm ) const; 404cdf0e10cSrcweir /** Writes a dummy SXLI records containing item layout info. */ 405cdf0e10cSrcweir void WriteSxli( XclExpStream& rStrm, sal_uInt16 nLineCount, sal_uInt16 nIndexCount ) const; 406cdf0e10cSrcweir /** Writes the SXEX records containing additional pivot table info. */ 407cdf0e10cSrcweir void WriteSxex( XclExpStream& rStrm ) const; 408cdf0e10cSrcweir 409cdf0e10cSrcweir void WriteQsiSxTag( XclExpStream& rStrm ) const; 410cdf0e10cSrcweir /** Writes the SX_AUTOFORMAT records with the autoformat id and header layout */ 411cdf0e10cSrcweir void WriteSxViewEx9( XclExpStream& rStrm ) const; 412cdf0e10cSrcweir 413cdf0e10cSrcweir // ------------------------------------------------------------------------ 414cdf0e10cSrcweir private: 415cdf0e10cSrcweir typedef XclExpRecordList< XclExpPTField > XclExpPTFieldList; 416cdf0e10cSrcweir typedef XclExpPTFieldList::RecordRefType XclExpPTFieldRef; 417cdf0e10cSrcweir typedef ::std::vector< XclPTDataFieldPos > XclPTDataFieldPosVec; 418cdf0e10cSrcweir 419cdf0e10cSrcweir const XclExpPivotCache& mrPCache; /// The pivot cache this pivot table bases on. 420cdf0e10cSrcweir XclPTInfo maPTInfo; /// Info about the pivot table (SXVIEW record). 421cdf0e10cSrcweir XclPTExtInfo maPTExtInfo; /// Extended info about the pivot table (SXEX record). 422cdf0e10cSrcweir XclPTViewEx9Info maPTViewEx9Info; /// The selected autoformat (SXVIEWEX9) 423cdf0e10cSrcweir XclExpPTFieldList maFieldList; /// All fields in pivot cache order. 424cdf0e10cSrcweir ScfUInt16Vec maRowFields; /// Row field indexes. 425cdf0e10cSrcweir ScfUInt16Vec maColFields; /// Column field indexes. 426cdf0e10cSrcweir ScfUInt16Vec maPageFields; /// Page field indexes. 427cdf0e10cSrcweir XclPTDataFieldPosVec maDataFields; /// Data field indexes. 428cdf0e10cSrcweir XclExpPTField maDataOrientField; /// Special data field orientation field. 429cdf0e10cSrcweir SCTAB mnOutScTab; /// Sheet index of the output range. 430cdf0e10cSrcweir bool mbValid; /// true = The pivot table is valid for export. 431cdf0e10cSrcweir bool mbFilterBtn; /// true = DataPilot has filter button. 432cdf0e10cSrcweir }; 433cdf0e10cSrcweir 434cdf0e10cSrcweir // ============================================================================ 435cdf0e10cSrcweir 436cdf0e10cSrcweir /** The main class for pivot table export. 437cdf0e10cSrcweir 438cdf0e10cSrcweir This class contains all pivot caches and pivot tables in a Calc document. 439cdf0e10cSrcweir It creates the pivot cache streams and pivot table records in the main 440cdf0e10cSrcweir workbook stream. It supports sharing of pivot caches between multiple pivot 441cdf0e10cSrcweir tables to decrease file size. 442cdf0e10cSrcweir */ 443cdf0e10cSrcweir class XclExpPivotTableManager : protected XclExpRoot 444cdf0e10cSrcweir { 445cdf0e10cSrcweir public: 446cdf0e10cSrcweir explicit XclExpPivotTableManager( const XclExpRoot& rRoot ); 447cdf0e10cSrcweir 448cdf0e10cSrcweir /** Creates all pivot tables and caches from the Calc DataPilot objects. */ 449cdf0e10cSrcweir void CreatePivotTables(); 450cdf0e10cSrcweir 451cdf0e10cSrcweir /** Creates a record wrapper for exporting all pivot caches. */ 452cdf0e10cSrcweir XclExpRecordRef CreatePivotCachesRecord(); 453cdf0e10cSrcweir /** Creates a record wrapper for exporting all pivot tables of the specified sheet. */ 454cdf0e10cSrcweir XclExpRecordRef CreatePivotTablesRecord( SCTAB nScTab ); 455cdf0e10cSrcweir 456cdf0e10cSrcweir /** Writes all pivot caches (all Workbook records and cache streams). */ 457cdf0e10cSrcweir void WritePivotCaches( XclExpStream& rStrm ); 458cdf0e10cSrcweir void WritePivotCachesXml( XclExpXmlStream& rStrm ); 459cdf0e10cSrcweir /** Writes all pivot tables of the specified Calc sheet. */ 460cdf0e10cSrcweir void WritePivotTables( XclExpStream& rStrm, SCTAB nScTab ); 461cdf0e10cSrcweir void WritePivotTablesXml( XclExpXmlStream& rStrm, SCTAB nScTab ); 462cdf0e10cSrcweir 463cdf0e10cSrcweir private: 464cdf0e10cSrcweir /** Finds an existing (if enabled in mbShareCaches) or creates a new pivot cache. 465cdf0e10cSrcweir @return Pointer to the pivot cache or 0, if the passed source range was invalid. */ 466cdf0e10cSrcweir const XclExpPivotCache* CreatePivotCache( const ScDPObject& rDPObj ); 467cdf0e10cSrcweir 468cdf0e10cSrcweir private: 469cdf0e10cSrcweir typedef XclExpRecordList< XclExpPivotCache > XclExpPivotCacheList; 470cdf0e10cSrcweir typedef XclExpPivotCacheList::RecordRefType XclExpPivotCacheRef; 471cdf0e10cSrcweir typedef XclExpRecordList< XclExpPivotTable > XclExpPivotTableList; 472cdf0e10cSrcweir typedef XclExpPivotTableList::RecordRefType XclExpPivotTableRef; 473cdf0e10cSrcweir 474cdf0e10cSrcweir XclExpPivotCacheList maPCacheList; /// List of all pivot caches. 475cdf0e10cSrcweir XclExpPivotTableList maPTableList; /// List of all pivot tables. 476cdf0e10cSrcweir bool mbShareCaches; /// true = Tries to share caches between tables. 477cdf0e10cSrcweir }; 478cdf0e10cSrcweir 479cdf0e10cSrcweir // ============================================================================ 480cdf0e10cSrcweir 481cdf0e10cSrcweir #endif 482cdf0e10cSrcweir 483