Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


Hello all,

I have been trying to add support for assigning to named ranges in
VBA. There are a couple of ways VBA does this but for now I'm focusing
on something like:

Range("A1:H8").Name = "TestRange"

Currently the Name property on [X/ScVba]Range is readonly. I've
attached a patch which is my first attempt to try and add a setter but
it was suggested that I also attach an xls with a test macro. I know
there is some changing going on with regards to VBA tests; is there a
place I should stick this to execute for now? I would also really
appreciate someone taking a quick look at the patch because I'm very
new to working with uno.

Thanks Michael and Markus for helping me out so much on IRC :)

August Sodora
augsod@gmail.com
(201) 280-8138
From 1f51f50dda79d2db9430aa52e233ce0b56cd1268 Mon Sep 17 00:00:00 2001
From: August Sodora <augsod@gmail.com>
Date: Wed, 26 Oct 2011 15:32:55 -0400
Subject: [PATCH] Add vba support for assigning names to cell ranges

---
 oovbaapi/ooo/vba/excel/XRange.idl |    2 +-
 sc/source/ui/vba/vbarange.cxx     |   23 +++++++++++++++++++++++
 sc/source/ui/vba/vbarange.hxx     |    1 +
 3 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/oovbaapi/ooo/vba/excel/XRange.idl b/oovbaapi/ooo/vba/excel/XRange.idl
index 62a0994..015c68c 100644
--- a/oovbaapi/ooo/vba/excel/XRange.idl
+++ b/oovbaapi/ooo/vba/excel/XRange.idl
@@ -64,7 +64,7 @@ interface XRange
     interface ::ooo::vba::excel::XFormat;
     //interface ::ooo::vba::XHelperInterface;
 
-    [attribute, readonly] any Name;
+    [attribute] any Name;
     [attribute] any Value;
     [attribute] any Formula;
     [attribute] any FormulaArray;
diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx
index fe8c9df..659bff8 100644
--- a/sc/source/ui/vba/vbarange.cxx
+++ b/sc/source/ui/vba/vbarange.cxx
@@ -1569,6 +1569,29 @@ uno::Any SAL_CALL ScVbaRange::getName() throw (uno::RuntimeException)
     return uno::makeAny( xName );
 }
 
+void
+ScVbaRange::setName( const uno::Any& aName ) 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(RTL_CONSTASCII_USTRINGPARAM( "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(RTL_CONSTASCII_USTRINGPARAM("NamedRanges"))) , uno::UNO_QUERY_THROW );
+
+    uno::Reference< excel::XNames > xNames( new ScVbaNames( uno::Reference< XHelperInterface >(), 
mxContext , xNamedRanges , xModel ) );
+
+    uno::Any aDummy;
+    //uno::Any aRefersTo;
+    //    aRefersTo <<= uno::Reference< excel::XRange >(this, uno::UNO_QUERY);
+    xNames->Add(aName, getCellRange(), aDummy, aDummy, aDummy, aDummy,
+                aDummy, aDummy, aDummy, aDummy, aDummy);
+}
+
 uno::Any
 ScVbaRange::getValue( ValueGetter& valueGetter) throw (uno::RuntimeException)
 {
diff --git a/sc/source/ui/vba/vbarange.hxx b/sc/source/ui/vba/vbarange.hxx
index db4e49d..26f639f 100644
--- a/sc/source/ui/vba/vbarange.hxx
+++ b/sc/source/ui/vba/vbarange.hxx
@@ -167,6 +167,7 @@ public:
 
     // Attributes
     virtual css::uno::Any SAL_CALL getName() throw (css::uno::RuntimeException);
+    virtual void   SAL_CALL setName( const css::uno::Any& aName ) throw 
(css::uno::RuntimeException);
     virtual css::uno::Any SAL_CALL getValue() throw (css::uno::RuntimeException);
     virtual void   SAL_CALL setValue( const css::uno::Any& aValue ) throw ( 
css::uno::RuntimeException);
     virtual css::uno::Any SAL_CALL getFormula() throw (css::uno::RuntimeException);
-- 
1.7.4.4


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.