summaryrefslogtreecommitdiff
path: root/sc/source/ui/vba/vbarange.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sc/source/ui/vba/vbarange.cxx')
-rw-r--r--sc/source/ui/vba/vbarange.cxx1977
1 files changed, 1272 insertions, 705 deletions
diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx
index 62bd15edd..1041f0201 100644
--- a/sc/source/ui/vba/vbarange.cxx
+++ b/sc/source/ui/vba/vbarange.cxx
@@ -1,7 +1,7 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
@@ -43,7 +43,6 @@
#include <com/sun/star/text/XTextRange.hpp>
#include <com/sun/star/sheet/XCellRangeAddressable.hpp>
#include <com/sun/star/table/CellRangeAddress.hpp>
-#include <com/sun/star/table/CellAddress.hpp>
#include <com/sun/star/sheet/XSpreadsheetView.hpp>
#include <com/sun/star/sheet/XCellRangeReferrer.hpp>
#include <com/sun/star/sheet/XSheetCellRange.hpp>
@@ -51,6 +50,7 @@
#include <com/sun/star/sheet/XSheetCellCursor.hpp>
#include <com/sun/star/sheet/XArrayFormulaRange.hpp>
#include <com/sun/star/sheet/XNamedRange.hpp>
+#include <com/sun/star/sheet/XNamedRanges.hpp>
#include <com/sun/star/sheet/XPrintAreas.hpp>
#include <com/sun/star/sheet/XCellRangesQuery.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
@@ -91,6 +91,15 @@
#include <com/sun/star/sheet/XSubTotalDescriptor.hpp>
#include <com/sun/star/sheet/GeneralFunction.hdl>
+#include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp>
+#include <com/sun/star/sheet/XSheetAnnotations.hpp>
+
+#include <com/sun/star/sheet/XDataPilotTable.hpp>
+#include <com/sun/star/sheet/XDataPilotTable2.hpp>
+#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
+#include <com/sun/star/sheet/DataPilotTablePositionData.hpp>
+#include <com/sun/star/sheet/DataPilotTablePositionType.hpp>
+
#include <ooo/vba/excel/XlPasteSpecialOperation.hpp>
#include <ooo/vba/excel/XlPasteType.hpp>
#include <ooo/vba/excel/Constants.hpp>
@@ -116,12 +125,15 @@
#include <ooo/vba/excel/XlSpecialCellsValue.hpp>
#include <ooo/vba/excel/XlConsolidationFunction.hpp>
#include <ooo/vba/excel/XlSearchDirection.hpp>
+#include <ooo/vba/excel/XlColumnDataType.hpp>
+#include <ooo/vba/excel/XlFilterAction.hpp>
#include <scitems.hxx>
#include <svl/srchitem.hxx>
#include <cellsuno.hxx>
#include <dbcolect.hxx>
#include "docfunc.hxx"
+#include <docuno.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/app.hxx>
@@ -132,6 +144,7 @@
#include <sc.hrc>
#include <globstr.hrc>
#include <unonames.hxx>
+#include <tools/stream.hxx>
#include "vbarange.hxx"
#include "vbafont.hxx"
@@ -143,8 +156,13 @@
#include "vbavalidation.hxx"
#include "vbahyperlinks.hxx"
+#include "vbapivottable.hxx"
+
+#include "asciiopt.hxx"
+#include "impex.hxx"
#include "tabvwsh.hxx"
#include "rangelst.hxx"
+#include "rangenam.hxx"
#include "convuno.hxx"
#include "compiler.hxx"
#include "attrib.hxx"
@@ -158,6 +176,8 @@
#include "vbaglobals.hxx"
#include "vbastyle.hxx"
+#include "vbaname.hxx"
+#include "vbanames.hxx"
#include <vector>
#include <vbahelper/vbacollectionimpl.hxx>
// begin test includes
@@ -178,16 +198,16 @@ double lcl_hmmToPoints( double nVal ) { return ( (double)((nVal /1000 ) * 567 )
static const sal_Int16 supportedIndexTable[] = { excel::XlBordersIndex::xlEdgeLeft, excel::XlBordersIndex::xlEdgeTop, excel::XlBordersIndex::xlEdgeBottom, excel::XlBordersIndex::xlEdgeRight, excel::XlBordersIndex::xlDiagonalDown, excel::XlBordersIndex::xlDiagonalUp, excel::XlBordersIndex::xlInsideVertical, excel::XlBordersIndex::xlInsideHorizontal };
-USHORT lcl_pointsToTwips( double nVal )
-{
+USHORT lcl_pointsToTwips( double nVal )
+{
nVal = nVal * static_cast<double>(20);
short nTwips = static_cast<short>(nVal);
return nTwips;
}
-double lcl_TwipsToPoints( USHORT nVal )
-{
+double lcl_TwipsToPoints( USHORT nVal )
+{
double nPoints = nVal;
- return nPoints / 20;
+ return nPoints / 20;
}
double lcl_Round2DecPlaces( double nVal )
@@ -214,7 +234,7 @@ uno::Reference< excel::XRange > lcl_makeXRangeFromSheetCellRanges( const uno::Re
ScRangeList aCellRanges;
sal_Int32 nLen = sAddresses.getLength();
if ( nLen )
- {
+ {
for ( sal_Int32 index = 0; index < nLen; ++index )
{
ScRange refRange;
@@ -273,7 +293,7 @@ public:
SingleRangeEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< css::uno::XComponentContext >& xContext, const uno::Reference< table::XCellRange >& xRange ) throw ( uno::RuntimeException ) : m_xParent( xParent ), m_xRange( xRange ), mxContext( xContext ), bHasMore( true ) { }
virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) { return bHasMore; }
- virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
+ virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
{
if ( !bHasMore )
throw container::NoSuchElementException();
@@ -298,14 +318,14 @@ public:
// XIndexAccess
virtual ::sal_Int32 SAL_CALL getCount() throw (::uno::RuntimeException) { return 1; }
virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
- {
+ {
if ( Index != 0 )
throw lang::IndexOutOfBoundsException();
- return uno::makeAny( m_xRange );
+ return uno::makeAny( m_xRange );
}
// XElementAccess
virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException){ return table::XCellRange::static_type(0); }
-
+
virtual ::sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException) { return sal_True; }
// XEnumerationAccess
virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration() throw (uno::RuntimeException) { return new SingleRangeEnumeration( mxParent, mxContext, m_xRange ); }
@@ -321,8 +341,8 @@ class RangesEnumerationImpl : public EnumerationHelperImpl
public:
RangesEnumerationImpl( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration, bool bIsRows, bool bIsColumns ) throw ( uno::RuntimeException ) : EnumerationHelperImpl( xParent, xContext, xEnumeration ), mbIsRows( bIsRows ), mbIsColumns( bIsColumns ) {}
- virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
- {
+ virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
+ {
return lcl_makeRange( m_xParent, m_xContext, m_xEnumeration->nextElement(), mbIsRows, mbIsColumns );
}
};
@@ -345,11 +365,11 @@ public:
virtual rtl::OUString& getServiceImplName() { static rtl::OUString sDummy; return sDummy; }
- virtual uno::Sequence< rtl::OUString > getServiceNames() { return uno::Sequence< rtl::OUString >(); }
+ virtual uno::Sequence< rtl::OUString > getServiceNames() { return uno::Sequence< rtl::OUString >(); }
-};
+};
-uno::Reference< container::XEnumeration > SAL_CALL
+uno::Reference< container::XEnumeration > SAL_CALL
ScVbaRangeAreas::createEnumeration() throw (uno::RuntimeException)
{
uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
@@ -362,55 +382,6 @@ ScVbaRangeAreas::createCollectionObject( const uno::Any& aSource )
return lcl_makeRange( mxParent, mxContext, aSource, mbIsRows, mbIsColumns );
}
-// assume that xIf is infact a ScCellRangesBase
-ScDocShell*
-getDocShellFromIf( const uno::Reference< uno::XInterface >& xIf ) throw ( uno::RuntimeException )
-{
- ScCellRangesBase* pUno = ScCellRangesBase::getImplementation( xIf );
- if ( !pUno )
- throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access underlying uno range object" ) ), uno::Reference< uno::XInterface >() );
- return pUno->GetDocShell();
-}
-
-ScDocShell*
-getDocShellFromRange( const uno::Reference< table::XCellRange >& xRange ) throw ( uno::RuntimeException )
-{
- // need the ScCellRangesBase to get docshell
- uno::Reference< uno::XInterface > xIf( xRange, uno::UNO_QUERY_THROW );
- return getDocShellFromIf(xIf );
-}
-
-ScDocShell*
-getDocShellFromRanges( const uno::Reference< sheet::XSheetCellRangeContainer >& xRanges ) throw ( uno::RuntimeException )
-{
- // need the ScCellRangesBase to get docshell
- uno::Reference< uno::XInterface > xIf( xRanges, uno::UNO_QUERY_THROW );
- return getDocShellFromIf(xIf );
-}
-
-uno::Reference< frame::XModel > getModelFromXIf( const uno::Reference< uno::XInterface >& xIf ) throw ( uno::RuntimeException )
-{
- ScDocShell* pDocShell = getDocShellFromIf(xIf );
- return pDocShell->GetModel();
-}
-
-uno::Reference< frame::XModel > getModelFromRange( const uno::Reference< table::XCellRange >& xRange ) throw ( uno::RuntimeException )
-{
- uno::Reference< uno::XInterface > xIf( xRange, uno::UNO_QUERY_THROW );
- return getModelFromXIf( xIf );
-}
-
-ScDocument*
-getDocumentFromRange( const uno::Reference< table::XCellRange >& xRange )
-{
- ScDocShell* pDocShell = getDocShellFromRange( xRange );
- if ( !pDocShell )
- throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access underlying docshell from uno range object" ) ), uno::Reference< uno::XInterface >() );
- ScDocument* pDoc = pDocShell->GetDocument();
- return pDoc;
-}
-
-
ScDocument*
ScVbaRange::getScDocument() throw (uno::RuntimeException)
{
@@ -418,21 +389,21 @@ ScVbaRange::getScDocument() throw (uno::RuntimeException)
{
uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW );
uno::Reference< table::XCellRange > xRange( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
- return getDocumentFromRange( xRange );
+ return excel::GetDocumentFromRange( xRange );
}
- return getDocumentFromRange( mxRange );
+ return excel::GetDocumentFromRange( mxRange );
}
-ScDocShell*
+ScDocShell*
ScVbaRange::getScDocShell() throw (uno::RuntimeException)
{
if ( mxRanges.is() )
{
uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW );
uno::Reference< table::XCellRange > xRange( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
- return getDocShellFromRange( xRange );
+ return excel::GetDocShellFromRange( xRange );
}
- return getDocShellFromRange( mxRange );
+ return excel::GetDocShellFromRange( mxRange );
}
/*static*/ ScVbaRange* ScVbaRange::getImplementation( const uno::Reference< excel::XRange >& rxRange )
@@ -478,7 +449,7 @@ class NumFormatHelper
public:
NumFormatHelper( const uno::Reference< table::XCellRange >& xRange )
{
- mxSupplier.set( getModelFromRange( xRange ), uno::UNO_QUERY_THROW );
+ mxSupplier.set( excel::GetModelFromRange( xRange ), uno::UNO_QUERY_THROW );
mxRangeProps.set( xRange, uno::UNO_QUERY_THROW);
mxFormats = mxSupplier->getNumberFormats();
}
@@ -490,7 +461,7 @@ public:
if ( mxFormats.is() )
return mxFormats->getByKey( nIndexKey );
- return uno::Reference< beans::XPropertySet > ();
+ return uno::Reference< beans::XPropertySet > ();
}
bool isBooleanType()
@@ -518,7 +489,7 @@ public:
if ( pUnoCellRange )
{
- SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( pUnoCellRange );
+ SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( pUnoCellRange );
SfxItemState eState = pDataSet->GetItemState( ATTR_VALUE_FORMAT, TRUE, NULL);
// one of the cells in the range is not like the other ;-)
// so return a zero length format to indicate that
@@ -715,7 +686,7 @@ CellValueSetter::processValue( const uno::Any& aValue, const uno::Reference< tab
case uno::TypeClass_BOOLEAN:
{
sal_Bool bState = sal_False;
- if ( aValue >>= bState )
+ if ( aValue >>= bState )
{
uno::Reference< table::XCellRange > xRange( xCell, uno::UNO_QUERY_THROW );
if ( bState )
@@ -743,7 +714,15 @@ CellValueSetter::processValue( const uno::Any& aValue, const uno::Reference< tab
{
double nDouble = 0.0;
if ( aValue >>= nDouble )
+ {
xCell->setValue( nDouble );
+ uno::Reference< table::XCellRange > xRange( xCell, uno::UNO_QUERY_THROW );
+ NumFormatHelper cellNumFormat( xRange );
+ if ( cellNumFormat.isBooleanType() )
+ {
+ cellNumFormat.setNumberFormat( util::NumberFormat::NUMBER );
+ }
+ }
else
isExtracted = false;
break;
@@ -837,9 +816,10 @@ protected:
double aDblValue = 0.0;
if ( aValue >>= sFormula )
{
- // convert to CONV_OOO style formula string because XCell::setFormula
- // always compile it in CONV_OOO style. Perhaps css.sheet.FormulaParser
- // should be used in future to directly pass formula tokens.
+ // convert to GRAM_PODF_A1 style grammar because XCell::setFormula
+ // always compile it in that grammar. Perhaps
+ // css.sheet.FormulaParser should be used in future to directly
+ // pass formula tokens when that API stabilizes.
if ( m_eGrammar != formula::FormulaGrammar::GRAM_PODF_A1 && ( sFormula.trim().indexOf('=') == 0 ) )
{
uno::Reference< uno::XInterface > xIf( xCell, uno::UNO_QUERY_THROW );
@@ -1082,7 +1062,7 @@ public:
uno::Reference< sheet::XSheetCellCursor > getSheetCellCursor() throw ( uno::RuntimeException )
{
- return uno::Reference< sheet::XSheetCellCursor >( getSpreadSheet()->createCursorByRange( getSheetCellRange() ), uno::UNO_QUERY_THROW );
+ return uno::Reference< sheet::XSheetCellCursor >( getSpreadSheet()->createCursorByRange( getSheetCellRange() ), uno::UNO_QUERY_THROW );
}
static uno::Reference< excel::XRange > createRangeFromRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference<uno::XComponentContext >& xContext,
@@ -1100,34 +1080,34 @@ public:
};
bool
-getCellRangesForAddress( USHORT& rResFlags, const rtl::OUString& sAddress, ScDocShell* pDocSh, ScRangeList& rCellRanges, formula::FormulaGrammar::AddressConvention& eConv )
+getCellRangesForAddress( USHORT& rResFlags, const rtl::OUString& sAddress, ScDocShell* pDocSh, ScRangeList& rCellRanges, formula::FormulaGrammar::AddressConvention& eConv, char cDelimiter = 0 )
{
-
+
ScDocument* pDoc = NULL;
if ( pDocSh )
{
pDoc = pDocSh->GetDocument();
String aString(sAddress);
USHORT nMask = SCA_VALID;
- rResFlags = rCellRanges.Parse( sAddress, pDoc, nMask, eConv, 0 );
+ rResFlags = rCellRanges.Parse( sAddress, pDoc, nMask, eConv, cDelimiter );
if ( rResFlags & SCA_VALID )
{
return true;
}
- }
+ }
return false;
-}
+}
bool getScRangeListForAddress( const rtl::OUString& sName, ScDocShell* pDocSh, ScRange& refRange, ScRangeList& aCellRanges, formula::FormulaGrammar::AddressConvention aConv = formula::FormulaGrammar::CONV_XL_A1 ) throw ( uno::RuntimeException )
{
// see if there is a match with a named range
uno::Reference< beans::XPropertySet > xProps( pDocSh->GetModel(), uno::UNO_QUERY_THROW );
uno::Reference< container::XNameAccess > xNameAccess( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NamedRanges") ) ), uno::UNO_QUERY_THROW );
- // Strangly enough you can have Range( "namedRange1, namedRange2, etc," )
+ // Strangly enough you can have Range( "namedRange1, namedRange2, etc," )
// loop around each ',' seperated name
std::vector< rtl::OUString > vNames;
sal_Int32 nIndex = 0;
- do
+ do
{
rtl::OUString aToken = sName.getToken( 0, ',', nIndex );
vNames.push_back( aToken );
@@ -1136,14 +1116,33 @@ bool getScRangeListForAddress( const rtl::OUString& sName, ScDocShell* pDocSh, S
if ( !vNames.size() )
vNames.push_back( sName );
- std::vector< rtl::OUString >::iterator it = vNames.begin();
- std::vector< rtl::OUString >::iterator it_end = vNames.end();
+ std::vector< rtl::OUString >::iterator it = vNames.begin();
+ std::vector< rtl::OUString >::iterator it_end = vNames.end();
for ( ; it != it_end; ++it )
{
-
- formula::FormulaGrammar::AddressConvention eConv = aConv;
+
+ formula::FormulaGrammar::AddressConvention eConv = aConv;
// spaces are illegal ( but the user of course can enter them )
rtl::OUString sAddress = (*it).trim();
+ // if a local name ( on the active sheet ) exists this will
+ // take precedence over a global with the same name
+ if ( !xNameAccess->hasByName( sAddress ) && pDocSh )
+ {
+ // try a local name
+ ScDocument* pDoc = pDocSh->GetDocument();
+ SCTAB nCurTab = pDocSh->GetCurTab();
+ if ( pDoc )
+ {
+ NameToNameMap* pMap = pDoc->GetLocalNameMap( nCurTab );
+ if ( pMap )
+ {
+ NameToNameMap::iterator itTmp = pMap->find( sAddress );
+ if ( itTmp != pMap->end() ) // found a mapping
+ sAddress = itTmp->second;
+ }
+ }
+ }
+ char aChar = 0;
if ( xNameAccess->hasByName( sAddress ) )
{
uno::Reference< sheet::XNamedRange > xNamed( xNameAccess->getByName( sAddress ), uno::UNO_QUERY_THROW );
@@ -1151,12 +1150,13 @@ bool getScRangeListForAddress( const rtl::OUString& sName, ScDocShell* pDocSh, S
// As the address comes from OOO, the addressing
// style is may not be XL_A1
eConv = pDocSh->GetDocument()->GetAddressConvention();
- }
+ aChar = ';';
+ }
USHORT nFlags = 0;
- if ( !getCellRangesForAddress( nFlags, sAddress, pDocSh, aCellRanges, eConv ) )
+ if ( !getCellRangesForAddress( nFlags, sAddress, pDocSh, aCellRanges, eConv, aChar ) )
return false;
-
+
bool bTabFromReferrer = !( nFlags & SCA_TAB_3D );
for ( ScRange* pRange = aCellRanges.First() ; pRange; pRange = aCellRanges.Next() )
@@ -1179,7 +1179,7 @@ getRangeForName( const uno::Reference< uno::XComponentContext >& xContext, const
ScRangeList aCellRanges;
ScRange refRange;
ScUnoConversion::FillScRange( refRange, pAddr );
- if ( !getScRangeListForAddress ( sName, pDocSh, refRange, aCellRanges, eConv ) )
+ if ( !getScRangeListForAddress ( sName, pDocSh, refRange, aCellRanges, eConv ) )
throw uno::RuntimeException();
// Single range
if ( aCellRanges.First() == aCellRanges.Last() )
@@ -1190,7 +1190,7 @@ getRangeForName( const uno::Reference< uno::XComponentContext >& xContext, const
}
uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( pDocSh, aCellRanges ) );
- uno::Reference< XHelperInterface > xFixThisParent = excel::getUnoSheetModuleObj( xRanges );
+ uno::Reference< XHelperInterface > xFixThisParent = excel::getUnoSheetModuleObj( xRanges );
return new ScVbaRange( xFixThisParent, xContext, xRanges );
}
@@ -1248,7 +1248,7 @@ uno::Reference< sheet::XSheetCellRangeContainer > lclExpandToMerged( const uno::
ScUnoConversion::FillScRange( aScRange, aRangeAddr );
aScRanges.Append( aScRange );
}
- return new ScCellRangesObj( getDocShellFromRanges( rxCellRanges ), aScRanges );
+ return new ScCellRangesObj( excel::GetDocShellFromRanges( rxCellRanges ), aScRanges );
}
void lclExpandAndMerge( const uno::Reference< table::XCellRange >& rxCellRange, bool bMerge ) throw (uno::RuntimeException)
@@ -1294,7 +1294,7 @@ util::TriState lclGetMergedState( const uno::Reference< table::XCellRange >& rxC
of a merged range is part of this range are not covered. */
ScRange aScRange;
ScUnoConversion::FillScRange( aScRange, aRangeAddr );
- bool bHasMerged = getDocumentFromRange( rxCellRange )->HasAttrib( aScRange, HASATTR_MERGED | HASATTR_OVERLAPPED );
+ bool bHasMerged = excel::GetDocumentFromRange( rxCellRange )->HasAttrib( aScRange, HASATTR_MERGED | HASATTR_OVERLAPPED );
return bHasMerged ? util::TriState_INDETERMINATE : util::TriState_NO;
}
@@ -1311,6 +1311,28 @@ ScVbaRange::getRangeObjectForName(
return getRangeForName( xContext, sRangeName, pDocSh, refAddr, eConv );
}
+table::CellAddress ScVbaRange::getLeftUpperCellAddress()
+{
+ table::CellAddress aCellAddress;
+ uno::Reference< table::XCellRange > xCellRange = mxRange;
+ if ( mxRanges.is() && m_Areas.is() && m_Areas->getCount() > 1 )
+ {
+ uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY );
+ if ( xIndex.is() && xIndex->getCount() > 0 )
+ {
+ xCellRange.set( xIndex->getByIndex( 0 ), uno::UNO_QUERY );
+ }
+ }
+ if ( xCellRange.is() )
+ {
+ uno::Reference< sheet::XCellAddressable > xCellAddr( xCellRange->getCellByPosition( 0, 0 ), uno::UNO_QUERY );
+ if ( xCellAddr.is() )
+ {
+ aCellAddress = xCellAddr->getCellAddress();
+ }
+ }
+ return aCellAddress;
+}
table::CellRangeAddress getCellRangeAddressForVBARange( const uno::Any& aParam, ScDocShell* pDocSh, formula::FormulaGrammar::AddressConvention aConv = formula::FormulaGrammar::CONV_XL_A1) throw ( uno::RuntimeException )
{
@@ -1323,7 +1345,7 @@ table::CellRangeAddress getCellRangeAddressForVBARange( const uno::Any& aParam,
aParam >>= rString;
ScRangeList aCellRanges;
ScRange refRange;
- if ( getScRangeListForAddress ( rString, pDocSh, refRange, aCellRanges, aConv ) )
+ if ( getScRangeListForAddress ( rString, pDocSh, refRange, aCellRanges, aConv ) )
{
if ( aCellRanges.First() == aCellRanges.Last() )
{
@@ -1338,7 +1360,14 @@ table::CellRangeAddress getCellRangeAddressForVBARange( const uno::Any& aParam,
uno::Reference< excel::XRange > xRange;
aParam >>= xRange;
if ( xRange.is() )
+ {
+ ScVbaRange* pRange = dynamic_cast< ScVbaRange* >( xRange.get() );
+ if ( pRange && pDocSh && pRange->getScDocument() != pDocSh->GetDocument() )
+ {
+ throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Invalid range" ) ), uno::Reference< uno::XInterface >() );
+ }
xRange->getCellRange() >>= xRangeParam;
+ }
break;
}
default:
@@ -1350,8 +1379,8 @@ table::CellRangeAddress getCellRangeAddressForVBARange( const uno::Any& aParam,
uno::Reference< XCollection >
lcl_setupBorders( const uno::Reference< excel::XRange >& xParentRange, const uno::Reference<uno::XComponentContext>& xContext, const uno::Reference< table::XCellRange >& xRange ) throw( uno::RuntimeException )
{
- uno::Reference< XHelperInterface > xParent( xParentRange, uno::UNO_QUERY_THROW );
- ScDocument* pDoc = getDocumentFromRange(xRange);
+ uno::Reference< XHelperInterface > xParent( xParentRange, uno::UNO_QUERY_THROW );
+ ScDocument* pDoc = excel::GetDocumentFromRange(xRange);
if ( !pDoc )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access document from shell" ) ), uno::Reference< uno::XInterface >() );
ScVbaPalette aPalette( pDoc->GetDocumentShell() );
@@ -1359,8 +1388,21 @@ lcl_setupBorders( const uno::Reference< excel::XRange >& xParentRange, const uno
return borders;
}
+void lcl_NotifyRangeChanges( const uno::Reference< frame::XModel >& xModel, ScCellRangesBase* pUnoRangesBase )
+{
+ if ( xModel.is() && pUnoRangesBase )
+ {
+ ScModelObj* pModelObj = ScModelObj::getImplementation( xModel );
+ const ScRangeList& aCellRanges = pUnoRangesBase->GetRangeList();
+ if ( pModelObj && pModelObj->HasChangesListeners() )
+ {
+ pModelObj->NotifyChanges( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "cell-change" ) ), aCellRanges );
+ }
+ }
+}
+
ScVbaRange::ScVbaRange( uno::Sequence< uno::Any> const & args,
- uno::Reference< uno::XComponentContext> const & xContext ) throw ( lang::IllegalArgumentException ) : ScVbaRange_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext, getXSomethingFromArgs< beans::XPropertySet >( args, 1, false ), getModelFromXIf( getXSomethingFromArgs< uno::XInterface >( args, 1 ) ), true ), mbIsRows( sal_False ), mbIsColumns( sal_False )
+ uno::Reference< uno::XComponentContext> const & xContext ) throw ( lang::IllegalArgumentException ) : ScVbaRange_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext, getXSomethingFromArgs< beans::XPropertySet >( args, 1, false ), excel::GetModelFromRange( getXSomethingFromArgs< uno::XInterface >( args, 1 ) ), true ), mbIsRows( sal_False ), mbIsColumns( sal_False )
{
mxRange.set( mxPropertySet, uno::UNO_QUERY );
mxRanges.set( mxPropertySet, uno::UNO_QUERY );
@@ -1377,7 +1419,7 @@ ScVbaRange::ScVbaRange( uno::Sequence< uno::Any> const & args,
}
ScVbaRange::ScVbaRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< table::XCellRange >& xRange, sal_Bool bIsRows, sal_Bool bIsColumns ) throw( lang::IllegalArgumentException )
-: ScVbaRange_BASE( xParent, xContext, uno::Reference< beans::XPropertySet >( xRange, uno::UNO_QUERY_THROW ), getModelFromRange( xRange), true ), mxRange( xRange ),
+: ScVbaRange_BASE( xParent, xContext, uno::Reference< beans::XPropertySet >( xRange, uno::UNO_QUERY_THROW ), excel::GetModelFromRange( xRange), true ), mxRange( xRange ),
mbIsRows( bIsRows ),
mbIsColumns( bIsColumns )
{
@@ -1392,11 +1434,11 @@ ScVbaRange::ScVbaRange( const uno::Reference< XHelperInterface >& xParent, const
}
ScVbaRange::ScVbaRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< sheet::XSheetCellRangeContainer >& xRanges, sal_Bool bIsRows, sal_Bool bIsColumns ) throw ( lang::IllegalArgumentException )
-: ScVbaRange_BASE( xParent, xContext, uno::Reference< beans::XPropertySet >( xRanges, uno::UNO_QUERY_THROW ), getModelFromXIf( uno::Reference< uno::XInterface >( xRanges, uno::UNO_QUERY_THROW ) ), true ), mxRanges( xRanges ),mbIsRows( bIsRows ), mbIsColumns( bIsColumns )
+: ScVbaRange_BASE( xParent, xContext, uno::Reference< beans::XPropertySet >( xRanges, uno::UNO_QUERY_THROW ), excel::GetModelFromRange( uno::Reference< uno::XInterface >( xRanges, uno::UNO_QUERY_THROW ) ), true ), mxRanges( xRanges ),mbIsRows( bIsRows ), mbIsColumns( bIsColumns )
{
uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW );
- m_Areas = new ScVbaRangeAreas( xParent, mxContext, xIndex, mbIsRows, mbIsColumns );
+ m_Areas = new ScVbaRangeAreas( xParent, mxContext, xIndex, mbIsRows, mbIsColumns );
}
@@ -1431,9 +1473,55 @@ ScVbaRange::visitArray( ArrayVisitor& visitor )
}
}
+uno::Any SAL_CALL ScVbaRange::getName() throw (uno::RuntimeException)
+{
+ uno::Reference< excel::XName > xName;
+
+ ScDocShell* pDocShell = getScDocShell();
+ uno::Reference< frame::XModel > xModel = pDocShell ? pDocShell->GetModel() : NULL;
+ if ( !xModel.is() )
+ {
+ throw uno::RuntimeException( rtl::OUString::createFromAscii( "Invalid document" ), uno::Reference< uno::XInterface >() );
+ }
+ uno::Reference< beans::XPropertySet > xPropertySet( xModel, uno::UNO_QUERY_THROW );
+ uno::Reference< sheet::XNamedRanges > xNamedRanges( xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("NamedRanges")) , uno::UNO_QUERY_THROW );
+
+ uno::Reference< excel::XNames > xNames( new ScVbaNames( uno::Reference< XHelperInterface >(), mxContext , xNamedRanges , xModel ) );
+ sal_Int32 nCount = xNames->getCount();
+ ScCellRangesBase* pUnoRangesBase = getCellRangesBase();
+ if ( pUnoRangesBase && nCount > 0 )
+ {
+ ScRangeList aRangeList = pUnoRangesBase->GetRangeList();
+ for ( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
+ {
+ uno::Reference< excel::XName > xTmpName( xNames->Item( uno::makeAny( nIndex + 1 ), uno::Any() ), uno::UNO_QUERY );
+ if ( xTmpName.is() )
+ {
+ try
+ {
+ uno::Reference< excel::XRange > xRange = xTmpName->getRefersToRange();
+ if ( xRange.is() )
+ {
+ ScVbaRange* pRange = dynamic_cast< ScVbaRange* >( xRange.get() );
+ ScCellRangesBase* pCurRangesBase = pRange ? pRange->getCellRangesBase() : NULL;
+ if ( pCurRangesBase && aRangeList == pCurRangesBase->GetRangeList() )
+ {
+ xName = xTmpName;
+ break;
+ }
+ }
+ }
+ catch (const uno::Exception&)
+ {
+ }
+ }
+ }
+ }
+ return uno::makeAny( xName );
+}
-uno::Any
+uno::Any
ScVbaRange::getValue( ValueGetter& valueGetter) throw (uno::RuntimeException)
{
uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY_THROW );
@@ -1470,7 +1558,7 @@ ScVbaRange::getValue() throw (uno::RuntimeException)
}
-void
+void
ScVbaRange::setValue( const uno::Any &aValue, ValueSetter& valueSetter ) throw (uno::RuntimeException)
{
uno::TypeClass aClass = aValue.getValueTypeClass();
@@ -1480,8 +1568,8 @@ ScVbaRange::setValue( const uno::Any &aValue, ValueSetter& valueSetter ) thro
uno::Any aConverted;
try
{
- // test for single dimension, could do
- // with a better test than this
+ // test for single dimension, could do
+ // with a better test than this
if ( aValue.getValueTypeName().indexOf('[') == aValue.getValueTypeName().lastIndexOf('[') )
{
aConverted = xConverter->convertTo( aValue, getCppuType((uno::Sequence< uno::Any >*)0) );
@@ -1497,7 +1585,7 @@ ScVbaRange::setValue( const uno::Any &aValue, ValueSetter& valueSetter ) thro
}
catch ( uno::Exception& e )
{
- OSL_TRACE("Bahhh, caught exception %s",
+ OSL_TRACE("Bahhh, caught exception %s",
rtl::OUStringToOString( e.Message,
RTL_TEXTENCODING_UTF8 ).getStr() );
}
@@ -1515,12 +1603,15 @@ ScVbaRange::setValue( const uno::Any &aValue ) throw (uno::RuntimeException)
if ( m_Areas->getCount() > 1 )
{
AreasVisitor aVisitor( m_Areas );
- RangeValueProcessor valueProcessor( aValue );
+ RangeValueProcessor valueProcessor( aValue );
aVisitor.visit( valueProcessor );
return;
- }
+ }
CellValueSetter valueSetter( aValue );
setValue( aValue, valueSetter );
+
+ // Fires the range change event.
+ lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() );
}
void
@@ -1529,6 +1620,9 @@ ScVbaRange::Clear() throw (uno::RuntimeException)
using namespace ::com::sun::star::sheet::CellFlags;
sal_Int32 nFlags = VALUE | DATETIME | STRING | FORMULA | HARDATTR | EDITATTR | FORMATTED;
ClearContents( nFlags );
+
+ // Fires the range change event.
+ lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() );
}
//helper ClearContent
@@ -1547,7 +1641,7 @@ ScVbaRange::ClearContents( sal_Int32 nFlags ) throw (uno::RuntimeException)
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
ScVbaRange* pRange = getImplementation( xRange );
if ( pRange )
- pRange->ClearContents( nFlags );
+ pRange->ClearContents( nFlags );
}
return;
}
@@ -1566,9 +1660,12 @@ void
ScVbaRange::ClearContents() throw (uno::RuntimeException)
{
sal_Int32 nClearFlags = ( sheet::CellFlags::VALUE |
- sheet::CellFlags::STRING | sheet::CellFlags::DATETIME |
+ sheet::CellFlags::STRING | sheet::CellFlags::DATETIME |
sheet::CellFlags::FORMULA );
ClearContents( nClearFlags );
+
+ // Fires the range change event.
+ lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() );
}
void
@@ -1577,6 +1674,9 @@ ScVbaRange::ClearFormats() throw (uno::RuntimeException)
//FIXME: need to check if we need to combine sheet::CellFlags::FORMATTED
sal_Int32 nClearFlags = sheet::CellFlags::HARDATTR | sheet::CellFlags::FORMATTED | sheet::CellFlags::EDITATTR;
ClearContents( nClearFlags );
+
+ // Fires the range change event.
+ lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() );
}
void
@@ -1586,15 +1686,18 @@ ScVbaRange::setFormulaValue( const uno::Any& rFormula, formula::FormulaGrammar::
if ( m_Areas->getCount() > 1 )
{
AreasVisitor aVisitor( m_Areas );
- RangeFormulaProcessor valueProcessor( rFormula );
+ RangeFormulaProcessor valueProcessor( rFormula );
aVisitor.visit( valueProcessor );
return;
- }
+ }
CellFormulaValueSetter formulaValueSetter( rFormula, getScDocument(), eGram );
setValue( rFormula, formulaValueSetter );
+
+ // Fires the range change event.
+ lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() );
}
-uno::Any
+uno::Any
ScVbaRange::getFormulaValue( formula::FormulaGrammar::Grammar eGram ) throw (uno::RuntimeException)
{
// #TODO code within the test below "if ( m_Areas.... " can be removed
@@ -1608,13 +1711,13 @@ ScVbaRange::getFormulaValue( formula::FormulaGrammar::Grammar eGram ) throw (uno
}
CellFormulaValueGetter valueGetter( getScDocument(), eGram );
return getValue( valueGetter );
-
+
}
void
ScVbaRange::setFormula(const uno::Any &rFormula ) throw (uno::RuntimeException)
{
- // #FIXME converting "=$a$1" e.g. CONV_XL_A1 -> CONV_OOO // results in "=$a$1:a1", temporalily disable conversion
+ // #FIXME converting "=$a$1" e.g. CONV_XL_A1 -> CONV_OOO // results in "=$a$1:a1", temporalily disable conversion
setFormulaValue( rFormula,formula::FormulaGrammar::GRAM_NATIVE_XL_A1 );;
}
@@ -1636,7 +1739,7 @@ ScVbaRange::getFormula() throw (::com::sun::star::uno::RuntimeException)
return getFormulaValue( formula::FormulaGrammar::GRAM_NATIVE_XL_A1 );
}
-sal_Int32
+sal_Int32
ScVbaRange::getCount() throw (uno::RuntimeException)
{
// If this is a multiple selection apply setValue over all areas
@@ -1646,7 +1749,7 @@ ScVbaRange::getCount() throw (uno::RuntimeException)
RangeCountProcessor valueProcessor;
aVisitor.visit( valueProcessor );
return valueProcessor.value();
- }
+ }
sal_Int32 rowCount = 0;
sal_Int32 colCount = 0;
uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY_THROW );
@@ -1654,13 +1757,13 @@ ScVbaRange::getCount() throw (uno::RuntimeException)
colCount = xColumnRowRange->getColumns()->getCount();
if( IsRows() )
- return rowCount;
+ return rowCount;
if( IsColumns() )
return colCount;
return rowCount * colCount;
}
-sal_Int32
+sal_Int32
ScVbaRange::getRow() throw (uno::RuntimeException)
{
// #TODO code within the test below "if ( m_Areas.... " can be removed
@@ -1673,10 +1776,10 @@ ScVbaRange::getRow() throw (uno::RuntimeException)
return xRange->getRow();
}
uno::Reference< sheet::XCellAddressable > xCellAddressable(mxRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW );
- return xCellAddressable->getCellAddress().Row + 1; // Zero value indexing
-}
-
-sal_Int32
+ return xCellAddressable->getCellAddress().Row + 1; // Zero value indexing
+}
+
+sal_Int32
ScVbaRange::getColumn() throw (uno::RuntimeException)
{
// #TODO code within the test below "if ( m_Areas.... " can be removed
@@ -1707,8 +1810,8 @@ ScVbaRange::HasFormula() throw (uno::RuntimeException)
if ( index > 1 )
if ( aResult != xRange->HasFormula() )
return aNULL();
- aResult = xRange->HasFormula();
- if ( aNULL() == aResult )
+ aResult = xRange->HasFormula();
+ if ( aNULL() == aResult )
return aNULL();
}
return aResult;
@@ -1720,13 +1823,13 @@ ScVbaRange::HasFormula() throw (uno::RuntimeException)
uno::Reference<uno::XInterface> xRanges( pThisRanges->queryFormulaCells( ( sheet::FormulaResult::ERROR | sheet::FormulaResult::VALUE | sheet::FormulaResult::STRING ) ), uno::UNO_QUERY_THROW );
ScCellRangesBase* pFormulaRanges = dynamic_cast< ScCellRangesBase * > ( xRanges.get() );
// check if there are no formula cell, return false
- if ( pFormulaRanges->GetRangeList().Count() == 0 )
+ if ( pFormulaRanges->GetRangeList().Count() == 0 )
return uno::makeAny(sal_False);
-
+
// chech if there are holes (where some cells are not formulas)
- // or returned range is not equal to this range
- if ( ( pFormulaRanges->GetRangeList().Count() > 1 )
- || ( pFormulaRanges->GetRangeList().GetObject(0)->aStart != pThisRanges->GetRangeList().GetObject(0)->aStart )
+ // or returned range is not equal to this range
+ if ( ( pFormulaRanges->GetRangeList().Count() > 1 )
+ || ( pFormulaRanges->GetRangeList().GetObject(0)->aStart != pThisRanges->GetRangeList().GetObject(0)->aStart )
|| ( pFormulaRanges->GetRangeList().GetObject(0)->aEnd != pThisRanges->GetRangeList().GetObject(0)->aEnd ) )
return aNULL(); // should return aNULL;
}
@@ -1744,40 +1847,43 @@ ScVbaRange::fillSeries( sheet::FillDirection nFillDirection, sheet::FillMode nFi
uno::Reference< excel::XRange > xRange( xCollection->Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
ScVbaRange* pThisRange = getImplementation( xRange );
pThisRange->fillSeries( nFillDirection, nFillMode, nFillDateMode, fStep, fEndValue );
-
+
}
- return;
+ return;
}
-
+
uno::Reference< sheet::XCellSeries > xCellSeries(mxRange, uno::UNO_QUERY_THROW );
xCellSeries->fillSeries( nFillDirection, nFillMode, nFillDateMode, fStep, fEndValue );
+
+ // Fires the range change event.
+ lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() );
}
-void
+void
ScVbaRange::FillLeft() throw (uno::RuntimeException)
{
- fillSeries(sheet::FillDirection_TO_LEFT,
+ fillSeries(sheet::FillDirection_TO_LEFT,
sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF);
}
-void
+void
ScVbaRange::FillRight() throw (uno::RuntimeException)
{
- fillSeries(sheet::FillDirection_TO_RIGHT,
+ fillSeries(sheet::FillDirection_TO_RIGHT,
sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF);
}
-void
+void
ScVbaRange::FillUp() throw (uno::RuntimeException)
{
- fillSeries(sheet::FillDirection_TO_TOP,
+ fillSeries(sheet::FillDirection_TO_TOP,
sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF);
}
-void
+void
ScVbaRange::FillDown() throw (uno::RuntimeException)
{
- fillSeries(sheet::FillDirection_TO_BOTTOM,
+ fillSeries(sheet::FillDirection_TO_BOTTOM,
sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF);
}
@@ -1807,7 +1913,7 @@ ScVbaRange::Offset( const ::uno::Any &nRowOff, const uno::Any &nColOff ) throw (
ScCellRangesBase* pUnoRangesBase = getCellRangesBase();
ScRangeList aCellRanges = pUnoRangesBase->GetRangeList();
-
+
for ( ScRange* pRange = aCellRanges.First() ; pRange; pRange = aCellRanges.Next() )
{
@@ -1845,13 +1951,13 @@ ScVbaRange::CurrentRegion() throw (uno::RuntimeException)
uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
return xRange->CurrentRegion();
}
-
+
RangeHelper helper( mxRange );
- uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor =
+ uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor =
helper.getSheetCellCursor();
xSheetCellCursor->collapseToCurrentRegion();
uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW);
- return RangeHelper::createRangeFromRange( mxParent, mxContext, helper.getCellRangeFromSheet(), xCellRangeAddressable );
+ return RangeHelper::createRangeFromRange( mxParent, mxContext, helper.getCellRangeFromSheet(), xCellRangeAddressable );
}
uno::Reference< excel::XRange >
@@ -1867,11 +1973,11 @@ ScVbaRange::CurrentArray() throw (uno::RuntimeException)
return xRange->CurrentArray();
}
RangeHelper helper( mxRange );
- uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor =
+ uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor =
helper.getSheetCellCursor();
xSheetCellCursor->collapseToCurrentArray();
uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW);
- return RangeHelper::createRangeFromRange( mxParent, mxContext, helper.getCellRangeFromSheet(), xCellRangeAddressable );
+ return RangeHelper::createRangeFromRange( mxParent, mxContext, helper.getCellRangeFromSheet(), xCellRangeAddressable );
}
uno::Any
@@ -1886,15 +1992,24 @@ ScVbaRange::getFormulaArray() throw (uno::RuntimeException)
uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
return xRange->getFormulaArray();
}
-
+
uno::Reference< sheet::XCellRangeFormula> xCellRangeFormula( mxRange, uno::UNO_QUERY_THROW );
uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext );
uno::Any aMatrix;
- aMatrix = xConverter->convertTo( uno::makeAny( xCellRangeFormula->getFormulaArray() ) , getCppuType((uno::Sequence< uno::Sequence< uno::Any > >*)0) ) ;
+
+ //VBA, minz@cn.ibm.com
+ uno::Sequence< uno::Sequence<rtl::OUString> > aFmArray = xCellRangeFormula->getFormulaArray();
+ if( aFmArray.getLength() )
+ {
+ if( aFmArray.getLength() == 1 && aFmArray[0].getLength() == 1 )
+ aMatrix <<= aFmArray[0][0];
+ else
+ aMatrix = xConverter->convertTo( uno::makeAny( xCellRangeFormula->getFormulaArray() ) , getCppuType((uno::Sequence< uno::Sequence< uno::Any > >*)0) ) ;
+ }
return aMatrix;
}
-void
+void
ScVbaRange::setFormulaArray(const uno::Any& rFormula) throw (uno::RuntimeException)
{
// #TODO code within the test below "if ( m_Areas.... " can be removed
@@ -1960,8 +2075,8 @@ ScVbaRange::Address( const uno::Any& RowAbsolute, const uno::Any& ColumnAbsolut
}
sAddress += xRange->Address( RowAbsolute, ColumnAbsolute, ReferenceStyle, aExternalCopy, RelativeTo );
}
- return sAddress;
-
+ return sAddress;
+
}
ScAddress::Details dDetails( formula::FormulaGrammar::CONV_XL_A1, 0, 0 );
if ( ReferenceStyle.hasValue() )
@@ -1975,7 +2090,7 @@ ScVbaRange::Address( const uno::Any& RowAbsolute, const uno::Any& ColumnAbsolut
ScDocShell* pDocShell = getScDocShell();
ScDocument* pDoc = pDocShell->GetDocument();
- RangeHelper thisRange( mxRange );
+ RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
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 ) );
String sRange;
@@ -2007,11 +2122,11 @@ ScVbaRange::Address( const uno::Any& RowAbsolute, const uno::Any& ColumnAbsolut
if ( RelativeTo.hasValue() )
{
// #TODO should I throw an error if R1C1 is not set?
-
+
table::CellRangeAddress refAddress = getCellRangeAddressForVBARange( RelativeTo, pDocShell );
dDetails = ScAddress::Details( formula::FormulaGrammar::CONV_XL_R1C1, static_cast< SCROW >( refAddress.StartRow ), static_cast< SCCOL >( refAddress.StartColumn ) );
}
- aRange.Format( sRange, nFlags, pDoc, dDetails );
+ aRange.Format( sRange, nFlags, pDoc, dDetails );
return sRange;
}
@@ -2027,18 +2142,18 @@ ScVbaRange::Font() throw ( script::BasicErrorException, uno::RuntimeException)
if ( !pDoc )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access document from shell" ) ), uno::Reference< uno::XInterface >() );
- ScVbaPalette aPalette( pDoc->GetDocumentShell() );
+ ScVbaPalette aPalette( pDoc->GetDocumentShell() );
ScCellRangeObj* pRangeObj = NULL;
try
{
pRangeObj = getCellRangeObj();
}
- catch( uno::Exception& )
+ catch( uno::Exception& )
{
}
return new ScVbaFont( this, mxContext, aPalette, xProps, pRangeObj );
}
-
+
uno::Reference< excel::XRange >
ScVbaRange::Cells( const uno::Any &nRowIndex, const uno::Any &nColumnIndex ) throw(uno::RuntimeException)
{
@@ -2061,29 +2176,65 @@ ScVbaRange::Cells( const uno::Any &nRowIndex, const uno::Any &nColumnIndex ) thr
// set in the Any, we should convert as appropriate
// #FIXME - perhaps worth turning this into some sort of
// convertion routine e.g. bSuccess = getValueFromAny( nRow, nRowIndex, getCppuType((sal_Int32*)0) )
- if ( nRowIndex.hasValue() && !( nRowIndex >>= nRow ) )
+ uno::Any aRowIndexAny = nRowIndex;
+ if ( aRowIndexAny.getValueTypeClass() == uno::TypeClass_INTERFACE )
{
- uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext );
- uno::Any aConverted;
try
{
- aConverted = xConverter->convertTo( nRowIndex, getCppuType((sal_Int32*)0) );
- bIsIndex = ( aConverted >>= nRow );
+ aRowIndexAny = getDefaultPropByIntrospection( aRowIndexAny );
}
- catch( uno::Exception& ) {} // silence any errors
+ catch( uno::Exception& ) {}
}
- if ( bIsColumnIndex && !( nColumnIndex >>= nColumn ) )
+ else if ( aRowIndexAny.hasValue() && !( aRowIndexAny >>= nRow ) )
{
uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext );
uno::Any aConverted;
try
{
- aConverted = xConverter->convertTo( nColumnIndex, getCppuType((sal_Int32*)0) );
- bIsColumnIndex = ( aConverted >>= nColumn );
+ aConverted = xConverter->convertTo( aRowIndexAny, getCppuType((sal_Int32*)0) );
+ bIsIndex = ( aConverted >>= nRow );
}
catch( uno::Exception& ) {} // silence any errors
}
-
+
+ uno::Any aColumnAny = nColumnIndex;
+
+ if ( bIsColumnIndex )
+ {
+ // Column index can be a col address e.g Cells( 1, "B" ) etc.
+ rtl::OUString sCol;
+ if ( nColumnIndex >>= sCol )
+ {
+ ScAddress::Details dDetails( formula::FormulaGrammar::CONV_XL_A1, 0, 0 );
+ ScRange tmpRange;
+ USHORT flags = tmpRange.ParseCols( sCol, excel::GetDocumentFromRange( mxRange ), dDetails );
+ if ( ( flags & 0x200 ) != 0x200 )
+ throw uno::RuntimeException();
+ nColumn = tmpRange.aStart.Col() + 1;
+ }
+ else
+ {
+ if ( aColumnAny.getValueTypeClass() == uno::TypeClass_INTERFACE )
+ {
+ try
+ {
+ aColumnAny = getDefaultPropByIntrospection( aColumnAny );
+ }
+ catch( uno::Exception& ) {}
+ }
+ if ( !( aColumnAny >>= nColumn ) )
+ {
+ uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext );
+ uno::Any aConverted;
+ try
+ {
+ aConverted = xConverter->convertTo( aColumnAny, getCppuType((sal_Int32*)0) );
+ bIsColumnIndex = ( aConverted >>= nColumn );
+ }
+ catch( uno::Exception& ) {} // silence any errors
+ }
+ }
+ }
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisRangeAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
uno::Reference< table::XCellRange > xSheetRange = thisRange.getCellRangeFromSheet();
@@ -2106,7 +2257,7 @@ ScVbaRange::Cells( const uno::Any &nRowIndex, const uno::Any &nColumnIndex ) thr
else
--nColumn;
nRow = nRow + thisRangeAddress.StartRow;
- nColumn = nColumn + thisRangeAddress.StartColumn;
+ nColumn = nColumn + thisRangeAddress.StartColumn;
return new ScVbaRange( mxParent, mxContext, xSheetRange->getCellRangeByPosition( nColumn, nRow, nColumn, nRow ) );
}
@@ -2136,7 +2287,7 @@ ScVbaRange::Select() throw (uno::RuntimeException)
}
catch( uno::Exception& )
{
- }
+ }
}
}
@@ -2176,14 +2327,14 @@ ScVbaRange::Activate() throw (uno::RuntimeException)
RangeHelper thisRange( xCellRange );
uno::Reference< sheet::XCellRangeAddressable > xThisRangeAddress = thisRange.getCellRangeAddressable();
table::CellRangeAddress thisRangeAddress = xThisRangeAddress->getRangeAddress();
- uno::Reference< frame::XModel > xModel;
+ uno::Reference< frame::XModel > xModel;
ScDocShell* pShell = getScDocShell();
if ( pShell )
xModel = pShell->GetModel();
if ( !xModel.is() )
- throw uno::RuntimeException();
+ throw uno::RuntimeException();
// get current selection
uno::Reference< sheet::XCellRangeAddressable > xRange( xModel->getCurrentSelection(), ::uno::UNO_QUERY);
@@ -2200,9 +2351,9 @@ ScVbaRange::Activate() throw (uno::RuntimeException)
setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel );
return;
}
-
+
}
- }
+ }
if ( xRange.is() && cellInRange( xRange->getRangeAddress(), thisRangeAddress.StartColumn, thisRangeAddress.StartRow ) )
setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel );
@@ -2210,7 +2361,7 @@ ScVbaRange::Activate() throw (uno::RuntimeException)
{
// if this range is multi cell select the range other
// wise just position the cell at this single range position
- if ( isSingleCellRange() )
+ if ( isSingleCellRange() )
// This top-leftmost cell of this Range is not in the current
// selection so just select this range
setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel, false );
@@ -2240,12 +2391,12 @@ ScVbaRange::Rows(const uno::Any& aIndex ) throw (uno::RuntimeException)
aRange.aStart.SetRow( aRange.aStart.Row() + --nValue );
aRange.aEnd.SetRow( aRange.aStart.Row() );
}
-
- else if ( aIndex >>= sAddress )
+
+ else if ( aIndex >>= sAddress )
{
ScAddress::Details dDetails( formula::FormulaGrammar::CONV_XL_A1, 0, 0 );
ScRange tmpRange;
- tmpRange.ParseRows( sAddress, getDocumentFromRange( mxRange ), dDetails );
+ tmpRange.ParseRows( sAddress, excel::GetDocumentFromRange( mxRange ), dDetails );
nStartRow = tmpRange.aStart.Row();
nEndRow = tmpRange.aEnd.Row();
@@ -2254,7 +2405,7 @@ ScVbaRange::Rows(const uno::Any& aIndex ) throw (uno::RuntimeException)
}
else
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Illegal param" ) ), uno::Reference< uno::XInterface >() );
-
+
if ( aRange.aStart.Row() < 0 || aRange.aEnd.Row() < 0 )
throw uno::RuntimeException( rtl::OUString::createFromAscii("Internal failure, illegal param"), uno::Reference< uno::XInterface >() );
// return a normal range ( even for multi-selection
@@ -2265,7 +2416,7 @@ ScVbaRange::Rows(const uno::Any& aIndex ) throw (uno::RuntimeException)
if ( m_Areas->getCount() > 1 )
return new ScVbaRange( mxParent, mxContext, mxRanges, true );
return new ScVbaRange( mxParent, mxContext, mxRange, true );
-}
+}
uno::Reference< excel::XRange >
ScVbaRange::Columns(const uno::Any& aIndex ) throw (uno::RuntimeException)
@@ -2287,12 +2438,12 @@ ScVbaRange::Columns(const uno::Any& aIndex ) throw (uno::RuntimeException)
aRange.aStart.SetCol( aRange.aStart.Col() + static_cast< SCCOL > ( --nValue ) );
aRange.aEnd.SetCol( aRange.aStart.Col() );
}
-
- else if ( aIndex >>= sAddress )
+
+ else if ( aIndex >>= sAddress )
{
ScAddress::Details dDetails( formula::FormulaGrammar::CONV_XL_A1, 0, 0 );
ScRange tmpRange;
- tmpRange.ParseCols( sAddress, getDocumentFromRange( mxRange ), dDetails );
+ tmpRange.ParseCols( sAddress, excel::GetDocumentFromRange( mxRange ), dDetails );
nStartCol = tmpRange.aStart.Col();
nEndCol = tmpRange.aEnd.Col();
@@ -2301,14 +2452,14 @@ ScVbaRange::Columns(const uno::Any& aIndex ) throw (uno::RuntimeException)
}
else
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Illegal param" ) ), uno::Reference< uno::XInterface >() );
-
+
if ( aRange.aStart.Col() < 0 || aRange.aEnd.Col() < 0 )
throw uno::RuntimeException( rtl::OUString::createFromAscii("Internal failure, illegal param"), uno::Reference< uno::XInterface >() );
}
// Columns() - no params
uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pUnoRangesBase->GetDocShell(), aRange ) );
return new ScVbaRange( mxParent, mxContext, xRange, false, true );
-}
+}
void
ScVbaRange::setMergeCells( const uno::Any& aIsMerged ) throw (script::BasicErrorException, uno::RuntimeException)
@@ -2343,7 +2494,7 @@ ScVbaRange::setMergeCells( const uno::Any& aIsMerged ) throw (script::BasicError
// otherwise, merge single range
lclExpandAndMerge( mxRange, bMerge );
}
-
+
uno::Any
ScVbaRange::getMergeCells() throw (script::BasicErrorException, uno::RuntimeException)
{
@@ -2372,7 +2523,7 @@ ScVbaRange::getMergeCells() throw (script::BasicErrorException, uno::RuntimeExce
default: return aNULL();
}
}
-
+
void
ScVbaRange::Copy(const ::uno::Any& Destination) throw (uno::RuntimeException)
{
@@ -2395,9 +2546,11 @@ ScVbaRange::Copy(const ::uno::Any& Destination) throw (uno::RuntimeException)
}
else
{
- uno::Reference< frame::XModel > xModel = getModelFromRange( mxRange );
- Select();
- excel::implnCopy( xModel );
+ ScRange aRange;
+ RangeHelper thisRange( mxRange );
+ ScUnoConversion::FillScRange( aRange, thisRange.getCellRangeAddressable()->getRangeAddress() );
+ uno::Reference< frame::XModel > xModel = excel::GetModelFromRange( mxRange );
+ excel::implnCopyRange( xModel, aRange );
}
}
@@ -2419,13 +2572,14 @@ ScVbaRange::Cut(const ::uno::Any& Destination) throw (uno::RuntimeException)
uno::Reference< sheet::XCellRangeAddressable > xSource( mxRange, uno::UNO_QUERY);
xMover->moveRange( xDestination->getCellAddress(), xSource->getRangeAddress() );
}
- {
- uno::Reference< frame::XModel > xModel = getModelFromRange( mxRange );
+ //VBA, minz@cn.ibm.com.
+ else {
+ uno::Reference< frame::XModel > xModel = excel::GetModelFromRange( mxRange );
Select();
excel::implnCut( xModel );
}
}
-
+
void
ScVbaRange::setNumberFormat( const uno::Any& aFormat ) throw ( script::BasicErrorException, uno::RuntimeException)
{
@@ -2437,14 +2591,14 @@ ScVbaRange::setNumberFormat( const uno::Any& aFormat ) throw ( script::BasicErro
for ( sal_Int32 index=1; index <= nItems; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
- xRange->setNumberFormat( aFormat );
+ xRange->setNumberFormat( aFormat );
}
return;
}
NumFormatHelper numFormat( mxRange );
numFormat.setNumberFormat( sFormat );
}
-
+
uno::Any
ScVbaRange::getNumberFormat() throw ( script::BasicErrorException, uno::RuntimeException)
{
@@ -2461,8 +2615,8 @@ ScVbaRange::getNumberFormat() throw ( script::BasicErrorException, uno::RuntimeE
if ( index > 1 )
if ( aResult != xRange->getNumberFormat() )
return aNULL();
- aResult = xRange->getNumberFormat();
- if ( aNULL() == aResult )
+ aResult = xRange->getNumberFormat();
+ if ( aNULL() == aResult )
return aNULL();
}
return aResult;
@@ -2497,7 +2651,7 @@ ScVbaRange::Resize( const uno::Any &RowSize, const uno::Any &ColumnSize ) throw
xCellRangeAddressable->getRangeAddress().EndColumn,
xCellRangeAddressable->getRangeAddress().EndRow ) );
}
-
+
void
ScVbaRange::setWrapText( const uno::Any& aIsWrapped ) throw (script::BasicErrorException, uno::RuntimeException)
{
@@ -2508,7 +2662,7 @@ ScVbaRange::setWrapText( const uno::Any& aIsWrapped ) throw (script::BasicErrorE
for ( sal_Int32 index=1; index <= nItems; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
- xRange->setWrapText( aIsWrapped );
+ xRange->setWrapText( aIsWrapped );
}
return;
}
@@ -2517,7 +2671,7 @@ ScVbaRange::setWrapText( const uno::Any& aIsWrapped ) throw (script::BasicErrorE
bool bIsWrapped = extractBoolFromAny( aIsWrapped );
xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsTextWrapped" ) ), uno::Any( bIsWrapped ) );
}
-
+
uno::Any
ScVbaRange::getWrapText() throw (script::BasicErrorException, uno::RuntimeException)
{
@@ -2531,17 +2685,17 @@ ScVbaRange::getWrapText() throw (script::BasicErrorException, uno::RuntimeExcept
if ( index > 1 )
if ( aResult != xRange->getWrapText() )
return aNULL();
- aResult = xRange->getWrapText();
+ aResult = xRange->getWrapText();
}
return aResult;
}
SfxItemSet* pDataSet = getCurrentDataSet();
-
+
SfxItemState eState = pDataSet->GetItemState( ATTR_LINEBREAK, TRUE, NULL);
if ( eState == SFX_ITEM_DONTCARE )
return aNULL();
-
+
uno::Reference< beans::XPropertySet > xProps(mxRange, ::uno::UNO_QUERY_THROW );
uno::Any aValue = xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsTextWrapped" ) ) );
return aValue;
@@ -2551,7 +2705,7 @@ uno::Reference< excel::XInterior > ScVbaRange::Interior( ) throw ( script::Basic
{
uno::Reference< beans::XPropertySet > xProps( mxRange, uno::UNO_QUERY_THROW );
return new ScVbaInterior ( this, mxContext, xProps, getScDocument() );
-}
+}
uno::Reference< excel::XRange >
ScVbaRange::Range( const uno::Any &Cell1, const uno::Any &Cell2 ) throw (uno::RuntimeException)
{
@@ -2575,11 +2729,11 @@ ScVbaRange::Range( const uno::Any &Cell1, const uno::Any &Cell2, bool bForceUseI
uno::Reference< table::XCellRange > xRanges = thisRange.getCellRangeFromSheet();
uno::Reference< sheet::XCellRangeAddressable > xAddressable( xRanges, uno::UNO_QUERY_THROW );
- uno::Reference< table::XCellRange > xReferrer =
- xRanges->getCellRangeByPosition( getColumn()-1, getRow()-1,
- xAddressable->getRangeAddress().EndColumn,
+ uno::Reference< table::XCellRange > xReferrer =
+ xRanges->getCellRangeByPosition( getColumn()-1, getRow()-1,
+ xAddressable->getRangeAddress().EndColumn,
xAddressable->getRangeAddress().EndRow );
- // xAddressable now for this range
+ // xAddressable now for this range
xAddressable.set( xReferrer, uno::UNO_QUERY_THROW );
if( !Cell1.hasValue() )
@@ -2596,20 +2750,20 @@ ScVbaRange::Range( const uno::Any &Cell1, const uno::Any &Cell2, bool bForceUseI
{
rtl::OUString sName;
Cell1 >>= sName;
- RangeHelper referRange( xReferrer );
+ RangeHelper referRange( xReferrer );
table::CellRangeAddress referAddress = referRange.getCellRangeAddressable()->getRangeAddress();
return getRangeForName( mxContext, sName, getScDocShell(), referAddress );
-
+
}
else
{
table::CellRangeAddress cell1, cell2;
- cell1 = getCellRangeAddressForVBARange( Cell1, getScDocShell() );
+ cell1 = getCellRangeAddressForVBARange( Cell1, getScDocShell() );
// Cell1 & Cell2 defined
// Excel seems to combine the range as the range defined by
// the combination of Cell1 & Cell2
-
- cell2 = getCellRangeAddressForVBARange( Cell2, getScDocShell() );
+
+ cell2 = getCellRangeAddressForVBARange( Cell2, getScDocShell() );
resultAddress.StartColumn = ( cell1.StartColumn < cell2.StartColumn ) ? cell1.StartColumn : cell2.StartColumn;
resultAddress.StartRow = ( cell1.StartRow < cell2.StartRow ) ? cell1.StartRow : cell2.StartRow;
@@ -2629,8 +2783,8 @@ ScVbaRange::Range( const uno::Any &Cell1, const uno::Any &Cell2, bool bForceUseI
// this is not a call from Application.Range( x,y )
// if a different sheet from this range is specified it's
// an error
- if ( parentRangeAddress.Sheet != cell1.Sheet
- || parentRangeAddress.Sheet != cell2.Sheet
+ if ( parentRangeAddress.Sheet != cell1.Sheet
+ || parentRangeAddress.Sheet != cell2.Sheet
)
throw uno::RuntimeException();
@@ -2638,7 +2792,7 @@ ScVbaRange::Range( const uno::Any &Cell1, const uno::Any &Cell2, bool bForceUseI
ScUnoConversion::FillScRange( aRange, resultAddress );
}
ScRange parentAddress;
- ScUnoConversion::FillScRange( parentAddress, parentRangeAddress);
+ ScUnoConversion::FillScRange( parentAddress, parentRangeAddress);
if ( aRange.aStart.Col() >= 0 && aRange.aStart.Row() >= 0 && aRange.aEnd.Col() >= 0 && aRange.aEnd.Row() >= 0 )
{
sal_Int32 nStartX = parentAddress.aStart.Col() + aRange.aStart.Col();
@@ -2654,13 +2808,13 @@ ScVbaRange::Range( const uno::Any &Cell1, const uno::Any &Cell2, bool bForceUseI
xCellRange = new ScCellRangeObj( getScDocShell(), aNew );
}
}
-
+
return new ScVbaRange( mxParent, mxContext, xCellRange );
}
// Allow access to underlying openoffice uno api ( useful for debugging
-// with openoffice basic )
+// with openoffice basic )
uno::Any SAL_CALL ScVbaRange::getCellRange( ) throw (uno::RuntimeException)
{
uno::Any aAny;
@@ -2678,19 +2832,19 @@ uno::Any SAL_CALL ScVbaRange::getCellRange( ) throw (uno::RuntimeException)
throw uno::RuntimeException();
}
-static USHORT
+static USHORT
getPasteFlags (sal_Int32 Paste)
{
- USHORT nFlags = IDF_NONE;
+ USHORT nFlags = IDF_NONE;
switch (Paste) {
- case excel::XlPasteType::xlPasteComments:
+ case excel::XlPasteType::xlPasteComments:
nFlags = IDF_NOTE;break;
- case excel::XlPasteType::xlPasteFormats:
+ case excel::XlPasteType::xlPasteFormats:
nFlags = IDF_ATTRIB;break;
- case excel::XlPasteType::xlPasteFormulas:
+ case excel::XlPasteType::xlPasteFormulas:
nFlags = IDF_FORMULA;break;
- case excel::XlPasteType::xlPasteFormulasAndNumberFormats :
- case excel::XlPasteType::xlPasteValues:
+ case excel::XlPasteType::xlPasteFormulasAndNumberFormats :
+ case excel::XlPasteType::xlPasteValues:
#ifdef VBA_OOBUILD_HACK
nFlags = ( IDF_VALUE | IDF_DATETIME | IDF_STRING | IDF_SPECIAL_BOOLEAN ); break;
#else
@@ -2699,52 +2853,50 @@ getPasteFlags (sal_Int32 Paste)
case excel::XlPasteType::xlPasteValuesAndNumberFormats:
nFlags = IDF_VALUE | IDF_ATTRIB; break;
case excel::XlPasteType::xlPasteColumnWidths:
- case excel::XlPasteType::xlPasteValidation:
+ case excel::XlPasteType::xlPasteValidation:
nFlags = IDF_NONE;break;
- case excel::XlPasteType::xlPasteAll:
- case excel::XlPasteType::xlPasteAllExceptBorders:
+ case excel::XlPasteType::xlPasteAll:
+ case excel::XlPasteType::xlPasteAllExceptBorders:
default:
nFlags = IDF_ALL;break;
};
return nFlags;
}
-static USHORT
+static USHORT
getPasteFormulaBits( sal_Int32 Operation)
{
USHORT nFormulaBits = PASTE_NOFUNC ;
switch (Operation)
{
- case excel::XlPasteSpecialOperation::xlPasteSpecialOperationAdd:
+ case excel::XlPasteSpecialOperation::xlPasteSpecialOperationAdd:
nFormulaBits = PASTE_ADD;break;
- case excel::XlPasteSpecialOperation::xlPasteSpecialOperationSubtract:
+ case excel::XlPasteSpecialOperation::xlPasteSpecialOperationSubtract:
nFormulaBits = PASTE_SUB;break;
- case excel::XlPasteSpecialOperation::xlPasteSpecialOperationMultiply:
+ case excel::XlPasteSpecialOperation::xlPasteSpecialOperationMultiply:
nFormulaBits = PASTE_MUL;break;
case excel::XlPasteSpecialOperation::xlPasteSpecialOperationDivide:
nFormulaBits = PASTE_DIV;break;
- case excel::XlPasteSpecialOperation::xlPasteSpecialOperationNone:
+ case excel::XlPasteSpecialOperation::xlPasteSpecialOperationNone:
default:
nFormulaBits = PASTE_NOFUNC; break;
};
-
+
return nFormulaBits;
}
-void SAL_CALL
-ScVbaRange::PasteSpecial( const uno::Any& Paste, const uno::Any& Operation, const uno::Any& SkipBlanks, const uno::Any& Transpose ) throw (::com::sun::star::uno::RuntimeException)
+void SAL_CALL
+ScVbaRange::PasteSpecial( const uno::Any& Paste, const uno::Any& Operation, const uno::Any& SkipBlanks, const uno::Any& Transpose ) throw (::com::sun::star::uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("That command cannot be used on multiple selections" ) ), uno::Reference< uno::XInterface >() );
- ScDocShell* pShell = getScDocShell();
-
+ ScDocShell* pShell = getScDocShell();
+
uno::Reference< frame::XModel > xModel( ( pShell ? pShell->GetModel() : NULL ), uno::UNO_QUERY_THROW );
uno::Reference< view::XSelectionSupplier > xSelection( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
- // save old selection
- uno::Reference< uno::XInterface > xSel( xModel->getCurrentSelection() );
// select this range
xSelection->select( uno::makeAny( mxRange ) );
- // set up defaults
+ // set up defaults
sal_Int32 nPaste = excel::XlPasteType::xlPasteAll;
sal_Int32 nOperation = excel::XlPasteSpecialOperation::xlPasteSpecialOperationNone;
sal_Bool bTranspose = sal_False;
@@ -2762,24 +2914,22 @@ ScVbaRange::PasteSpecial( const uno::Any& Paste, const uno::Any& Operation, cons
USHORT nFlags = getPasteFlags(nPaste);
USHORT nFormulaBits = getPasteFormulaBits(nOperation);
excel::implnPasteSpecial(pShell->GetModel(), nFlags,nFormulaBits,bSkipBlanks,bTranspose);
- // restore selection
- xSelection->select( uno::makeAny( xSel ) );
}
-uno::Reference< excel::XRange >
+uno::Reference< excel::XRange >
ScVbaRange::getEntireColumnOrRow( bool bColumn ) throw (uno::RuntimeException)
{
ScCellRangesBase* pUnoRangesBase = getCellRangesBase();
// copy the range list
- ScRangeList aCellRanges = pUnoRangesBase->GetRangeList();
+ ScRangeList aCellRanges = pUnoRangesBase->GetRangeList();
for ( ScRange* pRange = aCellRanges.First() ; pRange; pRange = aCellRanges.Next() )
{
- if ( bColumn )
+ if ( bColumn )
{
pRange->aStart.SetRow( 0 );
pRange->aEnd.SetRow( MAXROW );
- }
+ }
else
{
pRange->aStart.SetCol( 0 );
@@ -2789,32 +2939,32 @@ ScVbaRange::getEntireColumnOrRow( bool bColumn ) throw (uno::RuntimeException)
if ( aCellRanges.Count() > 1 ) // Multi-Area
{
uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( pUnoRangesBase->GetDocShell(), aCellRanges ) );
-
+
return new ScVbaRange( mxParent, mxContext, xRanges, !bColumn, bColumn );
}
uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pUnoRangesBase->GetDocShell(), *aCellRanges.First() ) );
return new ScVbaRange( mxParent, mxContext, xRange, !bColumn, bColumn );
}
-uno::Reference< excel::XRange > SAL_CALL
+uno::Reference< excel::XRange > SAL_CALL
ScVbaRange::getEntireRow() throw (uno::RuntimeException)
{
return getEntireColumnOrRow(false);
}
-uno::Reference< excel::XRange > SAL_CALL
+uno::Reference< excel::XRange > SAL_CALL
ScVbaRange::getEntireColumn() throw (uno::RuntimeException)
{
return getEntireColumnOrRow();
}
-uno::Reference< excel::XComment > SAL_CALL
+uno::Reference< excel::XComment > SAL_CALL
ScVbaRange::AddComment( const uno::Any& Text ) throw (uno::RuntimeException)
{
// if there is already a comment in the top-left cell then throw
if( getComment().is() )
throw uno::RuntimeException();
-
+
// workaround: Excel allows to create empty comment, Calc does not
::rtl::OUString aNoteText;
if( Text.hasValue() && !(Text >>= aNoteText) )
@@ -2841,7 +2991,7 @@ ScVbaRange::getComment() throw (uno::RuntimeException)
if ( !xComment->Text( uno::Any(), uno::Any(), uno::Any() ).getLength() )
return NULL;
return xComment;
-
+
}
uno::Reference< beans::XPropertySet >
@@ -2853,18 +3003,18 @@ getRowOrColumnProps( const uno::Reference< table::XCellRange >& xCellRange, bool
xProps.set( xColRow->getRows(), uno::UNO_QUERY_THROW );
else
xProps.set( xColRow->getColumns(), uno::UNO_QUERY_THROW );
- return xProps;
+ return xProps;
}
-uno::Any SAL_CALL
+uno::Any SAL_CALL
ScVbaRange::getHidden() throw (uno::RuntimeException)
{
- // if multi-area result is the result of the
+ // if multi-area result is the result of the
// first area
if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(sal_Int32(1)), uno::Any() ), uno::UNO_QUERY_THROW );
- return xRange->getHidden();
+ return xRange->getHidden();
}
bool bIsVisible = false;
try
@@ -2877,10 +3027,10 @@ ScVbaRange::getHidden() throw (uno::RuntimeException)
{
throw uno::RuntimeException( e.Message, uno::Reference< uno::XInterface >() );
}
- return uno::makeAny( !bIsVisible );
+ return uno::makeAny( !bIsVisible );
}
-void SAL_CALL
+void SAL_CALL
ScVbaRange::setHidden( const uno::Any& _hidden ) throw (uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
@@ -2889,7 +3039,7 @@ ScVbaRange::setHidden( const uno::Any& _hidden ) throw (uno::RuntimeException)
for ( sal_Int32 index=1; index <= nItems; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
- xRange->setHidden( _hidden );
+ xRange->setHidden( _hidden );
}
return;
}
@@ -2903,7 +3053,7 @@ ScVbaRange::setHidden( const uno::Any& _hidden ) throw (uno::RuntimeException)
catch( uno::Exception& e )
{
throw uno::RuntimeException( e.Message, uno::Reference< uno::XInterface >() );
- }
+ }
}
::sal_Bool SAL_CALL
@@ -2916,8 +3066,8 @@ ScVbaRange::Replace( const ::rtl::OUString& What, const ::rtl::OUString& Replace
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
xRange->Replace( What, Replacement, LookAt, SearchOrder, MatchCase, MatchByte, SearchFormat, ReplaceFormat );
}
- return sal_True; // seems to return true always ( or at least I haven't found the trick of
- }
+ return sal_True; // seems to return true always ( or at least I haven't found the trick of
+ }
// sanity check required params
if ( !What.getLength() /*|| !Replacement.getLength()*/ )
@@ -2928,7 +3078,7 @@ ScVbaRange::Replace( const ::rtl::OUString& What, const ::rtl::OUString& Replace
const SvxSearchItem& globalSearchOptions = ScGlobal::GetSearchItem();
SvxSearchItem newOptions( globalSearchOptions );
- sal_Int16 nLook = globalSearchOptions.GetWordOnly() ? excel::XlLookAt::xlPart : excel::XlLookAt::xlWhole;
+ sal_Int16 nLook = globalSearchOptions.GetWordOnly() ? excel::XlLookAt::xlPart : excel::XlLookAt::xlWhole;
sal_Int16 nSearchOrder = globalSearchOptions.GetRowDirection() ? excel::XlSearchOrder::xlByRows : excel::XlSearchOrder::xlByColumns;
sal_Bool bMatchCase = sal_False;
@@ -2937,10 +3087,10 @@ ScVbaRange::Replace( const ::rtl::OUString& What, const ::rtl::OUString& Replace
{
uno::Reference< util::XReplaceDescriptor > xDescriptor =
xReplace->createReplaceDescriptor();
-
- xDescriptor->setSearchString( sWhat);
- xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHREGEXP ) ), uno::makeAny( sal_True ) );
- xDescriptor->setReplaceString( Replacement);
+
+ xDescriptor->setSearchString( sWhat);
+ xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHREGEXP ) ), uno::makeAny( sal_True ) );
+ xDescriptor->setReplaceString( Replacement);
if ( LookAt.hasValue() )
{
// sets SearchWords ( true is Cell match )
@@ -2955,7 +3105,7 @@ ScVbaRange::Replace( const ::rtl::OUString& What, const ::rtl::OUString& Replace
// set global search props ( affects the find dialog
// and of course the defaults for this method
newOptions.SetWordOnly( bSearchWords );
- xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHWORDS ) ), uno::makeAny( bSearchWords ) );
+ xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHWORDS ) ), uno::makeAny( bSearchWords ) );
}
// sets SearchByRow ( true for Rows )
if ( SearchOrder.hasValue() )
@@ -2968,35 +3118,44 @@ ScVbaRange::Replace( const ::rtl::OUString& What, const ::rtl::OUString& Replace
bSearchByRow = sal_True;
else
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Replace, illegal value for SearchOrder" )) , uno::Reference< uno::XInterface >() );
-
- newOptions.SetRowDirection( bSearchByRow );
- xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHBYROW ) ), uno::makeAny( bSearchByRow ) );
- }
+
+ newOptions.SetRowDirection( bSearchByRow );
+ xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHBYROW ) ), uno::makeAny( bSearchByRow ) );
+ }
if ( MatchCase.hasValue() )
{
// SearchCaseSensitive
- MatchCase >>= bMatchCase;
- xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHCASE ) ), uno::makeAny( bMatchCase ) );
- }
+ MatchCase >>= bMatchCase;
+ xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHCASE ) ), uno::makeAny( bMatchCase ) );
+ }
- ScGlobal::SetSearchItem( newOptions );
+ ScGlobal::SetSearchItem( newOptions );
// ignore MatchByte for the moment, its not supported in
// OOo.org afaik
uno::Reference< util::XSearchDescriptor > xSearch( xDescriptor, uno::UNO_QUERY );
+ // Find all cells that being replaced, used to fire the range changed event.
+ uno::Reference< container::XIndexAccess > xIndexAccess = xReplace->findAll( xSearch );
xReplace->replaceAll( xSearch );
+
+ if ( xIndexAccess.is() && xIndexAccess->getCount() > 0 )
+ {
+ // Fires the range change event.
+ ScCellRangesBase* pScCellRangesBase = ScCellRangesBase::getImplementation( xIndexAccess ); //liuchen 2010-01-05
+ lcl_NotifyRangeChanges( getScDocShell()->GetModel(), pScCellRangesBase ); //liuchen 2010-01-05 the original convert method will fail in SUSE
+ }
}
return sal_True; // always
}
-uno::Reference< excel::XRange > SAL_CALL
+uno::Reference< excel::XRange > SAL_CALL
ScVbaRange::Find( const uno::Any& What, const uno::Any& After, const uno::Any& LookIn, const uno::Any& LookAt, const uno::Any& SearchOrder, const uno::Any& SearchDirection, const uno::Any& MatchCase, const uno::Any& /*MatchByte*/, const uno::Any& /*SearchFormat*/ ) throw (uno::RuntimeException)
{
// return a Range object that represents the first cell where that information is found.
rtl::OUString sWhat;
sal_Int32 nWhat = 0;
double fWhat = 0.0;
-
+
// string.
if( What >>= sWhat )
{
@@ -3019,7 +3178,7 @@ ScVbaRange::Find( const uno::Any& What, const uno::Any& After, const uno::Any& L
const SvxSearchItem& globalSearchOptions = ScGlobal::GetSearchItem();
SvxSearchItem newOptions( globalSearchOptions );
- sal_Int16 nLookAt = globalSearchOptions.GetWordOnly() ? excel::XlLookAt::xlPart : excel::XlLookAt::xlWhole;
+ sal_Int16 nLookAt = globalSearchOptions.GetWordOnly() ? excel::XlLookAt::xlPart : excel::XlLookAt::xlWhole;
sal_Int16 nSearchOrder = globalSearchOptions.GetRowDirection() ? excel::XlSearchOrder::xlByRows : excel::XlSearchOrder::xlByColumns;
uno::Reference< util::XSearchable > xSearch( mxRange, uno::UNO_QUERY );
@@ -3048,7 +3207,7 @@ ScVbaRange::Find( const uno::Any& What, const uno::Any& After, const uno::Any& L
sal_Int32 nLookIn = 0;
if( LookIn >>= nLookIn )
{
- sal_Int16 nSearchType = 0;
+ sal_Int16 nSearchType = 0;
switch( nLookIn )
{
case excel::XlFindLookIn::xlComments :
@@ -3080,7 +3239,7 @@ ScVbaRange::Find( const uno::Any& What, const uno::Any& After, const uno::Any& L
else
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Replace, illegal value for LookAt" )) , uno::Reference< uno::XInterface >() );
newOptions.SetWordOnly( bSearchWords );
- xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHWORDS ) ), uno::makeAny( bSearchWords ) );
+ xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHWORDS ) ), uno::makeAny( bSearchWords ) );
}
// SearchOrder
@@ -3094,10 +3253,10 @@ ScVbaRange::Find( const uno::Any& What, const uno::Any& After, const uno::Any& L
bSearchByRow = sal_True;
else
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Replace, illegal value for SearchOrder" )) , uno::Reference< uno::XInterface >() );
-
- newOptions.SetRowDirection( bSearchByRow );
- xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHBYROW ) ), uno::makeAny( bSearchByRow ) );
- }
+
+ newOptions.SetRowDirection( bSearchByRow );
+ xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHBYROW ) ), uno::makeAny( bSearchByRow ) );
+ }
// SearchDirection
if ( SearchDirection.hasValue() )
@@ -3107,7 +3266,7 @@ ScVbaRange::Find( const uno::Any& What, const uno::Any& After, const uno::Any& L
{
sal_Bool bSearchBackwards = sal_False;
if ( nSearchDirection == excel::XlSearchDirection::xlNext )
- bSearchBackwards = sal_False;
+ bSearchBackwards = sal_False;
else if( nSearchDirection == excel::XlSearchDirection::xlPrevious )
bSearchBackwards = sal_True;
else
@@ -3124,8 +3283,8 @@ ScVbaRange::Find( const uno::Any& What, const uno::Any& After, const uno::Any& L
// SearchCaseSensitive
if( !( MatchCase >>= bMatchCase ) )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Replace, illegal value for MatchCase" )) , uno::Reference< uno::XInterface >() );
- }
- xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHCASE ) ), uno::makeAny( bMatchCase ) );
+ }
+ xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHCASE ) ), uno::makeAny( bMatchCase ) );
// MatchByte
// SearchFormat
@@ -3135,6 +3294,13 @@ ScVbaRange::Find( const uno::Any& What, const uno::Any& After, const uno::Any& L
uno::Reference< uno::XInterface > xInterface = xStartCell.is() ? xSearch->findNext( xStartCell, xDescriptor) : xSearch->findFirst( xDescriptor );
uno::Reference< table::XCellRange > xCellRange( xInterface, uno::UNO_QUERY );
+ // if we are searching from a starting cell and failed to find a match
+ // then try from the begining
+ if ( !xCellRange.is() && xStartCell.is() )
+ {
+ xInterface = xSearch->findFirst( xDescriptor );
+ xCellRange.set( xInterface, uno::UNO_QUERY );
+ }
if ( xCellRange.is() )
{
uno::Reference< excel::XRange > xResultRange = new ScVbaRange( mxParent, mxContext, xCellRange );
@@ -3158,7 +3324,7 @@ uno::Reference< table::XCellRange > processKey( const uno::Any& Key, uno::Refere
xKeyRange.set( Key, uno::UNO_QUERY_THROW );
}
else if ( Key.getValueType() == ::getCppuType( static_cast< const rtl::OUString* >(0) ) )
-
+
{
rtl::OUString sRangeName = ::comphelper::getString( Key );
table::CellRangeAddress aRefAddr;
@@ -3191,11 +3357,11 @@ const rtl::OUString& sPropName ) throw( uno::RuntimeException )
// helper method for Sort
void updateTableSortField( const uno::Reference< table::XCellRange >& xParentRange,
- const uno::Reference< table::XCellRange >& xColRowKey, sal_Int16 nOrder,
+ const uno::Reference< table::XCellRange >& xColRowKey, sal_Int16 nOrder,
table::TableSortField& aTableField, sal_Bool bIsSortColumn, sal_Bool bMatchCase ) throw ( uno::RuntimeException )
{
- RangeHelper parentRange( xParentRange );
- RangeHelper colRowRange( xColRowKey );
+ RangeHelper parentRange( xParentRange );
+ RangeHelper colRowRange( xColRowKey );
table::CellRangeAddress parentRangeAddress = parentRange.getCellRangeAddressable()->getRangeAddress();
@@ -3204,27 +3370,27 @@ void updateTableSortField( const uno::Reference< table::XCellRange >& xParentRan
// make sure that upper left poing of key range is within the
// parent range
if ( ( !bIsSortColumn && colRowKeyAddress.StartColumn >= parentRangeAddress.StartColumn &&
- colRowKeyAddress.StartColumn <= parentRangeAddress.EndColumn ) || ( bIsSortColumn &&
+ colRowKeyAddress.StartColumn <= parentRangeAddress.EndColumn ) || ( bIsSortColumn &&
colRowKeyAddress.StartRow >= parentRangeAddress.StartRow &&
colRowKeyAddress.StartRow <= parentRangeAddress.EndRow ) )
{
//determine col/row index
if ( bIsSortColumn )
- aTableField.Field = colRowKeyAddress.StartRow - parentRangeAddress.StartRow;
+ aTableField.Field = colRowKeyAddress.StartRow - parentRangeAddress.StartRow;
else
- aTableField.Field = colRowKeyAddress.StartColumn - parentRangeAddress.StartColumn;
+ aTableField.Field = colRowKeyAddress.StartColumn - parentRangeAddress.StartColumn;
aTableField.IsCaseSensitive = bMatchCase;
- if ( nOrder == excel::XlSortOrder::xlAscending )
- aTableField.IsAscending = sal_True;
- else
- aTableField.IsAscending = sal_False;
+ if ( nOrder == excel::XlSortOrder::xlAscending )
+ aTableField.IsAscending = sal_True;
+ else
+ aTableField.IsAscending = sal_False;
}
else
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Illegal Key param" ) ), uno::Reference< uno::XInterface >() );
-
-}
+
+}
void SAL_CALL
ScVbaRange::Sort( const uno::Any& Key1, const uno::Any& Order1, const uno::Any& Key2, const uno::Any& /*Type*/, const uno::Any& Order2, const uno::Any& Key3, const uno::Any& Order3, const uno::Any& Header, const uno::Any& OrderCustom, const uno::Any& MatchCase, const uno::Any& Orientation, const uno::Any& SortMethod, const uno::Any& DataOption1, const uno::Any& DataOption2, const uno::Any& DataOption3 ) throw (uno::RuntimeException)
@@ -3257,14 +3423,14 @@ 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 a IsSingleCell() method
uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY_THROW );
-
+
// 'Fraid I don't remember what I was trying to achieve here ???
-/*
+/*
if ( isSingleCellRange() )
{
uno::Reference< XRange > xCurrent = CurrentRegion();
xCurrent->Sort( Key1, Order1, Key2, Type, Order2, Key3, Order3, Header, OrderCustom, MatchCase, Orientation, SortMethod, DataOption1, DataOption2, DataOption3 );
- return;
+ return;
}
*/
// set up defaults
@@ -3282,8 +3448,8 @@ ScVbaRange::Sort( const uno::Any& Key1, const uno::Any& Order1, const uno::Any&
if ( Orientation.hasValue() )
{
- // Documentation says xlSortRows is default but that doesn't appear to be
- // the case. Also it appears that xlSortColumns is the default which
+ // Documentation says xlSortRows is default but that doesn't appear to be
+ // the case. Also it appears that xlSortColumns is the default which
// strangely enought sorts by Row
nOrientation = ::comphelper::getINT16( Orientation );
// persist new option to be next calls default
@@ -3310,17 +3476,17 @@ ScVbaRange::Sort( const uno::Any& Key1, const uno::Any& Order1, const uno::Any&
#ifdef VBA_OOBUILD_HACK
aSortParam.nCompatHeader = nHeader;
#endif
- }
+ }
if ( nHeader == excel::XlYesNoGuess::xlGuess )
{
bool bHasColHeader = pDoc->HasColHeader( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), static_cast< SCCOL >( thisRangeAddress.EndColumn ), static_cast< SCROW >( thisRangeAddress.EndRow ), static_cast< SCTAB >( thisRangeAddress.Sheet ));
bool bHasRowHeader = pDoc->HasRowHeader( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), static_cast< SCCOL >( thisRangeAddress.EndColumn ), static_cast< SCROW >( thisRangeAddress.EndRow ), static_cast< SCTAB >( thisRangeAddress.Sheet ) );
if ( bHasColHeader || bHasRowHeader )
- nHeader = excel::XlYesNoGuess::xlYes;
+ nHeader = excel::XlYesNoGuess::xlYes;
else
- nHeader = excel::XlYesNoGuess::xlNo;
-#ifdef VBA_OOBUILD_HACK
+ nHeader = excel::XlYesNoGuess::xlNo;
+#ifdef VBA_OOBUILD_HACK
aSortParam.nCompatHeader = nHeader;
#endif
}
@@ -3332,7 +3498,7 @@ ScVbaRange::Sort( const uno::Any& Key1, const uno::Any& Order1, const uno::Any&
{
nSortMethod = ::comphelper::getINT16( SortMethod );
}
-
+
if ( OrderCustom.hasValue() )
{
OrderCustom >>= nCustom;
@@ -3349,7 +3515,7 @@ ScVbaRange::Sort( const uno::Any& Key1, const uno::Any& Order1, const uno::Any&
if ( Order1.hasValue() )
{
nOrder1 = ::comphelper::getINT16(Order1);
- if ( nOrder1 == excel::XlSortOrder::xlAscending )
+ if ( nOrder1 == excel::XlSortOrder::xlAscending )
aSortParam.bAscending[0] = TRUE;
else
aSortParam.bAscending[0] = FALSE;
@@ -3358,7 +3524,7 @@ ScVbaRange::Sort( const uno::Any& Key1, const uno::Any& Order1, const uno::Any&
if ( Order2.hasValue() )
{
nOrder2 = ::comphelper::getINT16(Order2);
- if ( nOrder2 == excel::XlSortOrder::xlAscending )
+ if ( nOrder2 == excel::XlSortOrder::xlAscending )
aSortParam.bAscending[1] = TRUE;
else
aSortParam.bAscending[1] = FALSE;
@@ -3366,15 +3532,15 @@ ScVbaRange::Sort( const uno::Any& Key1, const uno::Any& Order1, const uno::Any&
if ( Order3.hasValue() )
{
nOrder3 = ::comphelper::getINT16(Order3);
- if ( nOrder3 == excel::XlSortOrder::xlAscending )
+ if ( nOrder3 == excel::XlSortOrder::xlAscending )
aSortParam.bAscending[2] = TRUE;
else
aSortParam.bAscending[2] = FALSE;
}
- uno::Reference< table::XCellRange > xKey1;
- uno::Reference< table::XCellRange > xKey2;
- uno::Reference< table::XCellRange > xKey3;
+ uno::Reference< table::XCellRange > xKey1;
+ uno::Reference< table::XCellRange > xKey2;
+ uno::Reference< table::XCellRange > xKey3;
ScDocShell* pDocShell = getScDocShell();
xKey1 = processKey( Key1, mxContext, pDocShell );
if ( !xKey1.is() )
@@ -3393,22 +3559,22 @@ ScVbaRange::Sort( const uno::Any& Key1, const uno::Any& Order1, const uno::Any&
sal_Int32 nTableIndex = 0;
updateTableSortField( mxRange, xKey1, nOrder1, sTableFields[ nTableIndex++ ], bIsSortColumns, bMatchCase );
- if ( xKey2.is() )
+ if ( xKey2.is() )
{
sTableFields.realloc( sTableFields.getLength() + 1 );
updateTableSortField( mxRange, xKey2, nOrder2, sTableFields[ nTableIndex++ ], bIsSortColumns, bMatchCase );
}
- if ( xKey3.is() )
+ if ( xKey3.is() )
{
sTableFields.realloc( sTableFields.getLength() + 1 );
updateTableSortField( mxRange, xKey3, nOrder3, sTableFields[ nTableIndex++ ], bIsSortColumns, bMatchCase );
}
sortDescriptor[ nTableSortFieldIndex ].Value <<= sTableFields;
- sal_Int32 nIndex = findSortPropertyIndex( sortDescriptor, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsSortColumns")) );
+ sal_Int32 nIndex = findSortPropertyIndex( sortDescriptor, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsSortColumns")) );
sortDescriptor[ nIndex ].Value <<= bIsSortColumns;
- nIndex = findSortPropertyIndex( sortDescriptor, CONTS_HEADER );
+ nIndex = findSortPropertyIndex( sortDescriptor, CONTS_HEADER );
sortDescriptor[ nIndex ].Value <<= bContainsHeader;
pDoc->SetSortParam( aSortParam, nTab );
@@ -3419,7 +3585,7 @@ ScVbaRange::Sort( const uno::Any& Key1, const uno::Any& Order1, const uno::Any&
}
-uno::Reference< excel::XRange > SAL_CALL
+uno::Reference< excel::XRange > SAL_CALL
ScVbaRange::End( ::sal_Int32 Direction ) throw (uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
@@ -3428,76 +3594,45 @@ ScVbaRange::End( ::sal_Int32 Direction ) throw (uno::RuntimeException)
return xRange->End( Direction );
}
-
- // #FIXME #TODO
- // euch! found my orig implementation sucked, so
- // trying this even suckier one ( really need to use/expose code in
- // around ScTabView::MoveCursorArea(), thats the bit that calcutes
- // where the cursor should go )
- // Main problem with this method is the ultra hacky attempt to preserve
- // the ActiveCell, there should be no need to go to these extreems
-
- // Save ActiveCell pos ( to restore later )
- uno::Any aDft;
- uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
- rtl::OUString sActiveCell = xApplication->getActiveCell()->Address(aDft, aDft, aDft, aDft, aDft );
+ table::CellAddress aAddress = getLeftUpperCellAddress();
+ SCTAB nTab = aAddress.Sheet;
+ SCCOL nCurX = aAddress.Column;
+ SCROW nCurY = aAddress.Row;
+ SCCOL nNewX = nCurX;
+ SCROW nNewY = nCurY;
- // position current cell upper left of this range
- Cells( uno::makeAny( (sal_Int32) 1 ), uno::makeAny( (sal_Int32) 1 ) )->Select();
+ ScDocShell* pDocShell = getScDocShell();
+ ScDocument* pDoc = pDocShell->GetDocument();
- uno::Reference< frame::XModel > xModel = getModelFromRange( mxRange );
+ SCsCOL nMoveX = 0;
+ SCsROW nMoveY = 0;
+ switch ( Direction )
+ {
+ case excel::XlDirection::xlDown:
+ nMoveY = 1;
+ break;
+ case excel::XlDirection::xlUp:
+ nMoveY = -1;
+ break;
+ case excel::XlDirection::xlToLeft:
+ nMoveX = -1;
+ break;
+ case excel::XlDirection::xlToRight:
+ nMoveX = 1;
+ break;
+ default:
+ throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid Direction" ) ), uno::Reference< uno::XInterface >() );
+ }
- SfxViewFrame* pViewFrame = excel::getViewFrame( xModel );
- if ( pViewFrame )
+ if ( pDoc )
{
- SfxAllItemSet aArgs( SFX_APP()->GetPool() );
- // Hoping this will make sure this slot is called
- // synchronously
- SfxBoolItem sfxAsync( SID_ASYNCHRON, sal_False );
- aArgs.Put( sfxAsync, sfxAsync.Which() );
- SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
-
- USHORT nSID = 0;
-
- switch( Direction )
- {
- case excel::XlDirection::xlDown:
- nSID = SID_CURSORBLKDOWN;
- break;
- case excel::XlDirection::xlUp:
- nSID = SID_CURSORBLKUP;
- break;
- case excel::XlDirection::xlToLeft:
- nSID = SID_CURSORBLKLEFT;
- break;
- case excel::XlDirection::xlToRight:
- nSID = SID_CURSORBLKRIGHT;
- break;
- default:
- throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ": Invalid ColumnIndex" ) ), uno::Reference< uno::XInterface >() );
- }
- if ( pDispatcher )
- {
- pDispatcher->Execute( nSID, (SfxCallMode)SFX_CALLMODE_SYNCHRON, aArgs );
- }
+ pDoc->FindAreaPos( nNewX, nNewY, nTab, nMoveX, nMoveY );
}
- // result is the ActiveCell
- rtl::OUString sMoved = xApplication->getActiveCell()->Address(aDft, aDft, aDft, aDft, aDft );
-
- // restore old ActiveCell
- uno::Any aVoid;
-
- uno::Reference< excel::XRange > xOldActiveCell( xApplication->getActiveSheet()->Range( uno::makeAny( sActiveCell ), aVoid ), uno::UNO_QUERY_THROW );
- xOldActiveCell->Select();
-
- uno::Reference< excel::XRange > resultCell;
-
- resultCell.set( xApplication->getActiveSheet()->Range( uno::makeAny( sMoved ), aVoid ), uno::UNO_QUERY_THROW );
-
- // return result
-
- return resultCell;
+ ScRange aNewRange( (SCCOL)nNewX, (SCROW)nNewY, nTab, (SCCOL)nNewX, (SCROW)nNewY, nTab );
+ uno::Reference< table::XCellRange > xCellRange( new ScCellRangeObj( getScDocShell(), aNewRange ) );
+ uno::Reference< excel::XRange > xResultRange = new ScVbaRange( mxParent, mxContext, xCellRange );
+ return xResultRange;
}
bool
@@ -3509,13 +3644,13 @@ ScVbaRange::isSingleCellRange()
return false;
}
-uno::Reference< excel::XCharacters > SAL_CALL
+uno::Reference< excel::XCharacters > SAL_CALL
ScVbaRange::characters( const uno::Any& Start, const uno::Any& Length ) throw (uno::RuntimeException)
{
if ( !isSingleCellRange() )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can't create Characters property for multicell range ") ), uno::Reference< uno::XInterface >() );
uno::Reference< text::XSimpleText > xSimple(mxRange->getCellByPosition(0,0) , uno::UNO_QUERY_THROW );
- ScDocument* pDoc = getDocumentFromRange(mxRange);
+ ScDocument* pDoc = excel::GetDocumentFromRange(mxRange);
if ( !pDoc )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access document from shell" ) ), uno::Reference< uno::XInterface >() );
@@ -3523,7 +3658,7 @@ ScVbaRange::characters( const uno::Any& Start, const uno::Any& Length ) throw (u
return new ScVbaCharacters( this, mxContext, aPalette, xSimple, Start, Length );
}
- void SAL_CALL
+ void SAL_CALL
ScVbaRange::Delete( const uno::Any& Shift ) throw (uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
@@ -3532,14 +3667,14 @@ ScVbaRange::Delete( const uno::Any& Shift ) throw (uno::RuntimeException)
for ( sal_Int32 index=1; index <= nItems; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
- xRange->Delete( Shift );
+ xRange->Delete( Shift );
}
return;
}
- sheet::CellDeleteMode mode = sheet::CellDeleteMode_NONE ;
+ sheet::CellDeleteMode mode = sheet::CellDeleteMode_NONE ;
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
- if ( Shift.hasValue() )
+ if ( Shift.hasValue() )
{
sal_Int32 nShift = 0;
Shift >>= nShift;
@@ -3566,12 +3701,12 @@ ScVbaRange::Delete( const uno::Any& Shift ) throw (uno::RuntimeException)
mode = sheet::CellDeleteMode_LEFT;
}
uno::Reference< sheet::XCellRangeMovement > xCellRangeMove( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
- xCellRangeMove->removeRange( thisAddress, mode );
-
+ xCellRangeMove->removeRange( thisAddress, mode );
+
}
//XElementAccess
-sal_Bool SAL_CALL
+sal_Bool SAL_CALL
ScVbaRange::hasElements() throw (uno::RuntimeException)
{
uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY );
@@ -3583,7 +3718,7 @@ ScVbaRange::hasElements() throw (uno::RuntimeException)
}
// XEnumerationAccess
-uno::Reference< container::XEnumeration > SAL_CALL
+uno::Reference< container::XEnumeration > SAL_CALL
ScVbaRange::createEnumeration() throw (uno::RuntimeException)
{
if ( mbIsColumns || mbIsRows )
@@ -3591,17 +3726,17 @@ ScVbaRange::createEnumeration() throw (uno::RuntimeException)
uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY );
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW );
sal_Int32 nElems = 0;
- if ( mbIsColumns )
+ if ( mbIsColumns )
nElems = xColumnRowRange->getColumns()->getCount();
else
nElems = xColumnRowRange->getRows()->getCount();
return new ColumnsRowEnumeration( mxContext, xRange, nElems );
-
+
}
return new CellsEnumeration( mxParent, mxContext, m_Areas );
}
-::rtl::OUString SAL_CALL
+::rtl::OUString SAL_CALL
ScVbaRange::getDefaultMethodName( ) throw (uno::RuntimeException)
{
const static rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM("Item") );
@@ -3609,7 +3744,7 @@ ScVbaRange::getDefaultMethodName( ) throw (uno::RuntimeException)
}
-uno::Reference< awt::XDevice >
+uno::Reference< awt::XDevice >
getDeviceFromDoc( const uno::Reference< frame::XModel >& xModel ) throw( uno::RuntimeException )
{
uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
@@ -3619,7 +3754,7 @@ getDeviceFromDoc( const uno::Reference< frame::XModel >& xModel ) throw( uno::Ru
}
// returns calc internal col. width ( in points )
-double
+double
ScVbaRange::getCalcColWidth( const table::CellRangeAddress& rAddress) throw (uno::RuntimeException)
{
ScDocument* pDoc = getScDocument();
@@ -3632,19 +3767,19 @@ ScVbaRange::getCalcColWidth( const table::CellRangeAddress& rAddress) throw (uno
double
ScVbaRange::getCalcRowHeight( const table::CellRangeAddress& rAddress ) throw (uno::RuntimeException)
{
- ScDocument* pDoc = getDocumentFromRange( mxRange );
+ ScDocument* pDoc = excel::GetDocumentFromRange( mxRange );
USHORT nWidth = pDoc->GetOriginalHeight( rAddress.StartRow, rAddress.Sheet );
double nPoints = lcl_TwipsToPoints( nWidth );
nPoints = lcl_Round2DecPlaces( nPoints );
- return nPoints;
+ return nPoints;
}
// return Char Width in points
double getDefaultCharWidth( const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException )
{
- const static rtl::OUString sDflt( RTL_CONSTASCII_USTRINGPARAM("Default"));
- const static rtl::OUString sCharFontName( RTL_CONSTASCII_USTRINGPARAM("CharFontName"));
- const static rtl::OUString sPageStyles( RTL_CONSTASCII_USTRINGPARAM("PageStyles"));
+ const static rtl::OUString sDflt( RTL_CONSTASCII_USTRINGPARAM("Default"));
+ const static rtl::OUString sCharFontName( RTL_CONSTASCII_USTRINGPARAM("CharFontName"));
+ const static rtl::OUString sPageStyles( RTL_CONSTASCII_USTRINGPARAM("PageStyles"));
// get the font from the default style
uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( xModel, uno::UNO_QUERY_THROW );
uno::Reference< container::XNameAccess > xNameAccess( xStyleSupplier->getStyleFamilies(), uno::UNO_QUERY_THROW );
@@ -3657,32 +3792,32 @@ double getDefaultCharWidth( const uno::Reference< frame::XModel >& xModel ) thro
awt::FontDescriptor aDesc;
aDesc.Name = sFontName;
uno::Reference< awt::XFont > xFont( xDevice->getFont( aDesc ), uno::UNO_QUERY_THROW );
- double nCharPixelWidth = xFont->getCharWidth( (sal_Int8)'0' );
+ double nCharPixelWidth = xFont->getCharWidth( (sal_Int8)'0' );
double nPixelsPerMeter = xDevice->getInfo().PixelPerMeterX;
double nCharWidth = nCharPixelWidth / nPixelsPerMeter;
nCharWidth = nCharWidth * (double)56700;// in twips
- return lcl_TwipsToPoints( (USHORT)nCharWidth );
+ return lcl_TwipsToPoints( (USHORT)nCharWidth );
}
-uno::Any SAL_CALL
+uno::Any SAL_CALL
ScVbaRange::getColumnWidth() throw (uno::RuntimeException)
{
sal_Int32 nLen = m_Areas->getCount();
- if ( nLen > 1 )
+ if ( nLen > 1 )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW );
return xRange->getColumnWidth();
}
- double nColWidth = 0;
+ double nColWidth = 0;
ScDocShell* pShell = getScDocShell();
if ( pShell )
{
uno::Reference< frame::XModel > xModel = pShell->GetModel();
double defaultCharWidth = getDefaultCharWidth( xModel );
RangeHelper thisRange( mxRange );
- table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
+ table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
sal_Int32 nStartCol = thisAddress.StartColumn;
sal_Int32 nEndCol = thisAddress.EndColumn;
USHORT nColTwips = 0;
@@ -3690,7 +3825,7 @@ ScVbaRange::getColumnWidth() throw (uno::RuntimeException)
{
thisAddress.StartColumn = nCol;
USHORT nCurTwips = pShell->GetDocument()->GetOriginalWidth( static_cast< SCCOL >( thisAddress.StartColumn ), static_cast< SCTAB >( thisAddress.Sheet ) );
- if ( nCol == nStartCol )
+ if ( nCol == nStartCol )
nColTwips = nCurTwips;
if ( nColTwips != nCurTwips )
return aNULL();
@@ -3703,11 +3838,11 @@ ScVbaRange::getColumnWidth() throw (uno::RuntimeException)
return uno::makeAny( nColWidth );
}
-void SAL_CALL
+void SAL_CALL
ScVbaRange::setColumnWidth( const uno::Any& _columnwidth ) throw (uno::RuntimeException)
{
sal_Int32 nLen = m_Areas->getCount();
- if ( nLen > 1 )
+ if ( nLen > 1 )
{
for ( sal_Int32 index = 1; index != nLen; ++index )
{
@@ -3727,48 +3862,48 @@ ScVbaRange::setColumnWidth( const uno::Any& _columnwidth ) throw (uno::RuntimeEx
{
nColWidth = ( nColWidth * getDefaultCharWidth( xModel ) );
- RangeHelper thisRange( mxRange );
+ RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
USHORT nTwips = lcl_pointsToTwips( nColWidth );
-
+
ScDocFunc aFunc(*pDocShell);
SCCOLROW nColArr[2];
nColArr[0] = thisAddress.StartColumn;
nColArr[1] = thisAddress.EndColumn;
aFunc.SetWidthOrHeight( TRUE, 1, nColArr, thisAddress.Sheet, SC_SIZE_ORIGINAL,
- nTwips, TRUE, TRUE );
-
+ nTwips, TRUE, TRUE );
+
}
}
}
-uno::Any SAL_CALL
+uno::Any SAL_CALL
ScVbaRange::getWidth() throw (uno::RuntimeException)
{
- if ( m_Areas->getCount() > 1 )
+ if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW );
return xRange->getWidth();
}
- uno::Reference< table::XColumnRowRange > xColRowRange( mxRange, uno::UNO_QUERY_THROW );
- uno::Reference< container::XIndexAccess > xIndexAccess( xColRowRange->getColumns(), uno::UNO_QUERY_THROW );
- sal_Int32 nElems = xIndexAccess->getCount();
+ uno::Reference< table::XColumnRowRange > xColRowRange( mxRange, uno::UNO_QUERY_THROW );
+ uno::Reference< container::XIndexAccess > xIndexAccess( xColRowRange->getColumns(), uno::UNO_QUERY_THROW );
+ sal_Int32 nElems = xIndexAccess->getCount();
double nWidth = 0;
for ( sal_Int32 index=0; index<nElems; ++index )
{
- uno::Reference< sheet::XCellRangeAddressable > xAddressable( xIndexAccess->getByIndex( index ), uno::UNO_QUERY_THROW );
+ uno::Reference< sheet::XCellRangeAddressable > xAddressable( xIndexAccess->getByIndex( index ), uno::UNO_QUERY_THROW );
double nTmpWidth = getCalcColWidth( xAddressable->getRangeAddress() );
nWidth += nTmpWidth;
}
return uno::makeAny( nWidth );
}
-uno::Any SAL_CALL
+uno::Any SAL_CALL
ScVbaRange::Areas( const uno::Any& item) throw (uno::RuntimeException)
{
if ( !item.hasValue() )
return uno::makeAny( m_Areas );
- return m_Areas->Item( item, uno::Any() );
+ return m_Areas->Item( item, uno::Any() );
}
uno::Reference< excel::XRange >
@@ -3835,28 +3970,28 @@ ScVbaRange::BorderAround( const css::uno::Any& LineStyle, const css::uno::Any& W
return uno::makeAny( sal_True );
}
-uno::Any SAL_CALL
+uno::Any SAL_CALL
ScVbaRange::getRowHeight() throw (uno::RuntimeException)
{
sal_Int32 nLen = m_Areas->getCount();
- if ( nLen > 1 )
+ if ( nLen > 1 )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW );
return xRange->getRowHeight();
- }
+ }
- // if any row's RowHeight in the
+ // if any row's RowHeight in the
// range is different from any other then return NULL
- RangeHelper thisRange( mxRange );
+ RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
-
+
sal_Int32 nStartRow = thisAddress.StartRow;
sal_Int32 nEndRow = thisAddress.EndRow;
USHORT nRowTwips = 0;
// #TODO probably possible to use the SfxItemSet ( and see if
// SFX_ITEM_DONTCARE is set ) to improve performance
// #CHECKME looks like this is general behaviour not just row Range specific
-// if ( mbIsRows )
+// if ( mbIsRows )
ScDocShell* pShell = getScDocShell();
if ( pShell )
{
@@ -3874,11 +4009,11 @@ ScVbaRange::getRowHeight() throw (uno::RuntimeException)
return uno::makeAny( nHeight );
}
-void SAL_CALL
+void SAL_CALL
ScVbaRange::setRowHeight( const uno::Any& _rowheight) throw (uno::RuntimeException)
{
sal_Int32 nLen = m_Areas->getCount();
- if ( nLen > 1 )
+ if ( nLen > 1 )
{
for ( sal_Int32 index = 1; index != nLen; ++index )
{
@@ -3890,62 +4025,62 @@ ScVbaRange::setRowHeight( const uno::Any& _rowheight) throw (uno::RuntimeExcepti
double nHeight = 0; // Incomming height is in points
_rowheight >>= nHeight;
nHeight = lcl_Round2DecPlaces( nHeight );
- RangeHelper thisRange( mxRange );
+ RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
USHORT nTwips = lcl_pointsToTwips( nHeight );
-
- ScDocShell* pDocShell = getDocShellFromRange( mxRange );
+
+ ScDocShell* pDocShell = excel::GetDocShellFromRange( mxRange );
ScDocFunc aFunc(*pDocShell);
SCCOLROW nRowArr[2];
nRowArr[0] = thisAddress.StartRow;
nRowArr[1] = thisAddress.EndRow;
aFunc.SetWidthOrHeight( FALSE, 1, nRowArr, thisAddress.Sheet, SC_SIZE_ORIGINAL,
- nTwips, TRUE, TRUE );
+ nTwips, TRUE, TRUE );
}
-uno::Any SAL_CALL
+uno::Any SAL_CALL
ScVbaRange::getPageBreak() throw (uno::RuntimeException)
{
sal_Int32 nPageBreak = excel::XlPageBreak::xlPageBreakNone;
- ScDocShell* pShell = getDocShellFromRange( mxRange );
+ ScDocShell* pShell = excel::GetDocShellFromRange( mxRange );
if ( pShell )
{
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
BOOL bColumn = FALSE;
-
+
if (thisAddress.StartRow==0)
bColumn = TRUE;
-
+
uno::Reference< frame::XModel > xModel = pShell->GetModel();
if ( xModel.is() )
{
- ScDocument* pDoc = getDocumentFromRange( mxRange );
-
+ ScDocument* pDoc = excel::GetDocumentFromRange( mxRange );
+
ScBreakType nBreak = BREAK_NONE;
if ( !bColumn )
nBreak = pDoc->HasRowBreak(thisAddress.StartRow, thisAddress.Sheet);
else
nBreak = pDoc->HasColBreak(thisAddress.StartColumn, thisAddress.Sheet);
-
+
if (nBreak & BREAK_PAGE)
nPageBreak = excel::XlPageBreak::xlPageBreakAutomatic;
-
+
if (nBreak & BREAK_MANUAL)
nPageBreak = excel::XlPageBreak::xlPageBreakManual;
- }
+ }
}
return uno::makeAny( nPageBreak );
}
-void SAL_CALL
+void SAL_CALL
ScVbaRange::setPageBreak( const uno::Any& _pagebreak) throw (uno::RuntimeException)
{
- sal_Int32 nPageBreak = 0;
+ sal_Int32 nPageBreak = 0;
_pagebreak >>= nPageBreak;
-
- ScDocShell* pShell = getDocShellFromRange( mxRange );
+
+ ScDocShell* pShell = excel::GetDocShellFromRange( mxRange );
if ( pShell )
{
RangeHelper thisRange( mxRange );
@@ -3953,11 +4088,11 @@ ScVbaRange::setPageBreak( const uno::Any& _pagebreak) throw (uno::RuntimeExcepti
if ((thisAddress.StartColumn==0) && (thisAddress.StartRow==0))
return;
BOOL bColumn = FALSE;
-
+
if (thisAddress.StartRow==0)
bColumn = TRUE;
-
- ScAddress aAddr( static_cast<SCCOL>(thisAddress.StartColumn), thisAddress.StartRow, thisAddress.Sheet );
+
+ ScAddress aAddr( static_cast<SCCOL>(thisAddress.StartColumn), thisAddress.StartRow, thisAddress.Sheet );
uno::Reference< frame::XModel > xModel = pShell->GetModel();
if ( xModel.is() )
{
@@ -3970,28 +4105,28 @@ ScVbaRange::setPageBreak( const uno::Any& _pagebreak) throw (uno::RuntimeExcepti
}
}
-uno::Any SAL_CALL
+uno::Any SAL_CALL
ScVbaRange::getHeight() throw (uno::RuntimeException)
{
- if ( m_Areas->getCount() > 1 )
+ if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW );
return xRange->getHeight();
}
-
- uno::Reference< table::XColumnRowRange > xColRowRange( mxRange, uno::UNO_QUERY_THROW );
- uno::Reference< container::XIndexAccess > xIndexAccess( xColRowRange->getRows(), uno::UNO_QUERY_THROW );
+
+ uno::Reference< table::XColumnRowRange > xColRowRange( mxRange, uno::UNO_QUERY_THROW );
+ uno::Reference< container::XIndexAccess > xIndexAccess( xColRowRange->getRows(), uno::UNO_QUERY_THROW );
sal_Int32 nElems = xIndexAccess->getCount();
double nHeight = 0;
for ( sal_Int32 index=0; index<nElems; ++index )
{
- uno::Reference< sheet::XCellRangeAddressable > xAddressable( xIndexAccess->getByIndex( index ), uno::UNO_QUERY_THROW );
+ uno::Reference< sheet::XCellRangeAddressable > xAddressable( xIndexAccess->getByIndex( index ), uno::UNO_QUERY_THROW );
nHeight += getCalcRowHeight(xAddressable->getRangeAddress() );
}
return uno::makeAny( nHeight );
}
-awt::Point
+awt::Point
ScVbaRange::getPosition() throw ( uno::RuntimeException )
{
awt::Point aPoint;
@@ -4003,7 +4138,7 @@ ScVbaRange::getPosition() throw ( uno::RuntimeException )
xProps->getPropertyValue(POSITION) >>= aPoint;
return aPoint;
}
-uno::Any SAL_CALL
+uno::Any SAL_CALL
ScVbaRange::getLeft() throw (uno::RuntimeException)
{
// helperapi returns the first ranges left ( and top below )
@@ -4014,9 +4149,9 @@ ScVbaRange::getLeft() throw (uno::RuntimeException)
}
-uno::Any SAL_CALL
+uno::Any SAL_CALL
ScVbaRange::getTop() throw (uno::RuntimeException)
-{
+{
// helperapi returns the first ranges top
if ( m_Areas->getCount() > 1 )
return getArea( 0 )->getTop();
@@ -4039,11 +4174,11 @@ ScVbaRange::getWorksheet() throw (uno::RuntimeException)
uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW );
xRange.set( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
}
- ScDocShell* pDocShell = getDocShellFromRange(xRange);
+ ScDocShell* pDocShell = excel::GetDocShellFromRange(xRange);
RangeHelper rHelper(xRange);
// parent should be Thisworkbook
xSheet.set( new ScVbaWorksheet( uno::Reference< XHelperInterface >(), mxContext,rHelper.getSpreadSheet(),pDocShell->GetModel()) );
- }
+ }
return xSheet;
}
@@ -4052,11 +4187,11 @@ ScVbaRange::getWorksheet() throw (uno::RuntimeException)
uno::Reference< excel::XRange >
ScVbaRange::ApplicationRange( const uno::Reference< uno::XComponentContext >& xContext, const css::uno::Any &Cell1, const css::uno::Any &Cell2 ) throw (css::uno::RuntimeException)
{
- // Althought the documentation seems clear that Range without a
+ // Althought the documentation seems clear that Range without a
// qualifier then its a shortcut for ActiveSheet.Range
- // however, similarly Application.Range is apparently also a
+ // however, similarly Application.Range is apparently also a
// shortcut for ActiveSheet.Range
- // The is however a subtle behavioural difference I've come across
+ // The is however a subtle behavioural difference I've come across
// wrt to named ranges.
// If a named range "test" exists { Sheet1!$A1 } and the active sheet
// is Sheet2 then the following will fail
@@ -4066,14 +4201,14 @@ ScVbaRange::ApplicationRange( const uno::Reference< uno::XComponentContext >& xC
// msgbox Range("test").Address ' works
// msgbox Application.Range("test").Address ' works
- // Single param Range
+ // Single param Range
rtl::OUString sRangeName;
Cell1 >>= sRangeName;
if ( Cell1.hasValue() && !Cell2.hasValue() && sRangeName.getLength() )
{
const static rtl::OUString sNamedRanges( RTL_CONSTASCII_USTRINGPARAM("NamedRanges"));
uno::Reference< beans::XPropertySet > xPropSet( getCurrentExcelDoc(xContext), uno::UNO_QUERY_THROW );
-
+
uno::Reference< container::XNameAccess > xNamed( xPropSet->getPropertyValue( sNamedRanges ), uno::UNO_QUERY_THROW );
uno::Reference< sheet::XCellRangeReferrer > xReferrer;
try
@@ -4094,63 +4229,44 @@ ScVbaRange::ApplicationRange( const uno::Reference< uno::XComponentContext >& xC
}
}
}
- uno::Reference< sheet::XSpreadsheetView > xView( getCurrentExcelDoc(xContext)->getCurrentController(), uno::UNO_QUERY );
- uno::Reference< table::XCellRange > xSheetRange( xView->getActiveSheet(), uno::UNO_QUERY_THROW );
- ScVbaRange* pRange = new ScVbaRange( excel::getUnoSheetModuleObj( xSheetRange ), xContext, xSheetRange );
- uno::Reference< excel::XRange > xVbSheetRange( pRange );
- return pRange->Range( Cell1, Cell2, true );
-}
-uno::Reference< sheet::XDatabaseRanges >
-lcl_GetDataBaseRanges( ScDocShell* pShell ) throw ( uno::RuntimeException )
-{
- uno::Reference< frame::XModel > xModel;
- if ( pShell )
- xModel.set( pShell->GetModel(), uno::UNO_QUERY_THROW );
- uno::Reference< beans::XPropertySet > xModelProps( xModel, uno::UNO_QUERY_THROW );
- uno::Reference< sheet::XDatabaseRanges > xDBRanges( xModelProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DatabaseRanges") ) ), uno::UNO_QUERY_THROW );
- return xDBRanges;
-}
-// returns the XDatabaseRange for the autofilter on sheet (nSheet)
-// also populates sName with the name of range
-uno::Reference< sheet::XDatabaseRange >
-lcl_GetAutoFiltRange( ScDocShell* pShell, sal_Int16 nSheet, rtl::OUString& sName )
-{
- uno::Reference< container::XIndexAccess > xIndexAccess( lcl_GetDataBaseRanges( pShell ), uno::UNO_QUERY_THROW );
- uno::Reference< sheet::XDatabaseRange > xDataBaseRange;
- table::CellRangeAddress dbAddress;
- for ( sal_Int32 index=0; index < xIndexAccess->getCount(); ++index )
- {
- uno::Reference< sheet::XDatabaseRange > xDBRange( xIndexAccess->getByIndex( index ), uno::UNO_QUERY_THROW );
- uno::Reference< container::XNamed > xNamed( xDBRange, uno::UNO_QUERY_THROW );
- // autofilters work weirdly with openoffice, unnamed is the default
- // named range which is used to create an autofilter, but
- // its also possible that another name could be used
- // this also causes problems when an autofilter is created on
- // another sheet
- // ( but.. you can use any named range )
- dbAddress = xDBRange->getDataArea();
- if ( dbAddress.Sheet == nSheet )
- {
- sal_Bool bHasAuto = sal_False;
- uno::Reference< beans::XPropertySet > xProps( xDBRange, uno::UNO_QUERY_THROW );
- xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AutoFilter") ) ) >>= bHasAuto;
- if ( bHasAuto )
- {
- sName = xNamed->getName();
- xDataBaseRange=xDBRange;
- break;
- }
+ // Add these codes for supporting shortcut: Application.Range(Range1, Range2), Range1 or Range2 is not the range of current active sheet.
+ // If Range1 and Range2 are not in current active sheet, we should not use the active sheet, but use the sheet of Range1 and Range2.
+ // If Range1 and Range2 are not in the same sheet, we throw an exception.
+ uno::Reference< sheet::XSpreadsheet > xSpreadsheet;
+ uno::Reference< excel::XRange > xRange1( Cell1, uno::UNO_QUERY ), xRange2( Cell2, uno::UNO_QUERY );
+ if ( xRange1.is() )
+ {
+ RangeHelper thisRange( xRange1->getCellRange() );
+ xSpreadsheet = thisRange.getSpreadSheet();
+ }
+ else if ( xRange2.is() )
+ {
+ RangeHelper thisRange( xRange2->getCellRange() );
+ xSpreadsheet = thisRange.getSpreadSheet();
+ }
+ if ( !xSpreadsheet.is() )
+ {
+ uno::Reference< frame::XModel > xModel = getCurrentExcelDoc( xContext );
+ if ( xModel.is() )
+ {
+ uno::Reference< sheet::XSpreadsheetView > xView( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
+ xSpreadsheet = xView->getActiveSheet();
}
}
- return xDataBaseRange;
-}
+
+ uno::Reference< table::XCellRange > xSheetRange( xSpreadsheet, uno::UNO_QUERY_THROW );
+ ScVbaRange* pRange = new ScVbaRange( excel::getUnoSheetModuleObj( xSheetRange ), xContext, xSheetRange );
+
+ uno::Reference< excel::XRange > xVbSheetRange( pRange );
+ return pRange->Range( Cell1, Cell2, true );
+}
// Helper functions for AutoFilter
ScDBData* lcl_GetDBData_Impl( ScDocShell* pDocShell, sal_Int16 nSheet )
{
rtl::OUString sName;
- lcl_GetAutoFiltRange( pDocShell, nSheet, sName );
+ excel::GetAutoFiltRange( pDocShell, nSheet, sName );
OSL_TRACE("lcl_GetDBData_Impl got autofilter range %s for sheet %d",
rtl::OUStringToOString( sName, RTL_TEXTENCODING_UTF8 ).getStr() , nSheet );
ScDBData* pRet = NULL;
@@ -4170,7 +4286,7 @@ ScDBData* lcl_GetDBData_Impl( ScDocShell* pDocShell, sal_Int16 nSheet )
void lcl_SelectAll( ScDocShell* pDocShell, ScQueryParam& aParam )
{
if ( pDocShell )
- {
+ {
ScViewData* pViewData = pDocShell->GetViewData();
if ( pViewData )
{
@@ -4182,8 +4298,8 @@ void lcl_SelectAll( ScDocShell* pDocShell, ScQueryParam& aParam )
ScQueryParam lcl_GetQueryParam( ScDocShell* pDocShell, sal_Int16 nSheet )
{
- ScDBData* pDBData = lcl_GetDBData_Impl( pDocShell, nSheet );
- ScQueryParam aParam;
+ ScDBData* pDBData = lcl_GetDBData_Impl( pDocShell, nSheet );
+ ScQueryParam aParam;
if (pDBData)
{
pDBData->GetQueryParam( aParam );
@@ -4222,7 +4338,7 @@ void lcl_SetAllQueryForField( ScDocShell* pDocShell, SCCOLROW nField, sal_Int16
// Modifies sCriteria, and nOp depending on the value of sCriteria
void lcl_setTableFieldsFromCriteria( rtl::OUString& sCriteria1, uno::Reference< beans::XPropertySet >& xDescProps, sheet::TableFilterField2& rFilterField )
{
- // #TODO make this more efficient and cycle through
+ // #TODO make this more efficient and cycle through
// sCriteria1 character by character to pick up <,<>,=, * etc.
// right now I am more concerned with just getting it to work right
@@ -4245,28 +4361,28 @@ void lcl_setTableFieldsFromCriteria( rtl::OUString& sCriteria1, uno::Reference<
{
rFilterField.Operator = sheet::FilterOperator2::EQUAL;
sCriteria1 = sCriteria1.copy( EQUALS.getLength() );
- sCriteria1 = VBAToRegexp( sCriteria1 );
- // UseRegularExpressions
+ sCriteria1 = VBAToRegexp( sCriteria1 );
+ // UseRegularExpressions
if ( xDescProps.is() )
xDescProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseRegularExpressions" ) ), uno::Any( sal_True ) );
}
}
- else if ( ( nPos = sCriteria1.indexOf( NOTEQUALS ) ) == 0 )
+ else if ( ( nPos = sCriteria1.indexOf( NOTEQUALS ) ) == 0 )
{
if ( sCriteria1.getLength() == NOTEQUALS.getLength() )
- rFilterField.Operator = sheet::FilterOperator2::NOT_EMPTY;
+ rFilterField.Operator = sheet::FilterOperator2::NOT_EMPTY;
else
{
rFilterField.Operator = sheet::FilterOperator2::NOT_EQUAL;
sCriteria1 = sCriteria1.copy( NOTEQUALS.getLength() );
- sCriteria1 = VBAToRegexp( sCriteria1 );
- // UseRegularExpressions
+ sCriteria1 = VBAToRegexp( sCriteria1 );
+ // UseRegularExpressions
if ( xDescProps.is() )
xDescProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseRegularExpressions" ) ), uno::Any( sal_True ) );
}
- }
- else if ( ( nPos = sCriteria1.indexOf( GREATERTHAN ) ) == 0 )
+ }
+ else if ( ( nPos = sCriteria1.indexOf( GREATERTHAN ) ) == 0 )
{
bIsNumeric = true;
if ( ( nPos = sCriteria1.indexOf( GREATERTHANEQUALS ) ) == 0 )
@@ -4281,7 +4397,7 @@ void lcl_setTableFieldsFromCriteria( rtl::OUString& sCriteria1, uno::Reference<
}
}
- else if ( ( nPos = sCriteria1.indexOf( LESSTHAN ) ) == 0 )
+ else if ( ( nPos = sCriteria1.indexOf( LESSTHAN ) ) == 0 )
{
bIsNumeric = true;
if ( ( nPos = sCriteria1.indexOf( LESSTHANEQUALS ) ) == 0 )
@@ -4304,22 +4420,22 @@ void lcl_setTableFieldsFromCriteria( rtl::OUString& sCriteria1, uno::Reference<
rFilterField.IsNumeric= sal_True;
rFilterField.NumericValue = sCriteria1.toDouble();
}
- rFilterField.StringValue = sCriteria1;
+ rFilterField.StringValue = sCriteria1;
}
-void SAL_CALL
+void SAL_CALL
ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const uno::Any& Operator, const uno::Any& Criteria2, const uno::Any& VisibleDropDown ) throw (uno::RuntimeException)
{
- // Is there an existing autofilter
- RangeHelper thisRange( mxRange );
+ // Is there an existing autofilter
+ RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
sal_Int16 nSheet = thisAddress.Sheet;
ScDocShell* pShell = getScDocShell();
- sal_Bool bHasAuto = sal_False;
+ sal_Bool bHasAuto = sal_False;
rtl::OUString sAutofiltRangeName;
- uno::Reference< sheet::XDatabaseRange > xDataBaseRange = lcl_GetAutoFiltRange( pShell, nSheet, sAutofiltRangeName );
+ uno::Reference< sheet::XDatabaseRange > xDataBaseRange = excel::GetAutoFiltRange( pShell, nSheet, sAutofiltRangeName );
if ( xDataBaseRange.is() )
- bHasAuto = true;
+ bHasAuto = true;
uno::Reference< table::XCellRange > xFilterRange;
if ( !bHasAuto )
@@ -4327,7 +4443,7 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const
if ( m_Areas->getCount() > 1 )
throw uno::RuntimeException( STR_ERRORMESSAGE_APPLIESTOSINGLERANGEONLY, uno::Reference< uno::XInterface >() );
- table::CellRangeAddress autoFiltAddress;
+ table::CellRangeAddress autoFiltAddress;
//CurrentRegion()
if ( isSingleCellRange() )
{
@@ -4343,14 +4459,14 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const
autoFiltAddress = currentRegion.getCellRangeAddressable()->getRangeAddress();
}
}
- }
+ }
else // multi-cell range
{
RangeHelper multiCellRange( mxRange );
autoFiltAddress = multiCellRange.getCellRangeAddressable()->getRangeAddress();
}
- uno::Reference< sheet::XDatabaseRanges > xDBRanges = lcl_GetDataBaseRanges( pShell );
+ uno::Reference< sheet::XDatabaseRanges > xDBRanges = excel::GetDataBaseRanges( pShell );
if ( xDBRanges.is() )
{
rtl::OUString sGenName( RTL_CONSTASCII_USTRINGPARAM("VBA_Autofilter_") );
@@ -4362,25 +4478,25 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const
xDataBaseRange.set( xDBRanges->getByName( sGenName ), uno::UNO_QUERY_THROW );
}
if ( !xDataBaseRange.is() )
- throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Failed to find the autofilter placeholder range" ) ), uno::Reference< uno::XInterface >() );
+ throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Failed to find the autofilter placeholder range" ) ), uno::Reference< uno::XInterface >() );
uno::Reference< beans::XPropertySet > xDBRangeProps( xDataBaseRange, uno::UNO_QUERY_THROW );
// set autofilt
- xDBRangeProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AutoFilter") ), uno::Any(sal_True) );
+ xDBRangeProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AutoFilter") ), uno::Any(sal_True) );
// set header
uno::Reference< beans::XPropertySet > xFiltProps( xDataBaseRange->getFilterDescriptor(), uno::UNO_QUERY_THROW );
sal_Bool bHasColHeader = sal_False;
ScDocument* pDoc = pShell ? pShell->GetDocument() : NULL;
-
+
bHasColHeader = pDoc->HasColHeader( static_cast< SCCOL >( autoFiltAddress.StartColumn ), static_cast< SCROW >( autoFiltAddress.StartRow ), static_cast< SCCOL >( autoFiltAddress.EndColumn ), static_cast< SCROW >( autoFiltAddress.EndRow ), static_cast< SCTAB >( autoFiltAddress.Sheet ) ) ? sal_True : sal_False;
- xFiltProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ContainsHeader") ), uno::Any( bHasColHeader ) );
+ xFiltProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ContainsHeader") ), uno::Any( bHasColHeader ) );
}
sal_Int32 nField = 0; // *IS* 1 based
rtl::OUString sCriteria1;
sal_Int32 nOperator = excel::XlAutoFilterOperator::xlAnd;
-
+
sal_Bool bVisible = sal_True;
bool bChangeDropDown = false;
VisibleDropDown >>= bVisible;
@@ -4389,8 +4505,8 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const
// required
bVisible = sal_False;
else
- bChangeDropDown = true;
- sheet::FilterConnection nConn = sheet::FilterConnection_AND;
+ bChangeDropDown = true;
+ sheet::FilterConnection nConn = sheet::FilterConnection_AND;
double nCriteria1 = 0;
bool bHasCritValue = Criteria1.hasValue();
@@ -4398,13 +4514,26 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const
if ( bHasCritValue )
bCritHasNumericValue = ( Criteria1 >>= nCriteria1 );
- if ( !Field.hasValue() && ( Criteria1.hasValue() || Operator.hasValue() || Criteria2.hasValue() ) )
+ if ( !Field.hasValue() && ( Criteria1.hasValue() || Operator.hasValue() || Criteria2.hasValue() ) )
throw uno::RuntimeException();
// Use the normal uno api, sometimes e.g. when you want to use ALL as the filter
// we can't use refresh as the uno interface doesn't have a concept of ALL
- // in this case we just call the core calc functionality -
- bool bAll = false;;
- if ( ( Field >>= nField ) )
+ // in this case we just call the core calc functionality -
+ bool bAll = false;
+ uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext );
+ bool bIsValidFieldValue = ( Field >>= nField );
+ if ( !bIsValidFieldValue && xConverter.is() )
+ {
+ try
+ {
+ uno::Any aConverted = xConverter->convertTo( Field, getCppuType( (sal_Int32*)0 ) );
+ bIsValidFieldValue = ( aConverted >>= nField );
+ }
+ catch( const uno::Exception& ex )
+ {
+ }
+ }
+ if ( bIsValidFieldValue )
{
uno::Reference< sheet::XSheetFilterDescriptor2 > xDesc(
xDataBaseRange->getFilterDescriptor(), uno::UNO_QUERY );
@@ -4413,11 +4542,11 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const
uno::Sequence< sheet::TableFilterField2 > sTabFilts;
uno::Reference< beans::XPropertySet > xDescProps( xDesc, uno::UNO_QUERY_THROW );
if ( Criteria1.hasValue() )
- {
+ {
sTabFilts.realloc( 1 );
sTabFilts[0].Operator = sheet::FilterOperator2::EQUAL;// sensible default
if ( !bCritHasNumericValue )
- {
+ {
Criteria1 >>= sCriteria1;
sTabFilts[0].IsNumeric = bCritHasNumericValue;
if ( bHasCritValue && sCriteria1.getLength() )
@@ -4434,15 +4563,27 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const
else // no value specified
bAll = true;
// not sure what the relationship between Criteria1 and Operator is,
- // e.g. can you have a Operator without a Criteria ? in openoffice it
- if ( Operator.hasValue() && ( Operator >>= nOperator ) )
+ // e.g. can you have a Operator without a Criteria ? in openoffice it
+ bool bIsValidOpValue = ( Operator.hasValue() && ( Operator >>= nOperator ) );
+ if ( Operator.hasValue() && !bIsValidOpValue && xConverter.is() )
+ {
+ try
+ {
+ uno::Any aConverted = xConverter->convertTo( Operator, getCppuType( (sal_Int32*)0 ) );
+ bIsValidOpValue = ( aConverted >>= nOperator );
+ }
+ catch( const uno::Exception& ex )
+ {
+ }
+ }
+ if ( bIsValidOpValue )
{
// if its a bottom/top Ten(Percent/Value) and there
// is no value specified for critera1 set it to 10
if ( !bCritHasNumericValue && !sCriteria1.getLength() && ( nOperator != excel::XlAutoFilterOperator::xlOr ) && ( nOperator != excel::XlAutoFilterOperator::xlAnd ) )
{
- sTabFilts[0].IsNumeric = sal_True;
- sTabFilts[0].NumericValue = 10;
+ sTabFilts[0].IsNumeric = sal_True;
+ sTabFilts[0].NumericValue = 10;
bAll = false;
}
switch ( nOperator )
@@ -4467,21 +4608,21 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const
break;
default:
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("UnknownOption") ), uno::Reference< uno::XInterface >() );
-
- }
- }
+ }
+
+ }
if ( !bAll )
{
- sTabFilts[0].Connection = sheet::FilterConnection_AND;
- sTabFilts[0].Field = (nField - 1);
+ sTabFilts[0].Connection = sheet::FilterConnection_AND;
+ sTabFilts[0].Field = (nField - 1);
rtl::OUString sCriteria2;
if ( Criteria2.hasValue() ) // there is a Criteria2
{
sTabFilts.realloc(2);
sTabFilts[1].Field = sTabFilts[0].Field;
- sTabFilts[1].Connection = nConn;
+ sTabFilts[1].Connection = nConn;
if ( Criteria2 >>= sCriteria2 )
{
@@ -4507,16 +4648,16 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const
xDataBaseRange->refresh();
}
else
- // was 0 based now seems to be 1
+ // was 0 based now seems to be 1
lcl_SetAllQueryForField( pShell, nField, nSheet );
}
}
- else
+ else
{
- // this is just to toggle autofilter on and off ( not to be confused with
- // a VisibleDropDown option combined with a field, in that case just the
+ // this is just to toggle autofilter on and off ( not to be confused with
+ // a VisibleDropDown option combined with a field, in that case just the
// button should be disabled ) - currently we don't support that
- bChangeDropDown = true;
+ bChangeDropDown = true;
uno::Reference< beans::XPropertySet > xDBRangeProps( xDataBaseRange, uno::UNO_QUERY_THROW );
if ( bHasAuto )
{
@@ -4540,7 +4681,7 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const
}
}
-void SAL_CALL
+void SAL_CALL
ScVbaRange::Insert( const uno::Any& Shift, const uno::Any& CopyOrigin ) throw (uno::RuntimeException)
{
sal_Bool bCopyOrigin = sal_True;
@@ -4551,7 +4692,7 @@ ScVbaRange::Insert( const uno::Any& Shift, const uno::Any& CopyOrigin ) throw (u
// #TODO investigate resultant behaviour using these constants
// currently just processing Shift
- sheet::CellInsertMode mode = sheet::CellInsertMode_NONE;
+ sheet::CellInsertMode mode = sheet::CellInsertMode_NONE;
if ( Shift.hasValue() )
{
sal_Int32 nShift = 0;
@@ -4568,7 +4709,7 @@ ScVbaRange::Insert( const uno::Any& Shift, const uno::Any& CopyOrigin ) throw (u
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ("Illegal paramater ") ), uno::Reference< uno::XInterface >() );
}
}
- else
+ else
{
if ( getRow() >= getColumn() )
mode = sheet::CellInsertMode_DOWN;
@@ -4576,15 +4717,15 @@ ScVbaRange::Insert( const uno::Any& Shift, const uno::Any& CopyOrigin ) throw (u
mode = sheet::CellInsertMode_RIGHT;
}
RangeHelper thisRange( mxRange );
- table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
- uno::Reference< sheet::XCellRangeMovement > xCellRangeMove( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
+ table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
+ uno::Reference< sheet::XCellRangeMovement > xCellRangeMove( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
xCellRangeMove->insertCells( thisAddress, mode );
if ( bCopyOrigin )
{
// After the insert ( this range ) actually has moved
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 ) );
- uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( getDocShellFromRange( mxRange ) , aRange ) );
- uno::Reference< excel::XRange > xVbaRange( new ScVbaRange( mxParent, mxContext, xRange, mbIsRows, mbIsColumns ) );
+ uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( excel::GetDocShellFromRange( mxRange ) , aRange ) );
+ uno::Reference< excel::XRange > xVbaRange( new ScVbaRange( mxParent, mxContext, xRange, mbIsRows, mbIsColumns ) );
xVbaRange->PasteSpecial( uno::Any(), uno::Any(), uno::Any(), uno::Any() );
}
}
@@ -4593,7 +4734,7 @@ void SAL_CALL
ScVbaRange::Autofit() throw (uno::RuntimeException)
{
sal_Int32 nLen = m_Areas->getCount();
- if ( nLen > 1 )
+ if ( nLen > 1 )
{
for ( sal_Int32 index = 1; index != nLen; ++index )
{
@@ -4606,13 +4747,13 @@ ScVbaRange::Autofit() throw (uno::RuntimeException)
// throw an error
if ( !( mbIsColumns || mbIsRows ) )
- DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
- ScDocShell* pDocShell = getDocShellFromRange( mxRange );
+ DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
+ ScDocShell* pDocShell = excel::GetDocShellFromRange( mxRange );
if ( pDocShell )
{
- RangeHelper thisRange( mxRange );
+ RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
-
+
ScDocFunc aFunc(*pDocShell);
SCCOLROW nColArr[2];
nColArr[0] = thisAddress.StartColumn;
@@ -4625,22 +4766,22 @@ ScVbaRange::Autofit() throw (uno::RuntimeException)
nColArr[1] = thisAddress.EndRow;
}
aFunc.SetWidthOrHeight( bDirection, 1, nColArr, thisAddress.Sheet, SC_SIZE_OPTIMAL,
- 0, TRUE, TRUE );
-
- }
+ 0, TRUE, TRUE );
+
+ }
}
/***************************************************************************************
- * interface for text:
+ * interface for text:
* com.sun.star.text.XText, com.sun.star.table.XCell, com.sun.star.container.XEnumerationAccess
- * com.sun.star.text.XTextRange,
- * the main problem is to recognize the numeric and date, which assosiate with DecimalSeparator, ThousandsSeparator,
+ * com.sun.star.text.XTextRange,
+ * the main problem is to recognize the numeric and date, which assosiate with DecimalSeparator, ThousandsSeparator,
* TrailingMinusNumbers and FieldInfo.
***************************************************************************************/
void SAL_CALL
ScVbaRange::TextToColumns( const css::uno::Any& Destination, const css::uno::Any& DataType, const css::uno::Any& TextQualifier,
- const css::uno::Any& ConsecutinveDelimiter, const css::uno::Any& Tab, const css::uno::Any& Semicolon, const css::uno::Any& Comma,
- const css::uno::Any& Space, const css::uno::Any& Other, const css::uno::Any& OtherChar, const css::uno::Any& /*FieldInfo*/,
+ const css::uno::Any& ConsecutiveDelimiter, const css::uno::Any& Tab, const css::uno::Any& Semicolon, const css::uno::Any& Comma,
+ const css::uno::Any& Space, const css::uno::Any& Other, const css::uno::Any& OtherChar, const css::uno::Any& FieldInfo,
const css::uno::Any& DecimalSeparator, const css::uno::Any& ThousandsSeparator, const css::uno::Any& /*TrailingMinusNumbers*/ ) throw (css::uno::RuntimeException)
{
uno::Reference< excel::XRange > xRange;
@@ -4668,7 +4809,7 @@ ScVbaRange::TextToColumns( const css::uno::Any& Destination, const css::uno::Any
}
sal_Bool bDilimited = ( xlTextParsingType == excel::XlTextParsingType::xlDelimited );
- sal_Int16 xlTextQualifier = excel::XlTextQualifier::xlTextQualifierDoubleQuote;
+ sal_Int16 xlTextQualifier = excel::XlTextQualifier::xlTextQualifierDoubleQuote;
if( TextQualifier.hasValue() )
{
if( !( TextQualifier >>= xlTextQualifier ))
@@ -4677,13 +4818,13 @@ ScVbaRange::TextToColumns( const css::uno::Any& Destination, const css::uno::Any
OSL_TRACE("set TextQualifier\n");
}
- sal_Bool bConsecutinveDelimiter = sal_False;
- if( ConsecutinveDelimiter.hasValue() )
+ sal_Bool bConsecutiveDelimiter = sal_False;
+ if( ConsecutiveDelimiter.hasValue() )
{
- if( !( ConsecutinveDelimiter >>= bConsecutinveDelimiter ) )
- throw uno::RuntimeException( rtl::OUString::createFromAscii( "ConsecutinveDelimiter parameter should be a boolean" ),
+ if( !( ConsecutiveDelimiter >>= bConsecutiveDelimiter ) )
+ throw uno::RuntimeException( rtl::OUString::createFromAscii( "ConsecutiveDelimiter parameter should be a boolean" ),
uno::Reference< uno::XInterface >() );
- OSL_TRACE("set ConsecutinveDelimiter\n");
+ OSL_TRACE("set ConsecutiveDelimiter\n");
}
sal_Bool bTab = sal_False;
@@ -4735,7 +4876,13 @@ ScVbaRange::TextToColumns( const css::uno::Any& Destination, const css::uno::Any
throw uno::RuntimeException( rtl::OUString::createFromAscii( "Other parameter should be a True" ),
uno::Reference< uno::XInterface >() );
}
- //TODO* FieldInfo Optional Variant. An array containing parse information for the individual columns of data. The interpretation depends on the value of DataType. When the data is delimited, this argument is an array of two-element arrays, with each two-element array specifying the conversion options for a particular column. The first element is the column number (1-based), and the second element is one of the xlColumnDataType constants specifying how the column is parsed.
+ // FieldInfo, Optional Variant. An array containing parse information for the individual columns of data.
+ // The interpretation depends on the value of DataType. When the data is delimited, this argument is an array
+ // of two-element arrays, with each two-element array specifying the conversion options for a particular column.
+ // The first element is the column number (1-based), and the second element is one of the xlColumnDataType
+ // constants specifying how the column is parsed.
+ uno::Sequence< uno::Sequence< uno::Any > > sFieldInfo;
+ FieldInfo >>= sFieldInfo;
rtl::OUString sDecimalSeparator;
if( DecimalSeparator.hasValue() )
@@ -4753,7 +4900,106 @@ ScVbaRange::TextToColumns( const css::uno::Any& Destination, const css::uno::Any
uno::Reference< uno::XInterface >() );
OSL_TRACE("set ThousandsSpeparator\n" );
}
- //TODO* TrailingMinusNumbers Optional Variant. Numbers that begin with a minus character.
+ //TODO* TrailingMinusNumbers Optional Variant. Numbers that begin with a minus character.
+
+ // Get the destination range's left-upper cell address.
+ ScVbaRange* pDestVbaRange = dynamic_cast< ScVbaRange* >( xRange.get() );
+ ScAddress aScDestAddress;
+ if ( pDestVbaRange )
+ {
+ ScUnoConversion::FillScAddress( aScDestAddress, pDestVbaRange->getLeftUpperCellAddress() );
+ }
+
+ // Parse the value of parameter FieldInfo.
+ USHORT nCount = 0, nRealCount = 0;
+ xub_StrLen* pColumns = NULL;
+ BYTE* pFormats = NULL;
+ if ( sFieldInfo.getLength() > 0 )
+ {
+ nCount = sFieldInfo.getLength();
+ pColumns = new xub_StrLen[nCount];
+ pFormats = new BYTE[nCount];
+ USHORT nFormat = 1;
+ uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext );
+ for ( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
+ {
+ if ( sFieldInfo[nIndex].getLength() >= 2 )
+ {
+ nFormat = 1;
+ try
+ {
+ uno::Any aConverted = xConverter->convertTo( sFieldInfo[nIndex][0], getCppuType((xub_StrLen*)0) );
+ aConverted >>= pColumns[nRealCount];
+ aConverted = xConverter->convertTo( sFieldInfo[nIndex][1], getCppuType((USHORT*)0) );
+ aConverted >>= nFormat;
+ }
+ catch( const uno::Exception& )
+ {
+ }
+ pFormats[nRealCount++] = nFormat;
+ }
+ }
+ }
+
+ sal_Unicode cTextQualifier = '"';
+ cTextQualifier = xlTextQualifier == excel::XlTextQualifier::xlTextQualifierNone ? '\0' : cTextQualifier;
+ cTextQualifier = xlTextQualifier == excel::XlTextQualifier::xlTextQualifierSingleQuote ? '\'' : cTextQualifier;
+
+ // Get field delimiters.
+ String rFieldDelimiters;
+ if ( bTab ) rFieldDelimiters += '\t';
+ if ( bSemicolon ) rFieldDelimiters += ';';
+ if ( bComma ) rFieldDelimiters += ',';
+ if ( bSpace ) rFieldDelimiters += ' ';
+ if ( bOther ) rFieldDelimiters += *sOtherChar.getStr();
+
+ // Get the text in current range to SvMemoryStream.
+ ScRange aSrcScRange;
+ ScCellRangesBase* pSrcCellRangesBase = getCellRangesBase();
+ if ( pSrcCellRangesBase )
+ {
+ ScRangeList aRangeList = pSrcCellRangesBase->GetRangeList();
+ if ( aRangeList.First() )
+ {
+ aSrcScRange = *aRangeList.First();
+ }
+ }
+ ScImportExport aExport( getScDocument(), aSrcScRange );
+ aExport.SetDelimiter( static_cast< sal_Unicode >( 0 ) );
+ SvMemoryStream aStream;
+ aStream.SetStreamCharSet( RTL_TEXTENCODING_UNICODE );
+ ScImportExport::SetNoEndianSwap( aStream );
+ aExport.ExportStream( aStream, String(), FORMAT_STRING );
+ aStream.Seek( 0 );
+
+ // Set ScAsciiOptions according to the input parameters.
+ ScAsciiOptions aOptions;
+ aOptions.SetFixedLen( !bDilimited );
+ aOptions.SetStartRow( 0 );
+ aOptions.SetColInfo( nRealCount, pColumns, pFormats );
+ if ( bDilimited )
+ {
+ aOptions.SetFieldSeps( rFieldDelimiters );
+ aOptions.SetMergeSeps( bConsecutiveDelimiter );
+ aOptions.SetTextSep( cTextQualifier );
+ }
+
+ // Split the String in to columns.
+ if ( pDestVbaRange && pDestVbaRange->getScDocument() )
+ {
+ ScImportExport aImport( pDestVbaRange->getScDocument(), aScDestAddress );
+ aImport.SetExtOptions( aOptions );
+ aImport.SetApi( false );
+ aImport.ImportStream( aStream, String(), FORMAT_STRING );
+ }
+ if ( pColumns )
+ {
+ DELETEZ( pColumns );
+ }
+ if ( pFormats )
+ {
+ DELETEZ( pFormats );
+ }
}
uno::Any SAL_CALL
@@ -4762,7 +5008,7 @@ ScVbaRange::Hyperlinks( const uno::Any& aIndex ) throw (uno::RuntimeException)
/* The range object always returns a new Hyperlinks object containing a
fixed list of existing hyperlinks in the range.
See vbahyperlinks.hxx for more details. */
-
+
// get the global hyperlink object of the sheet (sheet should always be the parent of a Range object)
uno::Reference< excel::XWorksheet > xWorksheet( getParent(), uno::UNO_QUERY_THROW );
uno::Reference< excel::XHyperlinks > xSheetHlinks( xWorksheet->Hyperlinks( uno::Any() ), uno::UNO_QUERY_THROW );
@@ -4780,7 +5026,7 @@ ScVbaRange::Hyperlinks( const uno::Any& aIndex ) throw (uno::RuntimeException)
css::uno::Reference< excel::XValidation > SAL_CALL
ScVbaRange::getValidation() throw (css::uno::RuntimeException)
{
- if ( !m_xValidation.is() )
+ if ( !m_xValidation.is() )
m_xValidation = new ScVbaValidation( this, mxContext, mxRange );
return m_xValidation;
}
@@ -4863,12 +5109,12 @@ uno::Any SAL_CALL ScVbaRange::getPrefixCharacter() throw (uno::RuntimeException)
character, if the cell is right-aligned; a circumflex character, if the
cell is centered; a backslash character, if the cell is set to filled;
or an empty string, if nothing of the above.
-
+
If a range or a list of ranges contains texts with leading apostroph
character as well as other cells, this function returns an empty
string.
*/
-
+
if( mxRange.is() )
return lclGetPrefixVariant( lclGetPrefixChar( mxRange ) );
if( mxRanges.is() )
@@ -4883,7 +5129,7 @@ uno::Any ScVbaRange::getShowDetail() throw ( css::uno::RuntimeException)
// In MSO VBA, the specified range must be a single summary column or row in an outline. otherwise throw exception
if( m_Areas->getCount() > 1 )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can not get Range.ShowDetail attribute ")), uno::Reference< uno::XInterface >() );
-
+
sal_Bool bShowDetail = sal_False;
RangeHelper helper( mxRange );
@@ -4897,8 +5143,8 @@ uno::Any ScVbaRange::getShowDetail() throw ( css::uno::RuntimeException)
if( (thisAddress.StartRow == thisAddress.EndRow && thisAddress.EndRow == aOutlineAddress.EndRow ) ||
(thisAddress.StartColumn == thisAddress.EndColumn && thisAddress.EndColumn == aOutlineAddress.EndColumn ))
{
- sal_Bool bColumn =thisAddress.StartRow == thisAddress.EndRow ? sal_False:sal_True;
- ScDocument* pDoc = getDocumentFromRange( mxRange );
+ sal_Bool bColumn =thisAddress.StartRow == thisAddress.EndRow ? sal_False:sal_True;
+ ScDocument* pDoc = excel::GetDocumentFromRange( mxRange );
ScOutlineTable* pOutlineTable = pDoc->GetOutlineTable(static_cast<SCTAB>(thisAddress.Sheet), sal_True);
const ScOutlineArray* pOutlineArray = bColumn ? pOutlineTable->GetColArray(): pOutlineTable->GetRowArray();
if( pOutlineArray )
@@ -4926,7 +5172,7 @@ void ScVbaRange::setShowDetail(const uno::Any& aShowDetail) throw ( css::uno::Ru
// In MSO VBA, the specified range must be a single summary column or row in an outline. otherwise throw exception
if( m_Areas->getCount() > 1 )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can not set Range.ShowDetail attribute ")), uno::Reference< uno::XInterface >() );
-
+
bool bShowDetail = extractBoolFromAny( aShowDetail );
RangeHelper helper( mxRange );
@@ -4939,9 +5185,9 @@ void ScVbaRange::setShowDetail(const uno::Any& aShowDetail) throw ( css::uno::Ru
table::CellRangeAddress thisAddress = helper.getCellRangeAddressable()->getRangeAddress();
if( (thisAddress.StartRow == thisAddress.EndRow && thisAddress.EndRow == aOutlineAddress.EndRow ) ||
(thisAddress.StartColumn == thisAddress.EndColumn && thisAddress.EndColumn == aOutlineAddress.EndColumn ))
- {
- // #FIXME, seems there is a different behavior between MSO and OOo.
- // In OOo, the showDetail will show all the level entrys, while only show the first level entry in MSO
+ {
+ // #FIXME, seems there is a different behavior between MSO and OOo.
+ // In OOo, the showDetail will show all the level entrys, while only show the first level entry in MSO
uno::Reference< sheet::XSheetOutline > xSheetOutline( helper.getSpreadSheet(), uno::UNO_QUERY_THROW );
if( bShowDetail )
xSheetOutline->showDetail( aOutlineAddress );
@@ -4954,7 +5200,25 @@ void ScVbaRange::setShowDetail(const uno::Any& aShowDetail) throw ( css::uno::Ru
}
}
-uno::Reference< excel::XRange > SAL_CALL
+//09-09-16 add by limingl
+::com::sun::star::uno::Reference< ::ooo::vba::excel::XQueryTable > SAL_CALL
+ScVbaRange::getQueryTable() throw (::com::sun::star::uno::RuntimeException)
+{
+ /*
+ if (m_pQueryTable == NULL)
+ {
+ m_pQueryTable = new ScVbaQueryTable(mxParent ,mxContext, getScDocument(), this); //add by limingl
+ }
+ //*/
+ if (!m_xQueryTable.is())
+ {
+ m_xQueryTable = new ScVbaQueryTable(mxParent ,mxContext, getScDocument(), this); //add by limingl
+ }
+
+ return m_xQueryTable;
+}
+//end add
+uno::Reference< excel::XRange > SAL_CALL
ScVbaRange::MergeArea() throw (script::BasicErrorException, uno::RuntimeException)
{
uno::Reference< sheet::XSheetCellRange > xMergeShellCellRange(mxRange->getCellRangeByPosition(0,0,0,0), uno::UNO_QUERY_THROW);
@@ -4973,7 +5237,7 @@ ScVbaRange::MergeArea() throw (script::BasicErrorException, uno::RuntimeExceptio
}
else
{
- ScRange refRange( static_cast< SCCOL >( aCellAddress.StartColumn ), static_cast< SCROW >( aCellAddress.StartRow ), static_cast< SCTAB >( aCellAddress.Sheet ),
+ ScRange refRange( static_cast< SCCOL >( aCellAddress.StartColumn ), static_cast< SCROW >( aCellAddress.StartRow ), static_cast< SCTAB >( aCellAddress.Sheet ),
static_cast< SCCOL >( aCellAddress.EndColumn ), static_cast< SCROW >( aCellAddress.EndRow ), static_cast< SCTAB >( aCellAddress.Sheet ) );
uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( getScDocShell() , refRange ) );
return new ScVbaRange( mxParent, mxContext,xRange );
@@ -4983,13 +5247,125 @@ ScVbaRange::MergeArea() throw (script::BasicErrorException, uno::RuntimeExceptio
return new ScVbaRange( mxParent, mxContext, mxRange );
}
-void SAL_CALL
+//2008-08-25 add by limingl
+//The recordset's member: Recordset.Fields.Item will get a Field obj.
+//Field.value is the column value.
+::sal_Int32 SAL_CALL
+ScVbaRange::CopyFromRecordset( const ::com::sun::star::uno::Any& Data, const ::com::sun::star::uno::Any& MaxRows, const ::com::sun::star::uno::Any& MaxColumns )
+throw (::com::sun::star::script::BasicErrorException, ::com::sun::star::uno::RuntimeException)
+{
+ uno::Sequence< uno::Any > aParams;
+ uno::Sequence< uno::Any > aFieldsParams(1);
+ uno::Sequence< sal_Int16 > aOutParamIndex;
+ uno::Sequence< uno::Any > aOutParam;
+ uno::Reference< uno::XInterface > xIntRes;
+ uno::Reference< uno::XInterface > xIntFields;
+ uno::Reference< uno::XInterface > xIntFld;
+ uno::Any aRet;
+ uno::Any aPar;
+ uno::Any aCrrCol;
+ uno::Any aCrrRow;
+ sal_Int16 nCrrCol = 0;
+ sal_Int32 nCrrRow = 0;
+ sal_Int32 nCol;
+ sal_Int32 nMaxRows = 0;
+ sal_Int32 nMaxColumns = 0;
+ sal_Bool bEof;
+// sal_Bool bColName = sal_True;
+ long lColCnt = 0;
+ if (MaxColumns.hasValue())
+ {
+ MaxColumns >>= nMaxColumns;
+ }
+
+ long lMaxCol = nMaxColumns;
+
+ if (MaxRows.hasValue())
+ {
+ MaxRows >>= nMaxRows;
+ }
+
+
+ Data >>= xIntRes;
+ uno::Reference< script::XInvocation > xInvRes(xIntRes, uno::UNO_QUERY_THROW);
+ rtl::OUString oMoveNext = rtl::OUString::createFromAscii("MoveNext") ;
+ rtl::OUString oEof = rtl::OUString::createFromAscii("EOF") ;
+ rtl::OUString oFields = rtl::OUString::createFromAscii("Fields") ;
+
+ if( !xInvRes->hasMethod(oMoveNext))
+ {
+ return -1;
+ }
+
+ //Get columns count
+ aRet = xInvRes->getValue(oFields);
+ aRet >>= xIntFields;
+ uno::Reference< script::XInvocation > xInvFields(xIntFields, uno::UNO_QUERY_THROW);
+ aRet = xInvFields->getValue( rtl::OUString::createFromAscii("Count")) ;
+ aRet >>= lColCnt;
+
+ //Set the assign column number
+ if (lMaxCol != 0)
+ {
+ if (lColCnt > lMaxCol)
+ {
+ lColCnt = lMaxCol;
+ }
+ }
+
+ aCrrRow <<= nCrrRow;
+ aCrrCol <<= nCrrCol;
+
+
+ //Get start position
+ uno::Reference< excel::XRange > xRngStartRow = Rows(uno::Any(sal_Int32(1)) );
+ uno::Reference< excel::XRange > xRngPos = xRngStartRow->Columns( uno::Any(sal_Int32(1)) );
+
+ while(1)
+ {//travel recordset
+ //get every column
+ for (long l = 0; l < lColCnt ; l++)
+ {
+ nCol = l;
+ aPar <<= nCol;
+ //get every field
+ aRet = xInvFields->invoke( rtl::OUString::createFromAscii("Item"), uno::Sequence< uno::Any >(&aPar,1) , aOutParamIndex,aOutParam);
+ aRet >>= xIntFld;
+ uno::Reference< script::XInvocation > xInvFld(xIntFld, uno::UNO_QUERY_THROW); //Get the Field obj
+
+ //set the field value
+ aRet = xInvFld->getValue( rtl::OUString::createFromAscii("Value") );
+ uno::Reference< excel::XRange > xRngToFill = xRngPos->Offset(aCrrRow,aCrrCol );
+
+ xRngToFill->setValue(aRet);
+ nCrrCol++;
+ aCrrCol <<= nCrrCol;
+ }
+
+ aRet = xInvRes->invoke(oMoveNext, aParams,aOutParamIndex,aOutParam );
+ aRet = xInvRes->getValue(oEof);
+ aRet >>= bEof;
+ if (bEof || ( nCrrRow >= nMaxRows && nMaxRows != 0) )
+ {//Arrive the end of recordset
+ break;
+ }
+
+ nCrrRow++;
+ aCrrRow <<= nCrrRow;
+ nCrrCol = 0;
+ aCrrCol <<= nCrrCol;
+ }
+
+ return 0;
+}
+//end add
+void SAL_CALL
ScVbaRange::PrintOut( const uno::Any& From, const uno::Any& To, const uno::Any& Copies, const uno::Any& Preview, const uno::Any& ActivePrinter, const uno::Any& PrintToFile, const uno::Any& Collate, const uno::Any& PrToFileName ) throw (uno::RuntimeException)
{
ScDocShell* pShell = NULL;
sal_Int32 nItems = m_Areas->getCount();
- uno::Sequence< table::CellRangeAddress > printAreas( nItems );
+ uno::Sequence< table::CellRangeAddress > printAreas( nItems );
uno::Reference< sheet::XPrintAreas > xPrintAreas;
for ( sal_Int32 index=1; index <= nItems; ++index )
{
@@ -5001,7 +5377,7 @@ ScVbaRange::PrintOut( const uno::Any& From, const uno::Any& To, const uno::Any&
{
ScVbaRange* pRange = getImplementation( xRange );
// initialise the doc shell and the printareas
- pShell = getDocShellFromRange( pRange->mxRange );
+ pShell = excel::GetDocShellFromRange( pRange->mxRange );
xPrintAreas.set( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
}
printAreas[ index - 1 ] = rangeAddress;
@@ -5018,25 +5394,25 @@ ScVbaRange::PrintOut( const uno::Any& From, const uno::Any& To, const uno::Any&
}
void SAL_CALL
-ScVbaRange::AutoFill( const uno::Reference< excel::XRange >& Destination, const uno::Any& Type ) throw (uno::RuntimeException)
+ScVbaRange::AutoFill( const uno::Reference< excel::XRange >& Destination, const uno::Any& Type ) throw (uno::RuntimeException)
{
uno::Reference< excel::XRange > xDest( Destination, uno::UNO_QUERY_THROW );
ScVbaRange* pRange = getImplementation( xDest );
RangeHelper destRangeHelper( pRange->mxRange );
- table::CellRangeAddress destAddress = destRangeHelper.getCellRangeAddressable()->getRangeAddress();
-
+ table::CellRangeAddress destAddress = destRangeHelper.getCellRangeAddressable()->getRangeAddress();
+
RangeHelper thisRange( mxRange );
- table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
+ table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
ScRange sourceRange;
ScRange destRange;
- ScUnoConversion::FillScRange( destRange, destAddress );
+ ScUnoConversion::FillScRange( destRange, destAddress );
ScUnoConversion::FillScRange( sourceRange, thisAddress );
-
-
+
+
// source is valid
-// if ( !sourceRange.In( destRange ) )
-// throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "source not in destination" ) ), uno::Reference< uno::XInterface >() );
+// if ( !sourceRange.In( destRange ) )
+// throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "source not in destination" ) ), uno::Reference< uno::XInterface >() );
FillDir eDir = FILL_TO_BOTTOM;
double fStep = 1.0;
@@ -5046,7 +5422,7 @@ ScVbaRange::AutoFill( const uno::Reference< excel::XRange >& Destination, const
// default to include the number of Rows in the source range;
SCCOLROW nSourceCount = ( sourceRange.aEnd.Row() - sourceRange.aStart.Row() ) + 1;
- SCCOLROW nCount = 0;
+ SCCOLROW nCount = 0;
if ( sourceRange != destRange )
{
@@ -5057,7 +5433,7 @@ ScVbaRange::AutoFill( const uno::Reference< excel::XRange >& Destination, const
{
nSourceCount = ( sourceRange.aEnd.Col() - sourceRange.aStart.Col() + 1 );
aSourceRange.aEnd.SetCol( static_cast<SCCOL>( aSourceRange.aStart.Col() + nSourceCount - 1 ) );
- eDir = FILL_TO_RIGHT;
+ eDir = FILL_TO_RIGHT;
nCount = aRange.aEnd.Col() - aSourceRange.aEnd.Col();
}
else if ( sourceRange.aEnd.Col() == destRange.aEnd.Col() )
@@ -5068,13 +5444,13 @@ ScVbaRange::AutoFill( const uno::Reference< excel::XRange >& Destination, const
}
}
- else if ( aSourceRange.aEnd == destRange.aEnd )
+ else if ( aSourceRange.aEnd == destRange.aEnd )
{
if ( sourceRange.aStart.Col() == destRange.aStart.Col() )
{
aSourceRange.aStart.SetRow( static_cast<SCROW>( aSourceRange.aEnd.Row() - nSourceCount + 1 ) );
nCount = aSourceRange.aStart.Row() - aRange.aStart.Row();
- eDir = FILL_TO_TOP;
+ eDir = FILL_TO_TOP;
fStep = -fStep;
}
else if ( sourceRange.aStart.Row() == destRange.aStart.Row() )
@@ -5082,15 +5458,15 @@ ScVbaRange::AutoFill( const uno::Reference< excel::XRange >& Destination, const
nSourceCount = ( sourceRange.aEnd.Col() - sourceRange.aStart.Col() ) + 1;
aSourceRange.aStart.SetCol( static_cast<SCCOL>( aSourceRange.aEnd.Col() - nSourceCount + 1 ) );
nCount = aSourceRange.aStart.Col() - aRange.aStart.Col();
- eDir = FILL_TO_LEFT;
+ eDir = FILL_TO_LEFT;
fStep = -fStep;
}
}
- }
- ScDocShell* pDocSh= getDocShellFromRange( mxRange );
+ }
+ ScDocShell* pDocSh= excel::GetDocShellFromRange( mxRange );
FillCmd eCmd = FILL_AUTO;
- FillDateCmd eDateCmd = FILL_DAY;
+ FillDateCmd eDateCmd = FILL_DAY;
#ifdef VBA_OOBUILD_HACK
double fEndValue = MAXDOUBLE;
@@ -5098,12 +5474,12 @@ ScVbaRange::AutoFill( const uno::Reference< excel::XRange >& Destination, const
if ( Type.hasValue() )
{
- sal_Int16 nFillType = excel::XlAutoFillType::xlFillDefault;
+ sal_Int16 nFillType = excel::XlAutoFillType::xlFillDefault;
Type >>= nFillType;
switch ( nFillType )
{
case excel::XlAutoFillType::xlFillCopy:
- eCmd = FILL_SIMPLE;
+ eCmd = FILL_SIMPLE;
fStep = 0.0;
break;
case excel::XlAutoFillType::xlFillDays:
@@ -5133,9 +5509,9 @@ ScVbaRange::AutoFill( const uno::Reference< excel::XRange >& Destination, const
break;
case excel::XlAutoFillType::xlFillDefault:
default:
- eCmd = FILL_AUTO;
+ eCmd = FILL_AUTO;
break;
- }
+ }
}
ScDocFunc aFunc(*pDocSh);
#ifdef VBA_OOBUILD_HACK
@@ -5160,7 +5536,7 @@ ScVbaRange::GoalSeek( const uno::Any& Goal, const uno::Reference< excel::XRange
table::CellAddress changingCell( changingCellAddr.Sheet, changingCellAddr.StartColumn, changingCellAddr.StartRow );
sheet::GoalResult res = xGoalSeek->seekGoal( thisCell, changingCell, sGoal );
ChangingCell->setValue( uno::makeAny( res.Result ) );
-
+
// openoffice behaves differently, result is 0 if the divergence is too great
// but... if it detects 0 is the value it requires then it will use that
// e.g. divergence & result both = 0.0 does NOT mean there is an error
@@ -5178,7 +5554,7 @@ ScVbaRange::Calculate( ) throw (script::BasicErrorException, uno::RuntimeExcept
getWorksheet()->Calculate();
}
-uno::Reference< excel::XRange > SAL_CALL
+uno::Reference< excel::XRange > SAL_CALL
ScVbaRange::Item( const uno::Any& row, const uno::Any& column ) throw (script::BasicErrorException, uno::RuntimeException)
{
if ( mbIsRows || mbIsColumns )
@@ -5192,7 +5568,7 @@ ScVbaRange::Item( const uno::Any& row, const uno::Any& column ) throw (script::B
xRange = Rows( row );
return xRange;
}
- return Cells( row, column );
+ return Cells( row, column );
}
void
@@ -5201,22 +5577,17 @@ ScVbaRange::AutoOutline( ) throw (script::BasicErrorException, uno::RuntimeExce
// #TODO #FIXME needs to check for summary row/col ( whatever they are )
// not valid for multi Area Addresses
if ( m_Areas->getCount() > 1 )
- DebugHelper::exception(SbERR_METHOD_FAILED, STR_ERRORMESSAGE_APPLIESTOSINGLERANGEONLY);
- // So needs to either span an entire Row or a just be a single cell
+ DebugHelper::exception(SbERR_METHOD_FAILED, STR_ERRORMESSAGE_APPLIESTOSINGLERANGEONLY);
+ // So needs to either span an entire Row or a just be a single cell
// ( that contains a summary RowColumn )
- // also the Single cell cause doesn't seem to be handled specially in
- // this code ( ported from the helperapi RangeImpl.java,
+ // also the Single cell cause doesn't seem to be handled specially in
+ // this code ( ported from the helperapi RangeImpl.java,
// RangeRowsImpl.java, RangesImpl.java, RangeSingleCellImpl.java
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
- if ( isSingleCellRange() || mbIsRows )
- {
- uno::Reference< sheet::XSheetOutline > xSheetOutline( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
- xSheetOutline->autoOutline( thisAddress );
- }
- else
- DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
+ uno::Reference< sheet::XSheetOutline > xSheetOutline( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
+ xSheetOutline->autoOutline( thisAddress );
}
void SAL_CALL
@@ -5228,24 +5599,24 @@ ScVbaRange:: ClearOutline( ) throw (script::BasicErrorException, uno::RuntimeEx
for ( sal_Int32 index=1; index <= nItems; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
- xRange->ClearOutline();
+ xRange->ClearOutline();
}
return;
}
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
uno::Reference< sheet::XSheetOutline > xSheetOutline( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
- xSheetOutline->clearOutline();
+ xSheetOutline->clearOutline();
}
-void
+void
ScVbaRange::groupUnGroup( bool bUnGroup ) throw ( script::BasicErrorException, uno::RuntimeException )
{
if ( m_Areas->getCount() > 1 )
DebugHelper::exception(SbERR_METHOD_FAILED, STR_ERRORMESSAGE_APPLIESTOSINGLERANGEONLY);
- table::TableOrientation nOrient = table::TableOrientation_ROWS;
- if ( mbIsColumns )
- nOrient = table::TableOrientation_COLUMNS;
+ table::TableOrientation nOrient = table::TableOrientation_COLUMNS;
+ if ( mbIsRows )
+ nOrient = table::TableOrientation_ROWS;
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
uno::Reference< sheet::XSheetOutline > xSheetOutline( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
@@ -5255,23 +5626,23 @@ ScVbaRange::groupUnGroup( bool bUnGroup ) throw ( script::BasicErrorException, u
xSheetOutline->group( thisAddress, nOrient );
}
-void SAL_CALL
+void SAL_CALL
ScVbaRange::Group( ) throw (script::BasicErrorException, uno::RuntimeException)
{
- groupUnGroup();
+ groupUnGroup();
}
-void SAL_CALL
+void SAL_CALL
ScVbaRange::Ungroup( ) throw (script::BasicErrorException, uno::RuntimeException)
{
- groupUnGroup(true);
+ groupUnGroup(true);
}
void lcl_mergeCellsOfRange( const uno::Reference< table::XCellRange >& xCellRange, sal_Bool _bMerge = sal_True ) throw ( uno::RuntimeException )
{
uno::Reference< util::XMergeable > xMergeable( xCellRange, uno::UNO_QUERY_THROW );
- xMergeable->merge(_bMerge);
+ xMergeable->merge(_bMerge);
}
-void SAL_CALL
+void SAL_CALL
ScVbaRange::Merge( const uno::Any& Across ) throw (script::BasicErrorException, uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
@@ -5280,11 +5651,11 @@ ScVbaRange::Merge( const uno::Any& Across ) throw (script::BasicErrorException,
for ( sal_Int32 index=1; index <= nItems; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
- xRange->Merge(Across);
+ xRange->Merge(Across);
}
return;
}
- uno::Reference< table::XCellRange > oCellRange;
+ uno::Reference< table::XCellRange > oCellRange;
sal_Bool bAcross = sal_False;
Across >>= bAcross;
if ( !bAcross )
@@ -5300,7 +5671,7 @@ ScVbaRange::Merge( const uno::Any& Across ) throw (script::BasicErrorException,
}
}
-void SAL_CALL
+void SAL_CALL
ScVbaRange::UnMerge( ) throw (script::BasicErrorException, uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
@@ -5309,14 +5680,14 @@ ScVbaRange::UnMerge( ) throw (script::BasicErrorException, uno::RuntimeExceptio
for ( sal_Int32 index=1; index <= nItems; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
- xRange->UnMerge();
+ xRange->UnMerge();
}
return;
}
lcl_mergeCellsOfRange( mxRange, sal_False);
}
-uno::Any SAL_CALL
+uno::Any SAL_CALL
ScVbaRange::getStyle() throw (uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
@@ -5328,11 +5699,11 @@ ScVbaRange::getStyle() throw (uno::RuntimeException)
rtl::OUString sStyleName;
xProps->getPropertyValue(CELLSTYLE) >>= sStyleName;
ScDocShell* pShell = getScDocShell();
- uno::Reference< frame::XModel > xModel( pShell->GetModel() );
+ uno::Reference< frame::XModel > xModel( pShell->GetModel() );
uno::Reference< excel::XStyle > xStyle = new ScVbaStyle( this, mxContext, sStyleName, xModel );
return uno::makeAny( xStyle );
}
-void SAL_CALL
+void SAL_CALL
ScVbaRange::setStyle( const uno::Any& _style ) throw (uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
@@ -5349,11 +5720,11 @@ ScVbaRange::setStyle( const uno::Any& _style ) throw (uno::RuntimeException)
uno::Reference< excel::XRange >
ScVbaRange::PreviousNext( bool bIsPrevious )
-{
+{
ScMarkData markedRange;
- ScRange refRange;
+ ScRange refRange;
RangeHelper thisRange( mxRange );
-
+
ScUnoConversion::FillScRange( refRange, thisRange.getCellRangeAddressable()->getRangeAddress());
markedRange. SetMarkArea( refRange );
short nMove = bIsPrevious ? -1 : 1;
@@ -5362,8 +5733,8 @@ ScVbaRange::PreviousNext( bool bIsPrevious )
SCROW nNewY = refRange.aStart.Row();
SCTAB nTab = refRange.aStart.Tab();
- ScDocument* pDoc = getScDocument();
- pDoc->GetNextPos( nNewX,nNewY, nTab, nMove,0, TRUE,TRUE, markedRange );
+ ScDocument* pDoc = getScDocument();
+ pDoc->GetNextPos( nNewX,nNewY, nTab, nMove,0, TRUE,TRUE, markedRange );
refRange.aStart.SetCol( nNewX );
refRange.aStart.SetRow( nNewY );
refRange.aStart.SetTab( nTab );
@@ -5372,11 +5743,11 @@ ScVbaRange::PreviousNext( bool bIsPrevious )
refRange.aEnd.SetTab( nTab );
uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( getScDocShell() , refRange ) );
-
+
return new ScVbaRange( mxParent, mxContext, xRange );
}
-uno::Reference< excel::XRange > SAL_CALL
+uno::Reference< excel::XRange > SAL_CALL
ScVbaRange::Next() throw (script::BasicErrorException, uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
@@ -5387,7 +5758,7 @@ ScVbaRange::Next() throw (script::BasicErrorException, uno::RuntimeException)
return PreviousNext( false );
}
-uno::Reference< excel::XRange > SAL_CALL
+uno::Reference< excel::XRange > SAL_CALL
ScVbaRange::Previous() throw (script::BasicErrorException, uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
@@ -5401,9 +5772,10 @@ ScVbaRange::Previous() throw (script::BasicErrorException, uno::RuntimeException
uno::Reference< excel::XRange > SAL_CALL
ScVbaRange::SpecialCells( const uno::Any& _oType, const uno::Any& _oValue) throw ( script::BasicErrorException )
{
- bool bIsSingleCell = isSingleCellRange();
+ bool bIsSingleCell = isSingleCellRange();
bool bIsMultiArea = ( m_Areas->getCount() > 1 );
ScVbaRange* pRangeToUse = this;
+ uno::Reference< excel::XRange > xUsedRange( getWorksheet()->getUsedRange() );
sal_Int32 nType = 0;
if ( !( _oType >>= nType ) )
DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
@@ -5412,7 +5784,7 @@ ScVbaRange::SpecialCells( const uno::Any& _oType, const uno::Any& _oValue) throw
case excel::XlCellType::xlCellTypeSameFormatConditions:
case excel::XlCellType::xlCellTypeAllValidation:
case excel::XlCellType::xlCellTypeSameValidation:
- DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString());
+ DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString());
break;
case excel::XlCellType::xlCellTypeBlanks:
case excel::XlCellType::xlCellTypeComments:
@@ -5440,9 +5812,9 @@ ScVbaRange::SpecialCells( const uno::Any& _oType, const uno::Any& _oValue) throw
uno::Reference< excel::XRange > xTmpRange( m_Areas->Item( uno::makeAny( nArea ), uno::Any() ), uno::UNO_QUERY_THROW );
RangeHelper rHelper( xTmpRange->getCellRange() );
rangeResults.push_back( rHelper.getCellRangeAddressable()->getRangeAddress() );
- }
+ }
}
- }
+ }
ScRangeList aCellRanges;
std::vector< table::CellRangeAddress >::iterator it = rangeResults.begin();
std::vector< table::CellRangeAddress >::iterator it_end = rangeResults.end();
@@ -5459,24 +5831,23 @@ ScVbaRange::SpecialCells( const uno::Any& _oType, const uno::Any& _oValue) throw
return new ScVbaRange( mxParent, mxContext, xRange );
}
uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( getScDocShell(), aCellRanges ) );
-
+
return new ScVbaRange( mxParent, mxContext, xRanges );
}
else if ( bIsSingleCell )
{
- uno::Reference< excel::XRange > xUsedRange = getWorksheet()->getUsedRange();
- pRangeToUse = static_cast< ScVbaRange* >( xUsedRange.get() );
+ pRangeToUse = static_cast< ScVbaRange* >( xUsedRange.get() );
}
-
+
break;
- }
+ }
default:
DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
break;
}
if ( !pRangeToUse )
DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
- return pRangeToUse->SpecialCellsImpl( nType, _oValue );
+ return pRangeToUse->SpecialCellsImpl( nType, _oValue );
}
sal_Int32 lcl_getFormulaResultFlags(const uno::Any& aType) throw ( script::BasicErrorException )
@@ -5489,7 +5860,7 @@ sal_Int32 lcl_getFormulaResultFlags(const uno::Any& aType) throw ( script::Basic
{
case excel::XlSpecialCellsValue::xlErrors:
nRes= sheet::FormulaResult::ERROR;
- break;
+ break;
case excel::XlSpecialCellsValue::xlLogical:
//TODO bc93774: ask NN if this is really an appropriate substitute
nRes = sheet::FormulaResult::VALUE;
@@ -5506,7 +5877,7 @@ sal_Int32 lcl_getFormulaResultFlags(const uno::Any& aType) throw ( script::Basic
return nRes;
}
-uno::Reference< excel::XRange >
+uno::Reference< excel::XRange >
ScVbaRange::SpecialCellsImpl( sal_Int32 nType, const uno::Any& _oValue) throw ( script::BasicErrorException )
{
uno::Reference< excel::XRange > xRange;
@@ -5521,9 +5892,9 @@ ScVbaRange::SpecialCellsImpl( sal_Int32 nType, const uno::Any& _oValue) throw (
case excel::XlCellType::xlCellTypeSameFormatConditions:
case excel::XlCellType::xlCellTypeAllValidation:
case excel::XlCellType::xlCellTypeSameValidation:
- // Shouldn't get here ( should be filtered out by
+ // Shouldn't get here ( should be filtered out by
// ScVbaRange::SpecialCells()
- DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString());
+ DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString());
break;
case excel::XlCellType::xlCellTypeBlanks:
xLocSheetCellRanges = xQuery->queryEmptyCells();
@@ -5532,7 +5903,7 @@ ScVbaRange::SpecialCellsImpl( sal_Int32 nType, const uno::Any& _oValue) throw (
xLocSheetCellRanges = xQuery->queryContentCells(sheet::CellFlags::ANNOTATION);
break;
case excel::XlCellType::xlCellTypeConstants:
- xLocSheetCellRanges = xQuery->queryContentCells(23);
+ xLocSheetCellRanges = xQuery->queryContentCells(23);
break;
case excel::XlCellType::xlCellTypeFormulas:
{
@@ -5543,7 +5914,7 @@ ScVbaRange::SpecialCellsImpl( sal_Int32 nType, const uno::Any& _oValue) throw (
case excel::XlCellType::xlCellTypeLastCell:
xRange = Cells( uno::makeAny( getCount() ), uno::Any() );
case excel::XlCellType::xlCellTypeVisible:
- xLocSheetCellRanges = xQuery->queryVisibleCells();
+ xLocSheetCellRanges = xQuery->queryVisibleCells();
break;
default:
DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
@@ -5556,19 +5927,19 @@ ScVbaRange::SpecialCellsImpl( sal_Int32 nType, const uno::Any& _oValue) throw (
}
catch (uno::Exception& )
{
- DebugHelper::exception(SbERR_METHOD_FAILED, STR_ERRORMESSAGE_NOCELLSWEREFOUND);
+ DebugHelper::exception(SbERR_METHOD_FAILED, STR_ERRORMESSAGE_NOCELLSWEREFOUND);
}
return xRange;
}
-void SAL_CALL
+void SAL_CALL
ScVbaRange::RemoveSubtotal( ) throw (script::BasicErrorException, uno::RuntimeException)
{
uno::Reference< sheet::XSubTotalCalculatable > xSub( mxRange, uno::UNO_QUERY_THROW );
- xSub->removeSubTotals();
+ xSub->removeSubTotals();
}
-void SAL_CALL
+void SAL_CALL
ScVbaRange::Subtotal( ::sal_Int32 _nGroupBy, ::sal_Int32 _nFunction, const uno::Sequence< ::sal_Int32 >& _nTotalList, const uno::Any& aReplace, const uno::Any& PageBreaks, const uno::Any& /*SummaryBelowData*/ ) throw (script::BasicErrorException, uno::RuntimeException)
{
try
@@ -5639,14 +6010,191 @@ ScVbaRange::Subtotal( ::sal_Int32 _nGroupBy, ::sal_Int32 _nFunction, const uno::
}
}
-rtl::OUString&
+uno::Any SAL_CALL ScVbaRange::AdvancedFilter( sal_Int32 Action, const uno::Any& CriteriaRange,
+ const uno::Any& CopyToRange, const uno::Any& Unique ) throw (script::BasicErrorException, uno::RuntimeException)
+{
+ uno::Any aRet;
+ aRet <<= sal_True;
+
+ uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext );
+ ScDocument* pDoc = getScDocument();
+ if ( !pDoc )
+ {
+ throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access document from range" ) ), uno::Reference< uno::XInterface >() );
+ }
+
+ // Action
+ if ( Action != excel::XlFilterAction::xlFilterInPlace && Action != excel::XlFilterAction::xlFilterCopy )
+ {
+ throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Invalid input parameter" ) ), uno::Reference< uno::XInterface >() );
+ }
+ if ( m_Areas->getCount() > 1 )
+ {
+ throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Invalid range" ) ), uno::Reference< uno::XInterface >() );
+ }
+
+ sal_Bool bCopyOut = ( Action != excel::XlFilterAction::xlFilterInPlace );
+ uno::Reference< sheet::XSheetFilterDescriptor > xFilterDesc;
+ uno::Reference< sheet::XSheetFilterable > xSheetFilter( mxRange, uno::UNO_QUERY_THROW );
+
+ // CriteriaRange
+ String aBuiltInCriteria; // Excel Built-In Filter Criteria.
+ ScRangeData* pData = NULL;
+ table::CellRangeAddress refParentAddr;
+ uno::Any aCriteriaRange = CriteriaRange;
+ formula::FormulaGrammar::AddressConvention aConv = formula::FormulaGrammar::CONV_XL_A1;
+ if ( aCriteriaRange.hasValue() && aCriteriaRange.getValueTypeClass() == uno::TypeClass_STRING )
+ {
+ rtl::OUString rRangeString;
+ aCriteriaRange >>= rRangeString;
+ aConv = excel::IsR1C1ReferFormat( pDoc, rRangeString ) ? formula::FormulaGrammar::CONV_XL_R1C1 : aConv;
+ }
+ else
+ {
+ // Get Excel BuiltIn Filter Criteria.
+ ScRangeName* pRangeNames = pDoc->GetRangeName();
+ const USHORT nCount = pRangeNames ? pRangeNames->GetCount() : 0;
+ for ( USHORT index = 0; index < nCount; index++ )
+ {
+ pData = ( ScRangeData* )( pRangeNames->At( index ) );
+ if ( pData && pData->HasType( RT_CRITERIA ) )
+ {
+ pData->GetSymbol( aBuiltInCriteria, formula::FormulaGrammar::GRAM_NATIVE_XL_A1 );
+ break;
+ }
+ }
+ aCriteriaRange = aBuiltInCriteria.Len() > 0 ? uno::makeAny( rtl::OUString( aBuiltInCriteria ) ) : aCriteriaRange;
+ }
+ if ( aCriteriaRange.hasValue() )
+ {
+ table::CellRangeAddress criteriaRangeAddress = getCellRangeAddressForVBARange( aCriteriaRange, getScDocShell(), aConv );
+ ScRange refRange;
+ ScUnoConversion::FillScRange( refRange, criteriaRangeAddress );
+ uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( getScDocShell(), refRange ) );
+ uno::Reference< sheet::XSheetFilterableEx > xCriteria( xRange, uno::UNO_QUERY );
+ if ( xCriteria.is() )
+ {
+ xFilterDesc = xCriteria->createFilterDescriptorByObject( xSheetFilter );
+ }
+ }
+ else if ( mxRange.is() )
+ {
+ uno::Reference< sheet::XSheetFilterableEx > xCriteria( mxRange, uno::UNO_QUERY );
+ if ( xCriteria.is() )
+ {
+ xFilterDesc = xCriteria->createFilterDescriptorByObject( xSheetFilter );
+ }
+ }
+
+ uno::Reference< beans::XPropertySet > xPropertySet( xFilterDesc, uno::UNO_QUERY );
+ if ( xPropertySet.is() )
+ {
+ xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_COPYOUT ) ), uno::makeAny( bCopyOut ) );
+ }
+
+ // CopyToRange
+ if ( bCopyOut && CopyToRange.hasValue() && xPropertySet.is() )
+ {
+ formula::FormulaGrammar::AddressConvention aTmpConv = formula::FormulaGrammar::CONV_XL_A1;
+ if ( CopyToRange.getValueTypeClass() == uno::TypeClass_STRING )
+ {
+ rtl::OUString rRangeString;
+ CopyToRange >>= rRangeString;
+ aTmpConv = excel::IsR1C1ReferFormat( pDoc, rRangeString ) ? formula::FormulaGrammar::CONV_XL_R1C1 : aConv;
+ }
+ ScRange refRange;
+ ScUnoConversion::FillScRange( refRange, getCellRangeAddressForVBARange( CopyToRange, getScDocShell(), aTmpConv ) );
+ uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( getScDocShell(), refRange ) );
+ uno::Reference< sheet::XCellAddressable > xCellAddr( xRange->getCellByPosition( 0, 0 ), uno::UNO_QUERY_THROW );
+ xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_OUTPOS ) ), uno::makeAny( xCellAddr->getCellAddress() ) );
+ }
+
+ // Unique
+ if ( xPropertySet.is() )
+ {
+ sal_Bool bUnique = sal_False;
+ uno::Any aUnique;
+ try
+ {
+ aUnique <<= bUnique;
+ aUnique = ( xConverter.is() && Unique.hasValue() ) ? xConverter->convertTo( Unique, getCppuType( ( sal_Bool* ) 0 ) ) : aUnique;
+ }
+ catch( const uno::Exception& )
+ {
+ }
+ xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_SKIPDUP ) ), aUnique );
+ }
+
+ // Do filter.
+ if ( xFilterDesc.is() )
+ {
+ xSheetFilter->filter( xFilterDesc );
+ }
+
+ return aRet;
+}
+
+//Add by minz@cn.ibm.com. Range.PivotTable.
+//Returns a PivotTable object that represents the PivotTable report containing the upper-left corner of the specified range.
+uno::Reference< excel::XPivotTable >
+ScVbaRange::PivotTable() throw (uno::RuntimeException)
+{
+ uno::Reference< excel::XPivotTable > xDestPVTable;
+
+ uno::Reference< sheet::XSpreadsheet > xSheet;
+ if ( mxRange.is() )
+ {
+ RangeHelper thisRange( mxRange );
+ xSheet = thisRange.getSpreadSheet();
+ }
+ else if ( mxRanges.is() )
+ {
+ uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW );
+ uno::Reference< table::XCellRange > xRange( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
+ RangeHelper thisRange( xRange );
+ xSheet = thisRange.getSpreadSheet();
+ }
+
+// RangeHelper thisRange( mxRange );
+// uno::Reference< sheet::XSpreadsheet > xSheet = thisRange.getSpreadSheet();
+ uno::Reference< sheet::XDataPilotTablesSupplier > xTables(xSheet, uno::UNO_QUERY_THROW ) ;
+ uno::Reference< container::XIndexAccess > xIndexAccess( xTables->getDataPilotTables(), uno::UNO_QUERY_THROW );
+ if ( xIndexAccess.is() )
+ {
+ //get the upper-left cell address
+ table::CellAddress aAddress = getLeftUpperCellAddress();
+
+ sal_Int32 nCount = xIndexAccess->getCount();
+ for (sal_Int32 i=0; i < nCount; i++)
+ {
+ uno::Reference< sheet::XDataPilotTable > xDPTable(xIndexAccess->getByIndex(i), uno::UNO_QUERY);
+ uno::Reference< sheet::XDataPilotTable2 > xDPTable2(xDPTable, uno::UNO_QUERY);
+
+ //check if the cell is in the pivot table
+ sheet::DataPilotTablePositionData posData = xDPTable2->getPositionData(aAddress);
+ table::CellRangeAddress aCellRangeAddress = xDPTable->getOutputRange();
+ ScRange aScRange( aCellRangeAddress.StartColumn, aCellRangeAddress.StartRow, aCellRangeAddress.Sheet,
+ aCellRangeAddress.EndColumn, aCellRangeAddress.EndRow, aCellRangeAddress.Sheet );
+ ScAddress aPos( aAddress.Column, aAddress.Row, aAddress.Sheet );
+ if( !(posData.PositionType == sheet::DataPilotTablePositionType::NOT_IN_TABLE) || aScRange.In( aPos ) )
+ {
+ xDestPVTable = new ScVbaPivotTable( mxContext, xDPTable );
+ break;
+ }
+ }
+ }
+ return xDestPVTable;
+}
+
+
+rtl::OUString&
ScVbaRange::getServiceImplName()
{
static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaRange") );
return sImplName;
}
-uno::Sequence< rtl::OUString >
+uno::Sequence< rtl::OUString >
ScVbaRange::getServiceNames()
{
static uno::Sequence< rtl::OUString > aServiceNames;
@@ -5658,6 +6206,25 @@ ScVbaRange::getServiceNames()
return aServiceNames;
}
+sal_Bool SAL_CALL
+ScVbaRange::hasError() throw (uno::RuntimeException)
+{
+ double dResult = sal_False;
+ uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
+ uno::Reference< script::XInvocation > xInvoc( xApplication->WorksheetFunction(), uno::UNO_QUERY_THROW );
+
+ static rtl::OUString FunctionName( RTL_CONSTASCII_USTRINGPARAM("IsError" ) );
+ uno::Sequence< uno::Any > Params(1);
+ uno::Reference< excel::XRange > aRange( this );
+ Params[0] = uno::makeAny( aRange );
+ uno::Sequence< sal_Int16 > OutParamIndex;
+ uno::Sequence< uno::Any > OutParam;
+ xInvoc->invoke( FunctionName, Params, OutParamIndex, OutParam ) >>= dResult;
+ if ( dResult > 0.0 )
+ return sal_True;
+ return sal_False;
+}
+
namespace range
{
namespace sdecl = comphelper::service_decl;