diff options
author | Eike Rathke <erack@redhat.com> | 2022-06-13 17:00:43 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2022-06-13 19:24:41 +0200 |
commit | 3ad12672e924f7aef394119f9fe5f0b06a900b9e (patch) | |
tree | 94e1981bc47787987cc64f4267fe9ca7294fbd6a | |
parent | 9bc1ffa2153d2474b023e0860d3c9c68ee18727b (diff) |
Resolves: tdf#149531 Use initial sheet range for VBA Columns and Rows
... if the ScTableSheetObj's ScRangeList is empty. It might even
be that was never intended to be used and worked only by accident
in the past (pre 6.0), but it's somewhat unclear. It may even get
in the way in case it exists and the (first) range was modified,
e.g. shrunk by a Delete, as the resulting column or row object
could be different from the initial sheet range.
Change-Id: Ib9911df1b23802054a5bb0621bb7f5559ef3f39b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135732
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
-rw-r--r-- | sc/source/ui/vba/vbarange.cxx | 23 | ||||
-rw-r--r-- | sc/source/ui/vba/vbarange.hxx | 3 |
2 files changed, 20 insertions, 6 deletions
diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index 5a6c1f2f18b7..44e565700f71 100644 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -2374,17 +2374,29 @@ ScVbaRange::Activate() } +ScRange ScVbaRange::obtainRangeEvenIfRangeListIsEmpty( const ScCellRangesBase* pUnoRangesBase ) const +{ + // XXX It may be that using the current range list was never correct, but + // always the initial sheet range would be instead, history is unclear. + + const ScRangeList& rCellRanges = pUnoRangesBase->GetRangeList(); + if (!rCellRanges.empty()) + return rCellRanges.front(); + + table::CellRangeAddress aRA( lclGetRangeAddress( mxRange )); + return ScRange( aRA.StartColumn, aRA.StartRow, aRA.Sheet, aRA.EndColumn, aRA.EndRow, aRA.Sheet); +} + uno::Reference< excel::XRange > ScVbaRange::Rows(const uno::Any& aIndex ) { if ( aIndex.hasValue() ) { - sal_Int32 nValue = 0; ScCellRangesBase* pUnoRangesBase = getCellRangesBase(); - ScRangeList aCellRanges = pUnoRangesBase->GetRangeList(); - OUString sAddress; + ScRange aRange( obtainRangeEvenIfRangeListIsEmpty( pUnoRangesBase)); - ScRange aRange = aCellRanges.front(); + sal_Int32 nValue = 0; + OUString sAddress; if( aIndex >>= nValue ) { aRange.aStart.SetRow( aRange.aStart.Row() + --nValue ); @@ -2420,9 +2432,8 @@ uno::Reference< excel::XRange > ScVbaRange::Columns(const uno::Any& aIndex ) { ScCellRangesBase* pUnoRangesBase = getCellRangesBase(); - ScRangeList aCellRanges = pUnoRangesBase->GetRangeList(); + ScRange aRange( obtainRangeEvenIfRangeListIsEmpty( pUnoRangesBase)); - ScRange aRange = aCellRanges.front(); if ( aIndex.hasValue() ) { OUString sAddress; diff --git a/sc/source/ui/vba/vbarange.hxx b/sc/source/ui/vba/vbarange.hxx index b32cc1ba3a5d..a893115d3a75 100644 --- a/sc/source/ui/vba/vbarange.hxx +++ b/sc/source/ui/vba/vbarange.hxx @@ -119,6 +119,9 @@ class ScVbaRange : public ScVbaRange_BASE /** Fires a Worksheet_Change event for this range or range list. */ void fireChangeEvent(); + /// @throws css::uno::RuntimeException + ScRange obtainRangeEvenIfRangeListIsEmpty( const ScCellRangesBase* pUnoRangesBase ) const; + protected: virtual ScCellRangesBase* getCellRangesBase() override; /// @throws css::uno::RuntimeException |