diff options
-rw-r--r-- | sc/inc/column.hxx | 1 | ||||
-rw-r--r-- | sc/inc/document.hxx | 13 | ||||
-rw-r--r-- | sc/inc/table.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/column2.cxx | 13 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/data/formulacell.cxx | 3 | ||||
-rw-r--r-- | sc/source/core/data/table1.cxx | 12 |
7 files changed, 34 insertions, 14 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index ba79c23fb83c..6d09ad165894 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -184,6 +184,7 @@ public: bool HasVisibleDataAt(SCROW nRow) const; SCROW GetFirstDataPos() const; SCROW GetLastDataPos() const; + SCROW GetLastDataPos( SCROW nLastRow ) const; bool GetPrevDataPos(SCROW& rRow) const; bool GetNextDataPos(SCROW& rRow) const; void FindDataAreaPos(SCROW& rRow, bool bDown) const; // (without Broadcaster) diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 4cbf06a84b2b..6993abb0f8c7 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1028,11 +1028,16 @@ public: SCCOL& rEndCol, SCROW& rEndRow, bool bColumnsOnly ) const; /** - * Return the last non-empty row position in given columns, or 0 if the - * columns are empty. A negative value is returned if the given sheet or - * column positions are invalid. + * Return the last non-empty row position in given columns that's no + * greater than the initial last row position, or 0 if the columns are + * empty. A negative value is returned if the given sheet or column + * positions are invalid. + * + * <p>It starts from the specified last row position, and finds the first + * non-empty row position in the upward direction if the start row + * position is empty.</p> */ - SCROW GetLastDataRow( SCTAB nTab, SCCOL nCol1, SCCOL nCol2 ) const; + SCROW GetLastDataRow( SCTAB nTab, SCCOL nCol1, SCCOL nCol2, SCROW nLastRow ) const; SC_DLLPUBLIC void GetDataArea( SCTAB nTab, SCCOL& rStartCol, SCROW& rStartRow, SCCOL& rEndCol, SCROW& rEndRow, bool bIncludeOld, bool bOnlyDown ) const; diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 9bf3f903a3d4..fc8ae3a7a9df 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -469,7 +469,7 @@ public: bool ShrinkToUsedDataArea( bool& o_bShrunk, SCCOL& rStartCol, SCROW& rStartRow, SCCOL& rEndCol, SCROW& rEndRow, bool bColumnsOnly ) const; - SCROW GetLastDataRow( SCCOL nCol1, SCCOL nCol2 ) const; + SCROW GetLastDataRow( SCCOL nCol1, SCCOL nCol2, SCROW nLastRow ) const; SCSIZE GetEmptyLinesInBlock( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, ScDirection eDir ) const; diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx index 42c5469a11c0..eda83ffe7bbf 100644 --- a/sc/source/core/data/column2.cxx +++ b/sc/source/core/data/column2.cxx @@ -1255,6 +1255,19 @@ SCROW ScColumn::GetLastDataPos() const return MAXROW - static_cast<SCROW>(it->size); } +SCROW ScColumn::GetLastDataPos( SCROW nLastRow ) const +{ + sc::CellStoreType::const_position_type aPos = maCells.position(nLastRow); + if (aPos.first->type != sc::element_type_empty) + return nLastRow; + + if (aPos.first == maCells.begin()) + // This is the first block, and is empty. + return 0; + + return static_cast<SCROW>(aPos.first->position - 1); +} + bool ScColumn::GetPrevDataPos(SCROW& rRow) const { std::pair<sc::CellStoreType::const_iterator,size_t> aPos = maCells.position(rRow); diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index 7bda1da5f7a5..dc7db440e954 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -1018,13 +1018,13 @@ bool ScDocument::ShrinkToUsedDataArea( bool& o_bShrunk, SCTAB nTab, SCCOL& rStar return maTabs[nTab]->ShrinkToUsedDataArea( o_bShrunk, rStartCol, rStartRow, rEndCol, rEndRow, bColumnsOnly); } -SCROW ScDocument::GetLastDataRow( SCTAB nTab, SCCOL nCol1, SCCOL nCol2 ) const +SCROW ScDocument::GetLastDataRow( SCTAB nTab, SCCOL nCol1, SCCOL nCol2, SCROW nLastRow ) const { const ScTable* pTab = FetchTable(nTab); if (!pTab) return -1; - return pTab->GetLastDataRow(nCol1, nCol2); + return pTab->GetLastDataRow(nCol1, nCol2, nLastRow); } // connected area diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index b65940935316..249e4420826f 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -3365,7 +3365,8 @@ class GroupTokenConverter SCROW trimLength(SCTAB nTab, SCCOL nCol1, SCCOL nCol2, SCROW nRow, SCROW nRowLen) { - SCROW nLastRow = mrDoc.GetLastDataRow(nTab, nCol1, nCol2); + SCROW nLastRow = nRow + nRowLen - 1; // current last row. + nLastRow = mrDoc.GetLastDataRow(nTab, nCol1, nCol2, nLastRow); if (nLastRow < (nRow + nRowLen - 1)) nRowLen = nLastRow - nRow + 1; else if (nLastRow == 0) diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx index 9af12d690c1e..f827cc981e0c 100644 --- a/sc/source/core/data/table1.cxx +++ b/sc/source/core/data/table1.cxx @@ -987,20 +987,20 @@ bool ScTable::ShrinkToUsedDataArea( bool& o_bShrunk, SCCOL& rStartCol, SCROW& rS (rStartRow != rEndRow || aCol[rStartCol].HasDataAt( rStartRow))); } -SCROW ScTable::GetLastDataRow( SCCOL nCol1, SCCOL nCol2 ) const +SCROW ScTable::GetLastDataRow( SCCOL nCol1, SCCOL nCol2, SCROW nLastRow ) const { if (!ValidCol(nCol1) || !ValidCol(nCol2)) return -1; - SCROW nLastRow = 0; + SCROW nNewLastRow = 0; for (SCCOL i = nCol1; i <= nCol2; ++i) { - SCROW nThis = aCol[i].GetLastDataPos(); - if (nLastRow < nThis) - nLastRow = nThis; + SCROW nThis = aCol[i].GetLastDataPos(nLastRow); + if (nNewLastRow < nThis) + nNewLastRow = nThis; } - return nLastRow; + return nNewLastRow; } SCSIZE ScTable::GetEmptyLinesInBlock( SCCOL nStartCol, SCROW nStartRow, |