diff -uNr old/sc/inc/document.hxx new/sc/inc/document.hxx --- old/sc/inc/document.hxx 2008-02-15 16:55:50.000000000 +0800 +++ new/sc/inc/document.hxx 2008-09-24 23:14:16.000000000 +0800 @@ -805,7 +805,7 @@ SCCOL nEndCol, SCROW nEndRow ); void RemoveMerge( SCCOL nCol, SCROW nRow, SCTAB nTab ); - BOOL IsBlockEmpty( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, + SC_DLLPUBLIC BOOL IsBlockEmpty( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ) const; BOOL IsPrintEmpty( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, diff -uNr old/sc/source/ui/dbgui/tpsort.cxx new/sc/source/ui/dbgui/tpsort.cxx --- old/sc/source/ui/dbgui/tpsort.cxx 2008-02-15 16:55:56.000000000 +0800 +++ new/sc/source/ui/dbgui/tpsort.cxx 2008-09-24 23:11:30.000000000 +0800 @@ -242,7 +242,22 @@ } else { - aLbSort1.SelectEntryPos( 1 ); + ScDocument* pDoc = pViewData->GetDocument(); + SCCOL nCol = pViewData->GetCurX(); + BOOL bCursorRange = FALSE; + + if ( !pDoc->IsBlockEmpty( pViewData->GetTabNo(), rSortData.nCol1, rSortData.nRow1, rSortData.nCol2,rSortData.nRow2 ) ) + bCursorRange = TRUE; + if( bCursorRange ) + { + if( nCol < rSortData.nCol1 ) + nCol = rSortData.nCol1; + else if( nCol > rSortData.nCol2 ) + nCol = rSortData.nCol2; + } + + USHORT nSort1Pos = nCol - rSortData.nCol1+1; + aLbSort1.SelectEntryPos( nSort1Pos ); aLbSort2.SelectEntryPos( 0 ); aLbSort3.SelectEntryPos( 0 ); aBtnUp1.Check(); diff -uNr old/sc/source/ui/view/cellsh2.cxx new/sc/source/ui/view/cellsh2.cxx --- old/sc/source/ui/view/cellsh2.cxx 2008-02-15 16:56:04.000000000 +0800 +++ new/sc/source/ui/view/cellsh2.cxx 2008-09-24 23:13:20.000000000 +0800 @@ -340,15 +340,27 @@ SfxItemSet aArgSet( GetPool(), SCITEM_SORTDATA, SCITEM_SORTDATA ); ScSortParam aSortParam; ScDBData* pDBData = pTabViewShell->GetDBData(); + ScDocument* pDoc = GetViewData()->GetDocument(); + SCCOL nCol = GetViewData()->GetCurX(); + BOOL bCursorRange = FALSE; pDBData->GetSortParam( aSortParam ); + if ( !pDoc->IsBlockEmpty( GetViewData()->GetTabNo(), aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2 ) ) + bCursorRange = TRUE; + if( bCursorRange ) + { + if( nCol < aSortParam.nCol1 ) + nCol = aSortParam.nCol1; + else if( nCol > aSortParam.nCol2 ) + nCol = aSortParam.nCol2; + } aSortParam.bHasHeader = FALSE; aSortParam.bByRow = TRUE; aSortParam.bCaseSens = FALSE; aSortParam.bIncludePattern = FALSE; aSortParam.bInplace = TRUE; aSortParam.bDoSort[0] = TRUE; - aSortParam.nField[0] = aSortParam.nCol1; + aSortParam.nField[0] = nCol; aSortParam.bAscending[0] = (nSlotId == SID_SORT_ASCENDING); for ( USHORT i=1; i