diff -uNr old/sc/source/core/data/table3.cxx new/sc/source/core/data/table3.cxx --- old/sc/source/core/data/table3.cxx 2008-02-15 16:55:52.000000000 +0800 +++ new/sc/source/core/data/table3.cxx 2008-09-10 18:37:46.000000000 +0800 @@ -357,22 +357,40 @@ short ScTable::Compare( ScSortInfoArray* pArray, SCCOLROW nIndex1, SCCOLROW nIndex2 ) { - short nRes; - USHORT nSort = 0; - do - { - ScSortInfo* pInfo1 = pArray->Get( nSort, nIndex1 ); - ScSortInfo* pInfo2 = pArray->Get( nSort, nIndex2 ); - if ( aSortParam.bByRow ) - nRes = CompareCell( nSort, - pInfo1->pCell, static_cast(aSortParam.nField[nSort]), pInfo1->nOrg, - pInfo2->pCell, static_cast(aSortParam.nField[nSort]), pInfo2->nOrg ); - else - nRes = CompareCell( nSort, - pInfo1->pCell, static_cast(pInfo1->nOrg), aSortParam.nField[nSort], - pInfo2->pCell, static_cast(pInfo2->nOrg), aSortParam.nField[nSort] ); - } while ( nRes == 0 && ++nSort < pArray->GetUsedSorts() ); - return nRes; + short nRes; + USHORT nSort = 0; + do + { + ScSortInfo* pInfo1 = pArray->Get( nSort, nIndex1 ); + ScSortInfo* pInfo2 = pArray->Get( nSort, nIndex2 ); + if ( aSortParam.bByRow ) + { + nRes = CompareCell( nSort, + pInfo1->pCell, static_cast(aSortParam.nField[nSort]), pInfo1->nOrg, + pInfo2->pCell, static_cast(aSortParam.nField[nSort]), pInfo2->nOrg ); + if( nRes == 0 ) + { + if( pInfo1->nOrg < pInfo2->nOrg ) + nRes = -1; + else if( pInfo1->nOrg > pInfo2->nOrg ) + nRes = 1; + } + } + else + { + nRes = CompareCell( nSort, + pInfo1->pCell, static_cast(pInfo1->nOrg), aSortParam.nField[nSort], + pInfo2->pCell, static_cast(pInfo2->nOrg), aSortParam.nField[nSort] ); + if( nRes == 0 ) + { + if( pInfo1->nOrg < pInfo2->nOrg ) + nRes = -1; + else if( pInfo1->nOrg > pInfo2->nOrg ) + nRes = 1; + } + } + } while ( nRes == 0 && ++nSort < pArray->GetUsedSorts() ); + return nRes; } void ScTable::QuickSort( ScSortInfoArray* pArray, SCsCOLROW nLo, SCsCOLROW nHi )