diff options
author | Noel Power <noel.power@suse.com> | 2013-05-23 11:50:28 +0100 |
---|---|---|
committer | Noel Power <noel.power@suse.com> | 2013-05-27 19:44:48 +0100 |
commit | fc861c7088e9b639a1c2c80f8ba4535c798aeb34 (patch) | |
tree | 5318c20ce2bea9e16d2adb69b571b6491e6da185 /sc | |
parent | 72e0e01c4b2adf9583c83cc6c7e2f4850a8b4704 (diff) |
improve cell style xls[x|m] import performance
This change reorganizes the styles by column ( and by row ranges in that column )
so we can apply ScAttrEntry entries directly via Document.SetAttrEntries(...) this is
what the binary filter does also.
Change-Id: I7c1398c1d900e0a2b6c6ec3746b982ef60e653a0
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/filter/inc/stylesbuffer.hxx | 4 | ||||
-rw-r--r-- | sc/source/filter/oox/sheetdatabuffer.cxx | 140 | ||||
-rw-r--r-- | sc/source/filter/oox/stylesbuffer.cxx | 64 |
3 files changed, 192 insertions, 16 deletions
diff --git a/sc/source/filter/inc/stylesbuffer.hxx b/sc/source/filter/inc/stylesbuffer.hxx index 77654c7b2af4..32b439c7b9cc 100644 --- a/sc/source/filter/inc/stylesbuffer.hxx +++ b/sc/source/filter/inc/stylesbuffer.hxx @@ -35,6 +35,8 @@ #include "stlsheet.hxx" #include <editeng/svxenum.hxx> #include <editeng/frmdir.hxx> +#include "attarray.hxx" +#include <list> class ScMarkData; namespace com { namespace sun { namespace star { @@ -719,6 +721,8 @@ public: inline const Protection& getProtection() const { return maProtection; } void writeToMarkData( ::ScMarkData& rMarkData, sal_Int32 nNumFmtId ); + void applyPatternToAttrList( ::std::list<ScAttrEntry>& rAttrs, SCROW nRow1, SCROW nRow2, + sal_Int32 nForceScNumFmt ); /** Writes all formatting attributes to the passed property map. */ void writeToPropertyMap( PropertyMap& rPropMap ) const; /** Writes all formatting attributes to the passed property set. */ diff --git a/sc/source/filter/oox/sheetdatabuffer.cxx b/sc/source/filter/oox/sheetdatabuffer.cxx index 11a057d8ae29..48b5e8ec709a 100644 --- a/sc/source/filter/oox/sheetdatabuffer.cxx +++ b/sc/source/filter/oox/sheetdatabuffer.cxx @@ -361,6 +361,50 @@ void SheetDataBuffer::finalizeImport() // write default formatting of remaining row range maXfIdRowRangeList[ maXfIdRowRange.mnXfId ].push_back( maXfIdRowRange.maRowRange ); + + typedef ::std::pair< sal_Int32, sal_Int32 > RowRange; + struct RowRangeStyle + { + sal_Int32 mnStartRow; + sal_Int32 mnEndRow; + XfIdNumFmtKey mnNumFmt; + }; + struct StyleRowRangeComp + { + bool operator() (const RowRangeStyle& lhs, const RowRangeStyle& rhs) const + { + return lhs.mnEndRow<rhs.mnStartRow; + } + }; + + typedef ::std::set< RowRangeStyle, StyleRowRangeComp > RowStyles; + typedef ::std::map< sal_Int32, RowStyles > ColStyles; + + ColStyles aStylesPerColumn; + StylesBuffer& rStyles = getStyles(); + + std::map< std::pair< sal_Int32, sal_Int32 >, ApiCellRangeList > rangeStyleListMap; + + for( XfIdRangeListMap::const_iterator aIt = maXfIdRangeLists.begin(), aEnd = maXfIdRangeLists.end(); aIt != aEnd; ++aIt ) + addIfNotInMyMap( getStyles(), rangeStyleListMap, aIt->first.first, aIt->first.second, aIt->second ); + + // gather all ranges that have the same style and apply them in bulk + for ( std::map< std::pair< sal_Int32, sal_Int32 >, ApiCellRangeList >::iterator it = rangeStyleListMap.begin(), it_end = rangeStyleListMap.end(); it != it_end; ++it ) + { + const ApiCellRangeList& rRanges( it->second ); + for ( ApiCellRangeList::const_iterator it_range = rRanges.begin(), it_rangeend = rRanges.end(); it_range!=it_rangeend; ++it_range ) + { + RowRangeStyle aStyleRows; + aStyleRows.mnNumFmt.first = it->first.first; + aStyleRows.mnNumFmt.second = it->first.second; + aStyleRows.mnStartRow = it_range->StartRow; + aStyleRows.mnEndRow = it_range->EndRow; + for ( sal_Int32 nCol = it_range->StartColumn; nCol <= it_range->EndColumn; ++nCol ) + aStylesPerColumn[ nCol ].insert( aStyleRows ); + } + } + + // process row ranges for each column, don't overwrite any existing row entries for a column for ( std::map< sal_Int32, std::vector< ValueRange > >::iterator it = maXfIdRowRangeList.begin(), it_end = maXfIdRowRangeList.end(); it != it_end; ++it ) { ApiCellRangeList rangeList; @@ -368,27 +412,91 @@ void SheetDataBuffer::finalizeImport() // get all row ranges for id for ( std::vector< ValueRange >::iterator rangeIter = it->second.begin(), rangeIter_end = it->second.end(); rangeIter != rangeIter_end; ++rangeIter ) { - CellRangeAddress aRange( getSheetIndex(), 0, rangeIter->mnFirst, rAddrConv.getMaxApiAddress().Column, rangeIter->mnLast ); - rangeList.push_back( aRange ); + RowRangeStyle aStyleRows; + aStyleRows.mnNumFmt.first = it->first; + if ( aStyleRows.mnNumFmt.first == -1 ) // dud + continue; + aStyleRows.mnNumFmt.second = -1; + aStyleRows.mnStartRow = rangeIter->mnFirst; + aStyleRows.mnEndRow = rangeIter->mnLast; + for ( sal_Int32 nCol = 0; nCol <= rAddrConv.getMaxApiAddress().Column; ++nCol ) + { + RowStyles& rRowStyles = aStylesPerColumn[ nCol ]; + // If the rowrange style includes rows already + // allocated to a style then we need to split + // the range style Rows into sections ( to + // occupy only rows that have no style definition ) + + // We dont want to set any rowstyle 'rows' + // for rows where there is an existing 'style' ) + std::vector< RowRangeStyle > aRangeRowsSplits; + + RowStyles::iterator rows_it = rRowStyles.begin(); + RowStyles::iterator rows_end = rRowStyles.end(); + bool bAddRange = true; + for ( ; rows_it != rows_end; ++rows_it ) + { + const RowRangeStyle& r = *rows_it; + // if row is completely within existing style, discard it + if ( aStyleRows.mnStartRow >= r.mnStartRow && aStyleRows.mnEndRow <= r.mnEndRow ) + bAddRange = false; + else if ( aStyleRows.mnStartRow <= r.mnStartRow ) + { + // not intersecting at all?, if so finish as none left + // to check ( row ranges are in ascending order + if ( aStyleRows.mnEndRow < r.mnStartRow ) + break; + else if ( aStyleRows.mnEndRow <= r.mnEndRow ) + { + aStyleRows.mnEndRow = r.mnStartRow - 1; + break; + } + if ( aStyleRows.mnStartRow < r.mnStartRow ) + { + RowRangeStyle aSplit = aStyleRows; + aSplit.mnEndRow = r.mnStartRow - 1; + aRangeRowsSplits.push_back( aSplit ); + } + } + } + std::vector< RowRangeStyle >::iterator splits_it = aRangeRowsSplits.begin(); + std::vector< RowRangeStyle >::iterator splits_end = aRangeRowsSplits.end(); + for ( ; splits_it != splits_end; ++splits_it ) + rRowStyles.insert( *splits_it ); + if ( bAddRange ) + rRowStyles.insert( aStyleRows ); + } + } + } + ScDocument& rDoc = getScDocument(); + for ( ColStyles::iterator col = aStylesPerColumn.begin(), col_end = aStylesPerColumn.end(); col != col_end; ++col ) + { + RowStyles& rRowStyles = col->second; + std::list<ScAttrEntry> aAttrs; + SCCOL nScCol = static_cast< SCCOL >( col->first ); + for ( RowStyles::iterator rRows = rRowStyles.begin(), rRows_end = rRowStyles.end(); rRows != rRows_end; ++rRows ) + { + Xf* pXf = rStyles.getCellXf( rRows->mnNumFmt.first ).get(); + + if ( pXf ) + pXf->applyPatternToAttrList( aAttrs, rRows->mnStartRow, rRows->mnEndRow, rRows->mnNumFmt.second ); } - ScRangeList aList; - for ( ApiCellRangeList::const_iterator itRange = rangeList.begin(), itRange_end = rangeList.end(); itRange!=itRange_end; ++itRange ) + if (aAttrs.empty() || aAttrs.back().nRow != MAXROW) { - ScRange* pRange = new ScRange(); - ScUnoConversion::FillScRange( *pRange, *itRange ); - aList.push_back( pRange ); + ScAttrEntry aEntry; + aEntry.nRow = MAXROW; + aEntry.pPattern = rDoc.GetDefPattern(); + aAttrs.push_back(aEntry); } - ScMarkData aMark; - aMark.MarkFromRangeList( aList, false ); - getStyles().writeCellXfToMarkData( aMark, it->first, -1 ); + size_t nAttrSize = aAttrs.size(); + ScAttrEntry* pData = new ScAttrEntry[nAttrSize]; + std::list<ScAttrEntry>::const_iterator itr = aAttrs.begin(), itrEnd = aAttrs.end(); + for (size_t i = 0; itr != itrEnd; ++itr, ++i) + pData[i] = *itr; + + rDoc.SetAttrEntries(nScCol, getSheetIndex(), pData, static_cast<SCSIZE>(nAttrSize)); } - std::map< std::pair< sal_Int32, sal_Int32 >, ApiCellRangeList > rangeStyleListMap; - // gather all ranges that have the same style and apply them in bulk - for( XfIdRangeListMap::const_iterator aIt = maXfIdRangeLists.begin(), aEnd = maXfIdRangeLists.end(); aIt != aEnd; ++aIt ) - addIfNotInMyMap( getStyles(), rangeStyleListMap, aIt->first.first, aIt->first.second, aIt->second ); - for ( std::map< std::pair< sal_Int32, sal_Int32 >, ApiCellRangeList >::iterator it = rangeStyleListMap.begin(), it_end = rangeStyleListMap.end(); it != it_end; ++it ) - writeXfIdRangeListProperties( it->first.first, it->first.second, it->second ); // merge all cached merged ranges and update right/bottom cell borders for( MergedRangeList::iterator aIt = maMergedRanges.begin(), aEnd = maMergedRanges.end(); aIt != aEnd; ++aIt ) applyCellMerging( aIt->maRange ); diff --git a/sc/source/filter/oox/stylesbuffer.cxx b/sc/source/filter/oox/stylesbuffer.cxx index 0d0467d5139b..cead31d9dc5c 100644 --- a/sc/source/filter/oox/stylesbuffer.cxx +++ b/sc/source/filter/oox/stylesbuffer.cxx @@ -2281,6 +2281,70 @@ FontRef Xf::getFont() const return getStyles().getFont( maModel.mnFontId ); } +void Xf::applyPatternToAttrList( ::std::list<ScAttrEntry>& rAttrs, SCROW nRow1, SCROW nRow2, + sal_Int32 nNumFmtId ) +{ + createPattern(); + ScPatternAttr& rPat = *mpPattern; + ScDocument& rDoc = getScDocument(); + if ( isCellXf() ) + { + StylesBuffer& rStyles = getStyles(); + rStyles.createCellStyle( maModel.mnStyleXfId ); + + mpStyleSheet = rStyles.getCellStyleSheet( maModel.mnStyleXfId ); + if ( mpStyleSheet ) + { + //rDoc.ApplySelectionStyle( static_cast<ScStyleSheet&>(*mpStyleSheet), rMarkData ); + rPat.SetStyleSheet(mpStyleSheet, false); + } + else + { + ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool(); + if (pStylePool) + { + ScStyleSheet* pStyleSheet = static_cast<ScStyleSheet*>( + pStylePool->Find( + ScGlobal::GetRscString(STR_STYLENAME_STANDARD), SFX_STYLE_FAMILY_PARA)); + + if (pStyleSheet) + rPat.SetStyleSheet( pStyleSheet, false ); + } + } + } + if ( nNumFmtId >= 0 ) + { + ScPatternAttr aNumPat(rDoc.GetPool()); + getStyles().writeNumFmtToItemSet( aNumPat.GetItemSet(), nNumFmtId ); + rPat.GetItemSet().Put(aNumPat.GetItemSet()); + } + if (rPat.GetStyleName()) + { + // Check for a gap between the last entry and this one. + bool bHasGap = false; + if (rAttrs.empty() && nRow1 > 0) + // First attribute range doesn't start at row 0. + bHasGap = true; + + if (!rAttrs.empty() && rAttrs.back().nRow + 1 < nRow1) + bHasGap = true; + + if (bHasGap) + { + // Fill this gap with the default pattern. + ScAttrEntry aEntry; + aEntry.nRow = nRow1 - 1; + aEntry.pPattern = rDoc.GetDefPattern(); + rAttrs.push_back(aEntry); + } + + ScAttrEntry aEntry; + aEntry.nRow = nRow2; + aEntry.pPattern = static_cast<const ScPatternAttr*>(&rDoc.GetPool()->Put(rPat)); + rAttrs.push_back(aEntry); + } +} + void Xf::writeToMarkData( ::ScMarkData& rMarkData, sal_Int32 nNumFmtId ) { createPattern(); |