diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
commit | 267c6f2ac71f92999e969232431ba04678e7437e (patch) | |
tree | 358c9467650e1d0a1d7227a21dac2e3d08b622b2 /odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/python | |
parent | Initial commit. (diff) | |
download | libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.tar.xz libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.zip |
Adding upstream version 4:24.2.0.upstream/4%24.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/python')
-rwxr-xr-x | odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/python/FirstLoadComponent.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/python/FirstLoadComponent.py b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/python/FirstLoadComponent.py new file mode 100755 index 0000000000..a5d93d799f --- /dev/null +++ b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/python/FirstLoadComponent.py @@ -0,0 +1,62 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +import uno +import officehelper +import sys +import traceback +from com.sun.star.sheet.CellFlags import FORMULA + + +def main(): + try: + remote_context = officehelper.bootstrap() + if remote_context is None: + print("ERROR: Could not bootstrap default Office.") + sys.exit(1) + srv_mgr = remote_context.getServiceManager() + desktop = srv_mgr.createInstanceWithContext("com.sun.star.frame.Desktop", remote_context) + spreadsheet_component = desktop.loadComponentFromURL("private:factory/scalc", "_blank", 0, tuple()) + spreadsheets = spreadsheet_component.getSheets() + spreadsheets.insertNewByName("MySheet", 0) + elem_type = spreadsheets.getElementType() + print(elem_type) + sheet = spreadsheets.getByName("MySheet") + cell = sheet.getCellByPosition(0, 0) + cell.setValue(21) + cell = sheet.getCellByPosition(0, 1) + cell.setValue(21) + cell = sheet.getCellByPosition(0, 2) + cell.setFormula("=sum(A1:A2)") + + cell.setPropertyValue("CellStyle", "Result") + + spreadsheet_controller = spreadsheet_component.getCurrentController() + spreadsheet_controller.setActiveSheet(sheet) + cell.setPropertyValue("VertJustify", "com.sun.star.table.CellVertJustify.TOP") + formula_cells = sheet.queryContentCells(FORMULA) + formulas = formula_cells.getCells() + formula_enum = formulas.createEnumeration() + + while formula_enum.hasMoreElements(): + formula_cell = formula_enum.nextElement() + print("Formula cell in column " + str(formula_cell.getCellAddress().Column) + + ", row " + str(formula_cell.getCellAddress().Row) + + " contains " + cell.getFormula()) + + except Exception as e: + print(e) + traceback.print_exc() + sys.exit(1) + + +if __name__ == "__main__": + main() + +# vim: set shiftwidth=4 softtabstop=4 expandtab: |