sc/source/ui/vba/vbarange.cxx | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-)
New commits: commit 7c34db88f3ee99dbb495f3643ab956d7467d5e00 Author: Eike Rathke <er...@redhat.com> AuthorDate: Thu Jun 16 14:27:13 2022 +0200 Commit: Eike Rathke <er...@redhat.com> CommitDate: Thu Jun 16 17:46:34 2022 +0200 Resolves: tdf#149579 Expand Range.Sort single cell to Range.CurrentRegion Change-Id: Ib0ab1c2d0dd45f35f43cf710f7c15791d282ad4d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135997 Reviewed-by: Eike Rathke <er...@redhat.com> Tested-by: Jenkins (cherry picked from commit 350ae0a3f5e5b115070c2371a805bf7ab981d242) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135987 diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index 93b217f1d632..99933f165c24 100644 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -3420,8 +3420,23 @@ ScVbaRange::Sort( const uno::Any& Key1, const uno::Any& Order1, const uno::Any& ScDocument& rDoc = getScDocument(); - RangeHelper thisRange( mxRange ); + uno::Reference< table::XCellRange > xRangeCurrent; + if (isSingleCellRange()) + { + // Expand to CurrentRegion + uno::Reference< excel::XRange > xCurrent( CurrentRegion()); + if (xCurrent.is()) + { + const ScVbaRange* pRange = getImplementation( xCurrent ); + if (pRange) + xRangeCurrent = pRange->mxRange; + } + } + if (!xRangeCurrent.is()) + xRangeCurrent = mxRange; + RangeHelper thisRange( xRangeCurrent ); table::CellRangeAddress thisRangeAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + ScSortParam aSortParam; SCTAB nTab = thisRangeAddress.Sheet; rDoc.GetSortParam( aSortParam, nTab ); @@ -3435,7 +3450,7 @@ ScVbaRange::Sort( const uno::Any& Key1, const uno::Any& Order1, const uno::Any& // 1) #TODO #FIXME need to process DataOption[1..3] not used currently // 2) #TODO #FIXME need to refactor this ( below ) into an IsSingleCell() method - uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY_THROW ); + uno::Reference< table::XColumnRowRange > xColumnRowRange(xRangeCurrent, uno::UNO_QUERY_THROW ); // set up defaults @@ -3548,24 +3563,24 @@ ScVbaRange::Sort( const uno::Any& Key1, const uno::Any& Order1, const uno::Any& if ( Key3.hasValue() ) xKey3 = processKey( Key3, mxContext, pDocShell ); - uno::Reference< util::XSortable > xSort( mxRange, uno::UNO_QUERY_THROW ); + uno::Reference< util::XSortable > xSort( xRangeCurrent, uno::UNO_QUERY_THROW ); uno::Sequence< beans::PropertyValue > sortDescriptor = xSort->createSortDescriptor(); auto psortDescriptor = sortDescriptor.getArray(); sal_Int32 nTableSortFieldIndex = findSortPropertyIndex( sortDescriptor, "SortFields" ); uno::Sequence< table::TableSortField > sTableFields(1); sal_Int32 nTableIndex = 0; - updateTableSortField( mxRange, xKey1, nOrder1, sTableFields.getArray()[ nTableIndex++ ], bIsSortColumns, bMatchCase ); + updateTableSortField( xRangeCurrent, xKey1, nOrder1, sTableFields.getArray()[ nTableIndex++ ], bIsSortColumns, bMatchCase ); if ( xKey2.is() ) { sTableFields.realloc( sTableFields.getLength() + 1 ); - updateTableSortField( mxRange, xKey2, nOrder2, sTableFields.getArray()[ nTableIndex++ ], bIsSortColumns, bMatchCase ); + updateTableSortField( xRangeCurrent, xKey2, nOrder2, sTableFields.getArray()[ nTableIndex++ ], bIsSortColumns, bMatchCase ); } if ( xKey3.is() ) { sTableFields.realloc( sTableFields.getLength() + 1 ); - updateTableSortField( mxRange, xKey3, nOrder3, sTableFields.getArray()[ nTableIndex++ ], bIsSortColumns, bMatchCase ); + updateTableSortField( xRangeCurrent, xKey3, nOrder3, sTableFields.getArray()[ nTableIndex++ ], bIsSortColumns, bMatchCase ); } psortDescriptor[ nTableSortFieldIndex ].Value <<= sTableFields;