[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - 2 commits - desktop/source scripting/examples

Tor Lillqvist tml at collabora.com
Tue Apr 3 14:36:58 UTC 2018


 desktop/source/lib/init.cxx              |   14 +++++++++++
 scripting/examples/python/NamedRanges.py |   37 +++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

New commits:
commit 84da73dca4f2c8ee05e75ea119f1ad5f18c27677
Author: Tor Lillqvist <tml at collabora.com>
Date:   Fri Jan 19 18:00:46 2018 +0200

    Add another sample Python script, to handle named ranges in spreadsheets
    
    Change-Id: Ibe11ab2c3513a05b9aec574602b24df70270908c
    Reviewed-on: https://gerrit.libreoffice.org/51968
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tor Lillqvist <tml at collabora.com>
    (cherry picked from commit e32b4c8a079e4b51b1028d2467b872ff5b8cdd3a)
    Reviewed-on: https://gerrit.libreoffice.org/52092
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Reviewed-on: https://gerrit.libreoffice.org/52315

diff --git a/scripting/examples/python/NamedRanges.py b/scripting/examples/python/NamedRanges.py
new file mode 100644
index 000000000000..abdef141f397
--- /dev/null
+++ b/scripting/examples/python/NamedRanges.py
@@ -0,0 +1,37 @@
+import traceback
+import uno
+
+def GetNamedRanges():
+    """Returns a list of the named ranges in the document.
+    """
+    try:
+        desktop = XSCRIPTCONTEXT.getDesktop()
+        model = desktop.getCurrentComponent()
+        rangeNames = model.NamedRanges.ElementNames
+        result = []
+        for i in rangeNames:
+            range = model.NamedRanges.getByName(i).Content
+            result.append((i, range))
+        return result
+    except Exception as e:
+        print("Caught Exception: " + str(e))
+        tb = e.__traceback__
+        traceback.print_tb(tb)
+        return None
+
+def DefineNamedRange(sheet, x0, y0, width, height, name):
+    """Defines a new (or replaces an existing) named range on a sheet,
+    using zero-based absolute coordinates
+    """
+    desktop = XSCRIPTCONTEXT.getDesktop()
+    model = desktop.getCurrentComponent()
+    # FIXME: Is there some Python-callable API to turn a row and column into an A1 string?
+    # This obviously works only for the first 26 columns.
+    abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+    content = sheet +"!" + "$" + abc[x0 : x0+1] + "$" + str(y0+1) + ":" + "$" + abc[x0+width-1 : x0+width] + "$" + str(y0+height)
+    position = uno.createUnoStruct('com.sun.star.table.CellAddress')
+    position.Sheet = 0
+    position.Column = 0
+    position.Row = 0
+    model.NamedRanges.addNewByName(name, content, position, 0)
+    return None
commit 0a61121424458dcd6fabba3c95e26d54aed1f132
Author: Tor Lillqvist <tml at collabora.com>
Date:   Fri Jan 19 17:44:52 2018 +0200

    Handle also []any in unoAnyToPropertyTree()
    
    We add it as a subtree where each element in the sequence has as its
    name its number.
    
    Change-Id: I9422777d887d899f76ad6d259631d15c2db53f03
    Reviewed-on: https://gerrit.libreoffice.org/51967
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tor Lillqvist <tml at collabora.com>
    (cherry picked from commit 1bf2ed44a18666843d6c1b4a92966fd78cda07bf)
    Reviewed-on: https://gerrit.libreoffice.org/52091
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Reviewed-on: https://gerrit.libreoffice.org/52314

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 032db627d7d6..9c337990aebe 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -276,6 +276,20 @@ static boost::property_tree::ptree unoAnyToPropertyTree(const uno::Any& anyItem)
         aTree.put("value", OString::number(anyItem.get<sal_uInt32>()).getStr());
     else if (aType == "long")
         aTree.put("value", OString::number(anyItem.get<sal_Int32>()).getStr());
+    else if (aType == "[]any")
+    {
+        uno::Sequence<uno::Any> aSeq;
+        if (anyItem >>= aSeq)
+        {
+            boost::property_tree::ptree aSubTree;
+
+            for (auto i = 0; i < aSeq.getLength(); ++i)
+            {
+                aSubTree.add_child(OString::number(i).getStr(), unoAnyToPropertyTree(aSeq[i]));
+            }
+            aTree.add_child("value", aSubTree);
+        }
+    }
 
     // TODO: Add more as required
 


More information about the Libreoffice-commits mailing list