summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Power <noel.power@suse.com>2013-04-29 14:53:09 +0100
committerNoel Power <noel.power@suse.com>2013-05-07 09:56:29 +0100
commita5f9d5bda0ef09a8bad2fc7b988db4aea53c9553 (patch)
tree4f1cff8264c78db8dbbcd550ab3b1dd9ed696710
parentb713643f19ca45b0451f10e89562c802edaa699d (diff)
implement Range.Name
Change-Id: I884f84e437dad9440951e60c8f92fd6487c48832
-rw-r--r--oovbaapi/ooo/vba/excel/XRange.idl2
-rw-r--r--sc/source/ui/vba/vbarange.cxx52
-rw-r--r--sc/source/ui/vba/vbarange.hxx1
3 files changed, 55 insertions, 0 deletions
diff --git a/oovbaapi/ooo/vba/excel/XRange.idl b/oovbaapi/ooo/vba/excel/XRange.idl
index 5125ea6f34c5..eff93ee22efa 100644
--- a/oovbaapi/ooo/vba/excel/XRange.idl
+++ b/oovbaapi/ooo/vba/excel/XRange.idl
@@ -43,6 +43,7 @@ interface XCharacters;
interface XBorders;
interface XValidation;
interface XWorksheet;
+interface XName;
interface XRange
{
@@ -68,6 +69,7 @@ interface XRange
[attribute] any ColumnWidth;
[attribute, readonly ] any Width;
[attribute, readonly] XWorksheet Worksheet;
+ [attribute, readonly] XName Name;
[attribute] any RowHeight;
[attribute, readonly ] any Height;
[attribute, readonly ] any Top;
diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx
index 110512e373c3..852fefadb30c 100644
--- a/sc/source/ui/vba/vbarange.cxx
+++ b/sc/source/ui/vba/vbarange.cxx
@@ -161,6 +161,7 @@
#include "vbaglobals.hxx"
#include "vbastyle.hxx"
+#include "vbaname.hxx"
#include <vector>
#include <vbahelper/vbacollectionimpl.hxx>
// begin test includes
@@ -4095,6 +4096,57 @@ ScVbaRange::getTop() throw (uno::RuntimeException)
return uno::makeAny( lcl_hmmToPoints( aPoint.Y ) );
}
+
+uno::Reference< sheet::XCellRangeReferrer > getNamedRange( const uno::Reference< uno::XInterface >& xIf, const uno::Reference< table::XCellRange >& thisRange )
+{
+ uno::Reference< beans::XPropertySet > xProps( xIf, uno::UNO_QUERY_THROW );
+ uno::Reference< container::XNameAccess > xNameAccess( xProps->getPropertyValue( "NamedRanges" ), uno::UNO_QUERY_THROW );
+
+ uno::Sequence< OUString > sNames = xNameAccess->getElementNames();
+// uno::Reference< table::XCellRange > thisRange( getCellRange(), uno::UNO_QUERY_THROW );
+ uno::Reference< sheet::XCellRangeReferrer > xNamedRange;
+ for ( sal_Int32 i=0; i < sNames.getLength(); ++i )
+ {
+ uno::Reference< sheet::XCellRangeReferrer > xName( xNameAccess->getByName( sNames[ i ] ), uno::UNO_QUERY );
+ if ( xName.is() )
+ {
+ if ( thisRange == xName->getReferredCells() )
+ {
+ xNamedRange = xName;
+ break;
+ }
+ }
+ }
+ return xNamedRange;
+}
+
+uno::Reference< excel::XName >
+ScVbaRange::getName() throw (uno::RuntimeException)
+{
+ uno::Reference< beans::XPropertySet > xProps( getUnoModel(), uno::UNO_QUERY );
+ uno::Reference< table::XCellRange > thisRange( getCellRange(), uno::UNO_QUERY_THROW );
+ // Application range
+ uno::Reference< sheet::XCellRangeReferrer > xNamedRange = getNamedRange( xProps, thisRange );
+
+ if ( !xNamedRange.is() )
+ {
+ // not in application range then assume it might be in
+ // sheet namedranges
+ RangeHelper aRange( thisRange );
+ uno::Reference< sheet::XSpreadsheet > xSheet = aRange.getSpreadSheet();
+ xProps.set( xSheet, uno::UNO_QUERY );
+ // impl here
+ xNamedRange = getNamedRange( xProps, thisRange );
+ }
+ if ( xProps.is() && xNamedRange.is() )
+ {
+ uno::Reference< sheet::XNamedRanges > xNamedRanges( xProps, uno::UNO_QUERY_THROW );
+ uno::Reference< sheet::XNamedRange > xName( xNamedRange, uno::UNO_QUERY_THROW );
+ return new ScVbaName( mxParent, mxContext, xName, xNamedRanges, getUnoModel() );
+ }
+ return uno::Reference< excel::XName >();
+}
+
uno::Reference< excel::XWorksheet >
ScVbaRange::getWorksheet() throw (uno::RuntimeException)
{
diff --git a/sc/source/ui/vba/vbarange.hxx b/sc/source/ui/vba/vbarange.hxx
index 3459f52f6647..9f1166a4cb9f 100644
--- a/sc/source/ui/vba/vbarange.hxx
+++ b/sc/source/ui/vba/vbarange.hxx
@@ -183,6 +183,7 @@ public:
virtual css::uno::Any SAL_CALL getTop() throw (css::uno::RuntimeException);
virtual css::uno::Any SAL_CALL getLeft() throw (css::uno::RuntimeException);
+ virtual css::uno::Reference< ov::excel::XName > SAL_CALL getName() throw (css::uno::RuntimeException);
virtual css::uno::Reference< ov::excel::XWorksheet > SAL_CALL getWorksheet() throw (css::uno::RuntimeException);
virtual css::uno::Any SAL_CALL getPageBreak() throw (css::uno::RuntimeException);
virtual void SAL_CALL setPageBreak( const css::uno::Any& _pagebreak ) throw (css::uno::RuntimeException);