summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2018-01-18 18:27:50 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-04-03 13:12:07 +0200
commita8ba30a54c6005de746c09fe19ded72c8bfebc6e (patch)
tree4cb1ab7a31dc033be7bb6886e1c1b5834a8915cc
parent825ba822a9d445e81ff8b05aac69949cad40182b (diff)
Add another sample Python script
Change-Id: I542a8b36a097d8961dc76fdcc3d25a3d7b6eb526 Reviewed-on: https://gerrit.libreoffice.org/51966 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tor Lillqvist <tml@collabora.com> (cherry picked from commit aa27a25d152ab70f60fedcea3bd4cd99d68103a0) Reviewed-on: https://gerrit.libreoffice.org/52090 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
-rw-r--r--scripting/Package_ScriptsPython.mk1
-rw-r--r--scripting/examples/python/SetCellColor.py15
2 files changed, 16 insertions, 0 deletions
diff --git a/scripting/Package_ScriptsPython.mk b/scripting/Package_ScriptsPython.mk
index 1d0de559bd20..8cc8a85472ff 100644
--- a/scripting/Package_ScriptsPython.mk
+++ b/scripting/Package_ScriptsPython.mk
@@ -12,6 +12,7 @@ $(eval $(call gb_Package_Package,scripting_ScriptsPython,$(SRCDIR)/scripting/exa
$(eval $(call gb_Package_add_files_with_dir,scripting_ScriptsPython,$(LIBO_SHARE_FOLDER)/Scripts,\
python/Capitalise.py \
python/HelloWorld.py \
+ python/SetCellColor.py \
python/pythonSamples/TableSample.py \
))
diff --git a/scripting/examples/python/SetCellColor.py b/scripting/examples/python/SetCellColor.py
new file mode 100644
index 000000000000..743a6daa948b
--- /dev/null
+++ b/scripting/examples/python/SetCellColor.py
@@ -0,0 +1,15 @@
+def SetCellColor(x, y, color):
+ """Sets the background of the cell at (x,y) (zero-based column and row
+ indices, for example (2,3) == C4) on the first sheet and
+ returns the contents of the cell as a string.
+ """
+ #get the doc from the scripting context which is made available to all scripts
+ desktop = XSCRIPTCONTEXT.getDesktop()
+ model = desktop.getCurrentComponent()
+ #check whether there's already an opened document
+ if not hasattr(model, "Sheets"):
+ return ""
+ sheet = model.Sheets.Sheet1
+ cell = sheet.getCellByPosition(x, y)
+ cell.CellBackColor = color
+ return cell.String