1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 """Returns a list of the named ranges in the document.
18 desktop
= XSCRIPTCONTEXT
.getDesktop()
19 model
= desktop
.getCurrentComponent()
20 rangeNames
= model
.NamedRanges
.ElementNames
23 range = model
.NamedRanges
.getByName(i
).Content
24 result
.append((i
, range))
26 except Exception as e
:
27 print("Caught Exception: " + str(e
))
29 traceback
.print_tb(tb
)
33 def DefineNamedRange(sheet
, x0
, y0
, width
, height
, name
):
34 """Defines a new (or replaces an existing) named range on a sheet,
35 using zero-based absolute coordinates
37 desktop
= XSCRIPTCONTEXT
.getDesktop()
38 model
= desktop
.getCurrentComponent()
39 # FIXME: Is there some Python-callable API to turn a row and column into an A1 string?
40 # This obviously works only for the first 26 columns.
41 abc
= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
42 content
= "$" + sheet
+ "." + "$" + \
43 abc
[x0
: x0
+1] + "$" + str(y0
+1) + ":" + "$" + abc
[x0
+width
-
44 1: x0
+width
] + "$" + str(y0
+height
)
45 position
= uno
.createUnoStruct('com.sun.star.table.CellAddress')
49 model
.NamedRanges
.addNewByName(name
, content
, position
, 0)
53 def DeleteNamedRange(name
):
55 desktop
= XSCRIPTCONTEXT
.getDesktop()
56 model
= desktop
.getCurrentComponent()
57 model
.NamedRanges
.removeByName(name
)
58 except Exception as e
:
59 print("Caught Exception: " + str(e
))
61 traceback
.print_tb(tb
)
64 # vim: set shiftwidth=4 softtabstop=4 expandtab: