Index: excel/read.cxx =================================================================== --- excel/read.cxx (revision 1381941) +++ excel/read.cxx (working copy) @@ -19,13 +19,9 @@ * *************************************************************/ - - // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_sc.hxx" - - //------------------------------------------------------------------------ #include @@ -1017,7 +1013,7 @@ { rNumFmtBfr.CreateScFormats(); rXFBfr.CreateUserStyles(); - rPTableMgr.ReadPivotCaches( maStrm ); + //rPTableMgr.ReadPivotCaches( maStrm ); eAkt = EXC_STATE_BEFORE_SHEET; } break; @@ -1203,8 +1199,15 @@ // #i45843# Convert pivot tables before calculation, so they are available // for the GETPIVOTDATA function. if( GetBiff() == EXC_BIFF8 ) - GetPivotTableManager().ConvertPivotTables(); +// GetPivotTableManager().ConvertPivotTables(); + { + SCTAB nTabCount = GetDoc().GetTableCount(); + GetPivotTableManager().ConvertPivotTables( maStrm ); + + for( SCTAB nDummyTab = GetDoc().GetTableCount() - 1; nDummyTab >= nTabCount; nDummyTab-- ) + GetDoc().DeleteTab( nDummyTab ); + } pProgress.reset(); if (pD->IsAdjustHeightEnabled()) @@ -1226,8 +1229,9 @@ else if( rAddrConv.IsColTruncated() ) eLastErr = SCWARN_IMPORT_COLUMN_OVERFLOW; - if( GetBiff() == EXC_BIFF8 ) - GetPivotTableManager().MaybeRefreshPivotTables(); +// Refreshing pivot tables moves to the end of converting every table +// if( GetBiff() == EXC_BIFF8 ) +// GetPivotTableManager().MaybeRefreshPivotTables(); } return eLastErr; Index: excel/xipivot.cxx =================================================================== --- excel/xipivot.cxx (revision 1381941) +++ excel/xipivot.cxx (working copy) @@ -19,8 +19,6 @@ * *************************************************************/ - - // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_sc.hxx" @@ -1420,6 +1418,8 @@ mpDPObj = pDPObj; ApplyMergeFlags(aOutRange, aSaveData); + MaybeRefresh(); // refresh after convert immediately + mxPCache = XclImpPivotCacheRef(); // release memory } void XclImpPivotTable::MaybeRefresh() @@ -1612,23 +1612,48 @@ // ---------------------------------------------------------------------------- -void XclImpPivotTableManager::ReadPivotCaches( XclImpStream& rStrm ) +// Reading all used pivot caches at one time and then converting all pivot tables together will consume too much memory, forbid this action +// ConvertPivotTables will change to read cache one by one and convert it then release the memory +/*void XclImpPivotTableManager::ReadPivotCaches( XclImpStream& rStrm ) { for( XclImpPivotCacheVec::iterator aIt = maPCaches.begin(), aEnd = maPCaches.end(); aIt != aEnd; ++aIt ) (*aIt)->ReadPivotCacheStream( rStrm ); -} +}*/ -void XclImpPivotTableManager::ConvertPivotTables() +void XclImpPivotTableManager::ConvertPivotTables( XclImpStream & rStm/* guoyanp: for DP memory */ ) { +// for( XclImpPivotTableVec::iterator aIt = maPTables.begin(), aEnd = maPTables.end(); aIt != aEnd; ++aIt ) +// (*aIt)->Convert(); + + std::map< sal_uInt16, std::list< XclImpPivotTableRef > > aMap; + for( XclImpPivotTableVec::iterator aIt = maPTables.begin(), aEnd = maPTables.end(); aIt != aEnd; ++aIt ) - (*aIt)->Convert(); + aMap[(*aIt)->GetCacheId()].push_back( *aIt ); + + size_t iCache = 0; + + for( std::map< sal_uInt16, std::list< XclImpPivotTableRef > >::iterator i = aMap.begin(); i != aMap.end(); i++, iCache++ ) + { + if( i->first >= maPCaches.size() ) continue; + + maPCaches[iCache]->ReadPivotCacheStream( rStm ); + + for( std::list< XclImpPivotTableRef >::iterator j = i->second.begin(); j != i->second.end(); j++ ) + (*j)->Convert(); + + maPCaches[iCache] = XclImpPivotCacheRef(); + } } -void XclImpPivotTableManager::MaybeRefreshPivotTables() +// Reading all used pivot caches at one time and then converting all pivot tables together will consume too much memory, forbid that action +// ConvertPivotTables will change to read cache one by one and convert it then release the memory +// So refreshing all pivot tables at one time is forbidden too because the cache already released +// Need to refresh one by one after convert every pivot table +/*void XclImpPivotTableManager::MaybeRefreshPivotTables() { for( XclImpPivotTableVec::iterator aIt = maPTables.begin(), aEnd = maPTables.end(); aIt != aEnd; ++aIt ) (*aIt)->MaybeRefresh(); -} +}*/ // ============================================================================ Index: inc/xipivot.hxx =================================================================== --- inc/xipivot.hxx (revision 1381941) +++ inc/xipivot.hxx (working copy) @@ -19,8 +19,6 @@ * *************************************************************/ - - #ifndef SC_XIPIVOT_HXX #define SC_XIPIVOT_HXX @@ -358,6 +356,8 @@ void ApplyMergeFlags(const ScRange& rOutRange, const ScDPSaveData& rSaveData); + sal_uInt16 GetCacheId() const { return maPTInfo.mnCacheIdx; }; + // ------------------------------------------------------------------------ private: typedef ::std::vector< XclImpPTFieldRef > XclImpPTFieldVec; @@ -433,12 +433,12 @@ // ------------------------------------------------------------------------ /** Reads all used pivot caches and creates additional sheets for external data sources. */ - void ReadPivotCaches( XclImpStream& rStrm ); +// void ReadPivotCaches( XclImpStream& rStrm ); /** Inserts all pivot tables into the Calc document. */ - void ConvertPivotTables(); +// void ConvertPivotTables(); + void ConvertPivotTables( XclImpStream & ); +// void MaybeRefreshPivotTables(); - void MaybeRefreshPivotTables(); - private: typedef ::std::vector< XclImpPivotCacheRef > XclImpPivotCacheVec; typedef ::std::vector< XclImpPivotTableRef > XclImpPivotTableVec;