5
5
* $RCSfile: vbarange.cxx,v $
9
* last change: $Author: noelpwer $ $Date: 2007-09-14 10:15:55 -0500 (Fri, 14 Sep 2007) $
9
* last change: $Author: noelpwer $ $Date: 2007-11-07 05:19:30 -0600 (Wed, 07 Nov 2007) $
11
11
* The Contents of this file are made available subject to
12
12
* the terms of GNU Lesser General Public License Version 2.1.
425
425
NumFormatHelper( const uno::Reference< table::XCellRange >& xRange )
427
mxSupplier.set( getCurrentDocument(), uno::UNO_QUERY_THROW );
427
mxSupplier.set( getModelFromRange( xRange ), uno::UNO_QUERY_THROW );
428
428
mxRangeProps.set( xRange, uno::UNO_QUERY_THROW);
429
429
mxFormats = mxSupplier->getNumberFormats();
1003
static table::CellRangeAddress getCellRangeAddress( const uno::Any& aParam,
1004
const uno::Reference< sheet::XSpreadsheet >& xDoc )
1006
uno::Reference< table::XCellRange > xRangeParam;
1007
switch ( aParam.getValueTypeClass() )
1009
case uno::TypeClass_STRING:
1011
rtl::OUString rString;
1013
xRangeParam = ScVbaRange::getCellRangeForName( rString, xDoc );
1016
case uno::TypeClass_INTERFACE:
1018
uno::Reference< excel::XRange > xRange;
1021
xRange->getCellRange() >>= xRangeParam;
1025
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can't extact CellRangeAddress from type" ) ), uno::Reference< uno::XInterface >() );
1027
uno::Reference< sheet::XCellRangeAddressable > xAddressable( xRangeParam, uno::UNO_QUERY_THROW );
1028
return xAddressable->getRangeAddress();
1032
1004
getCellRangesForAddress( USHORT& rResFlags, const rtl::OUString& sAddress, ScDocShell* pDocSh, ScRangeList& rCellRanges, ScAddress::Convention& eConv )
1052
getRangeForName( const uno::Reference< uno::XComponentContext >& xContext, const rtl::OUString& sName, ScDocShell* pDocSh, table::CellRangeAddress& pAddr ) throw ( uno::RuntimeException )
1023
bool getScRangeListForAddress( const rtl::OUString& sName, ScDocShell* pDocSh, ScRange& refRange, ScRangeList& aCellRanges, ScAddress::Convention aConv = ScAddress::CONV_XL_A1 ) throw ( uno::RuntimeException )
1054
ScAddress::Convention eConv = ScAddress::CONV_XL_A1;
1055
1025
// see if there is a match with a named range
1056
1026
uno::Reference< beans::XPropertySet > xProps( pDocSh->GetModel(), uno::UNO_QUERY_THROW );
1057
1027
uno::Reference< container::XNameAccess > xNameAccess( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NamedRanges") ) ), uno::UNO_QUERY_THROW );
1058
1028
// Strangly enough you can have Range( "namedRange1, namedRange2, etc," )
1059
ScRangeList aCellRanges;
1060
1029
// loop around each ',' seperated name
1061
1030
std::vector< rtl::OUString > vNames;
1062
1031
sal_Int32 nIndex = 0;
1073
1042
std::vector< rtl::OUString >::iterator it_end = vNames.end();
1074
1043
for ( ; it != it_end; ++it )
1046
ScAddress::Convention eConv = aConv;
1076
1047
// spaces are illegal ( but the user of course can enter them )
1077
1048
rtl::OUString sAddress = (*it).trim();
1078
1049
if ( xNameAccess->hasByName( sAddress ) )
1083
1054
// style is may not be XL_A1
1084
1055
eConv = pDocSh->GetDocument()->GetAddressConvention();
1087
ScUnoConversion::FillScRange( refRange, pAddr );
1088
1058
USHORT nFlags = 0;
1089
1059
if ( !getCellRangesForAddress( nFlags, sAddress, pDocSh, aCellRanges, eConv ) )
1090
throw uno::RuntimeException();
1092
1062
bool bTabFromReferrer = !( nFlags & SCA_TAB_3D );
1101
1071
pRange->aEnd.SetTab( bTabFromReferrer ? refRange.aEnd.Tab() : pRange->aEnd.Tab() );
1079
getRangeForName( const uno::Reference< uno::XComponentContext >& xContext, const rtl::OUString& sName, ScDocShell* pDocSh, table::CellRangeAddress& pAddr, ScAddress::Convention eConv = ScAddress::CONV_XL_A1 ) throw ( uno::RuntimeException )
1081
ScRangeList aCellRanges;
1083
ScUnoConversion::FillScRange( refRange, pAddr );
1084
if ( !getScRangeListForAddress ( sName, pDocSh, refRange, aCellRanges, eConv ) )
1085
throw uno::RuntimeException();
1105
1086
// Single range
1106
1087
if ( aCellRanges.First() == aCellRanges.Last() )
1114
1095
// #FIXME need proper (WorkSheet) parent
1115
1096
return new ScVbaRange( uno::Reference< vba::XHelperInterface >(), xContext, xRanges );
1099
css::uno::Reference< excel::XRange >
1100
ScVbaRange::getRangeObjectForName( const uno::Reference< uno::XComponentContext >& xContext, const rtl::OUString& sRangeName, ScDocShell* pDocSh, ScAddress::Convention eConv ) throw ( uno::RuntimeException )
1102
table::CellRangeAddress refAddr;
1103
return getRangeForName( xContext, sRangeName, pDocSh, refAddr, eConv );
1107
table::CellRangeAddress getCellRangeAddressForVBARange( const uno::Any& aParam, ScDocShell* pDocSh, ScAddress::Convention aConv = ScAddress::CONV_XL_A1) throw ( uno::RuntimeException )
1109
uno::Reference< table::XCellRange > xRangeParam;
1110
switch ( aParam.getValueTypeClass() )
1112
case uno::TypeClass_STRING:
1114
rtl::OUString rString;
1116
ScRangeList aCellRanges;
1118
if ( getScRangeListForAddress ( rString, pDocSh, refRange, aCellRanges, aConv ) )
1120
if ( aCellRanges.First() == aCellRanges.Last() )
1122
table::CellRangeAddress aRangeAddress;
1123
ScUnoConversion::FillApiRange( aRangeAddress, *aCellRanges.First() );
1124
return aRangeAddress;
1128
case uno::TypeClass_INTERFACE:
1130
uno::Reference< excel::XRange > xRange;
1133
xRange->getCellRange() >>= xRangeParam;
1137
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can't extact CellRangeAddress from type" ) ), uno::Reference< uno::XInterface >() );
1139
uno::Reference< sheet::XCellRangeAddressable > xAddressable( xRangeParam, uno::UNO_QUERY_THROW );
1140
return xAddressable->getRangeAddress();
1119
1144
uno::Reference< vba::XCollection >
1128
1153
return borders;
1132
uno::Reference< beans::XPropertySet >
1133
lcl_getPropertiesFromArgs( uno::Sequence< uno::Any > const & args ) throw ( lang::IllegalArgumentException )
1135
boost::optional< uno::Reference< vba::XHelperInterface > >xParent;
1136
uno::Reference< table::XCellRange > xRange;
1137
comphelper::unwrapArgs( args, xParent, xRange );
1138
uno::Reference< beans::XPropertySet > xProps( xRange, uno::UNO_QUERY );
1140
throw lang::IllegalArgumentException();
1144
uno::Reference< frame::XModel >
1145
lcl_getModelFromArgs( uno::Sequence< uno::Any > const& args ) throw ( lang::IllegalArgumentException )
1147
boost::optional< uno::Reference< vba::XHelperInterface > >xParent;
1148
uno::Reference< table::XCellRange > xRange;
1149
comphelper::unwrapArgs( args, xParent, xRange );
1150
return getModelFromRange( xRange );
1153
uno::Reference< vba::XHelperInterface >
1154
lcl_getParentFromArgs( uno::Sequence< uno::Any > const& args ) throw ( lang::IllegalArgumentException )
1156
boost::optional< uno::Reference< vba::XHelperInterface > >xParent;
1157
uno::Reference< table::XCellRange > xRange;
1158
comphelper::unwrapArgs( args, xParent, xRange );
1162
1156
ScVbaRange::ScVbaRange( uno::Sequence< uno::Any> const & args,
1163
uno::Reference< uno::XComponentContext> const & xContext ) throw ( lang::IllegalArgumentException ) : ScVbaRange_BASE( lcl_getParentFromArgs( args ), xContext, lcl_getPropertiesFromArgs( args ), lcl_getModelFromArgs( args ), true ), mbIsRows( sal_False ), mbIsColumns( sal_False )
1157
uno::Reference< uno::XComponentContext> const & xContext ) throw ( lang::IllegalArgumentException ) : ScVbaRange_BASE( getXSomethingFromArgs< vba::XHelperInterface >( args, 0 ), xContext, getXSomethingFromArgs< beans::XPropertySet >( args, 1, false ), getModelFromRange( getXSomethingFromArgs< table::XCellRange >( args, 1 ) ), true ), mbIsRows( sal_False ), mbIsColumns( sal_False )
1165
1159
mxRange.set( mxPropertySet, uno::UNO_QUERY_THROW );
1166
1160
uno::Reference< container::XIndexAccess > xIndex( new SingleRangeIndexAccess( mxContext, mxRange ) );
1763
1757
dDetails = ScAddress::Details( ScAddress::CONV_XL_R1C1, 0, 0 );
1765
1759
USHORT nFlags = SCA_VALID;
1766
ScDocument* pDoc = getDocumentFromRange( mxRange );
1760
ScDocShell* pDocShell = getScDocShell();
1761
ScDocument* pDoc = pDocShell->GetDocument();
1767
1763
RangeHelper thisRange( mxRange );
1768
1764
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
1769
1765
ScRange aRange( static_cast< SCCOL >( thisAddress.StartColumn ), static_cast< SCROW >( thisAddress.StartRow ), static_cast< SCTAB >( thisAddress.Sheet ), static_cast< SCCOL >( thisAddress.EndColumn ), static_cast< SCROW >( thisAddress.EndRow ), static_cast< SCTAB >( thisAddress.Sheet ) );
1798
1794
// #TODO should I throw an error if R1C1 is not set?
1800
table::CellRangeAddress refAddress = getCellRangeAddress( RelativeTo, thisRange.getSpreadSheet() );
1796
table::CellRangeAddress refAddress = getCellRangeAddressForVBARange( RelativeTo, pDocShell );
1801
1797
dDetails = ScAddress::Details( ScAddress::CONV_XL_R1C1, static_cast< SCROW >( refAddress.StartRow ), static_cast< SCCOL >( refAddress.StartColumn ) );
1803
1799
aRange.Format( sRange, nFlags, pDoc, dDetails );
2317
2313
table::CellRangeAddress cell1, cell2;
2318
cell1 = getCellRangeAddress( Cell1, thisRange.getSpreadSheet() );
2314
cell1 = getCellRangeAddressForVBARange( Cell1, getScDocShell() );
2319
2315
// Cell1 & Cell2 defined
2320
2316
// Excel seems to combine the range as the range defined by
2321
2317
// the combination of Cell1 & Cell2
2323
cell2 = getCellRangeAddress( Cell2, thisRange.getSpreadSheet() );
2319
cell2 = getCellRangeAddressForVBARange( Cell2, getScDocShell() );
2325
2321
resultAddress.StartColumn = ( cell1.StartColumn < cell2.StartColumn ) ? cell1.StartColumn : cell2.StartColumn;
2326
2322
resultAddress.StartRow = ( cell1.StartRow < cell2.StartRow ) ? cell1.StartRow : cell2.StartRow;
2695
2691
return sal_True; // always
2698
uno::Reference< table::XCellRange >
2699
ScVbaRange::getCellRangeForName( const rtl::OUString& sRangeName, const uno::Reference< sheet::XSpreadsheet >& xDoc, ScAddress::Convention aConv )
2701
uno::Reference< uno::XInterface > xRanges( xDoc, uno::UNO_QUERY_THROW );
2702
ScCellRangeObj* pRanges = dynamic_cast< ScCellRangeObj* >( xRanges.get() );
2703
ScAddress::Convention eConv = aConv;//ScAddress::CONV_XL_A1; the default.
2705
ScAddress::Details dDetails( eConv, 0, 0 );
2707
uno::Reference< table::XCellRange > xRange;
2709
xRange = pRanges->getCellRangeByName( sRangeName, dDetails );
2713
uno::Reference< table::XCellRange > processKey( const uno::Any& Key, uno::Reference< table::XCellRange >& xRange )
2715
uno::Reference< table::XCellRange > xKey;
2694
uno::Reference< table::XCellRange > processKey( const uno::Any& Key, uno::Reference< uno::XComponentContext >& xContext, ScDocShell* pDocSh )
2696
uno::Reference< excel::XRange > xKeyRange;
2716
2697
if ( Key.getValueType() == excel::XRange::static_type() )
2718
uno::Reference< excel::XRange > xKeyRange( Key, uno::UNO_QUERY_THROW );
2719
xKey.set( xKeyRange->getCellRange(), uno::UNO_QUERY_THROW );
2699
xKeyRange.set( Key, uno::UNO_QUERY_THROW );
2721
2701
else if ( Key.getValueType() == ::getCppuType( static_cast< const rtl::OUString* >(0) ) )
2724
2704
rtl::OUString sRangeName = ::comphelper::getString( Key );
2725
RangeHelper dRange( xRange );
2726
xKey = ScVbaRange::getCellRangeForName( sRangeName, dRange.getSpreadSheet() );
2705
table::CellRangeAddress aRefAddr;
2707
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Range::Sort no docshell to calculate key param")), uno::Reference< uno::XInterface >() );
2708
xKeyRange = getRangeForName( xContext, sRangeName, pDocSh, aRefAddr );
2729
2711
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Range::Sort illegal type value for key param")), uno::Reference< uno::XInterface >() );
2712
uno::Reference< table::XCellRange > xKey;
2713
xKey.set( xKeyRange->getCellRange(), uno::UNO_QUERY_THROW );
2801
2785
RangeHelper thisRange( mxRange );
2802
2786
table::CellRangeAddress thisRangeAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
2803
2787
ScSortParam aSortParam;
2804
#ifdef VBA_OOBUILD_HACK
2805
2788
SCTAB nTab = thisRangeAddress.Sheet;
2806
2789
pDoc->GetSortParam( aSortParam, nTab );
2809
2791
if ( DataOption1.hasValue() )
2810
2792
DataOption1 >>= nDataOption1;
2934
2916
uno::Reference< table::XCellRange > xKey1;
2935
2917
uno::Reference< table::XCellRange > xKey2;
2936
2918
uno::Reference< table::XCellRange > xKey3;
2938
xKey1 = processKey( Key1, mxRange );
2919
ScDocShell* pDocShell = getScDocShell();
2920
xKey1 = processKey( Key1, mxContext, pDocShell );
2939
2921
if ( !xKey1.is() )
2940
2922
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Range::Sort needs a key1 param")), uno::Reference< uno::XInterface >() );
2942
2924
if ( Key2.hasValue() )
2943
xKey2 = processKey( Key2, mxRange );
2925
xKey2 = processKey( Key2, mxContext, pDocShell );
2944
2926
if ( Key3.hasValue() )
2945
xKey3 = processKey( Key3, mxRange );
2927
xKey3 = processKey( Key3, mxContext, pDocShell );
2947
2929
uno::Reference< util::XSortable > xSort( mxRange, uno::UNO_QUERY_THROW );
2948
2930
uno::Sequence< beans::PropertyValue > sortDescriptor = xSort->createSortDescriptor();
2970
2952
nIndex = findSortPropertyIndex( sortDescriptor, CONTS_HEADER );
2971
2953
sortDescriptor[ nIndex ].Value <<= bContainsHeader;
2973
#ifdef VBA_OOBUILD_HACK
2974
2955
pDoc->SetSortParam( aSortParam, nTab );
2976
2956
xSort->sort( sortDescriptor );
2978
2958
// #FIXME #TODO
3727
3707
void lcl_SelectAll( ScDocShell* pDocShell, ScQueryParam& aParam )
3729
ScViewData* pViewData = pDocShell->GetViewData();
3732
OSL_TRACE("Pushing out SelectAll query");
3733
pViewData->GetView()->Query( aParam, NULL, TRUE );
3711
ScViewData* pViewData = pDocShell->GetViewData();
3714
OSL_TRACE("Pushing out SelectAll query");
3715
pViewData->GetView()->Query( aParam, NULL, TRUE );
3769
void lcl_SetAllQueryForField( ScDocShell* pDocShell, sal_Int16 nField, sal_Int16 nSheet )
3752
void lcl_SetAllQueryForField( ScDocShell* pDocShell, SCCOLROW nField, sal_Int16 nSheet )
3771
3754
ScQueryParam aParam = lcl_GetQueryParam( pDocShell, nSheet );
3772
3755
lcl_SetAllQueryForField( aParam, nField );
4893
4876
xRange = lcl_makeXRangeFromSheetCellRanges( getParent(), mxContext, xLocSheetCellRanges, getScDocShell() );
4896
catch (uno::Exception& e)
4879
catch (uno::Exception& )
4898
4881
DebugHelper::exception(SbERR_METHOD_FAILED, STR_ERRORMESSAGE_NOCELLSWEREFOUND);
4972
4955
xSubDesc->addNew(aColumns, _nGroupBy - 1);
4973
4956
xSub->applySubTotals(xSubDesc, bDoReplace);
4975
catch (uno::Exception& e)
4958
catch (uno::Exception& )
4977
4960
DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());