The operation is simple, just put a number in cell A1. I'm trying with ** windows **.
As a preparation, first, launch a new calc.
Please put the python script that wrote the following in the place of your own macro.
def a1():
doc = XSCRIPTCONTEXT.getDocument()
sheet = doc.getSheets().getByName('Sheet1')
A1 = sheet.getCellRangeByName('A1')
A1.Value = 100
Execute Tools-> Macro-> Manage Macros-> python-> Applicable Script-> a1. To A1 Contains 100.
Since it is difficult to debug with macros, we will make it possible to operate using python scripts from the outside. For now, windows can effectively only use python, which comes with LibreOffice. The situation seems to be the same on Mac and Ubuntu. In other words, it's quite inconvenient ** because you can't add modules freely **.
** (Preparation) ** --python uses LibreOffice attachment (does not conflict with other pythons) --Pass the path through LibreOffice's python. --Start libreoffice ** in a state where it can be operated (explained next) **
(Start-up) Start with a batch command (please name it freely) with options as shown below. Note that there are two lines. The DOS window stays open. It's better to make it a service, but for the time being, this is the way to go. Once launched, ** click once on the sheet. ** The cause is unknown, but it doesn't work unless you click it once.
"C:\Program Files (x86)\LibreOffice 5\program\soffice.exe" ^
--calc --norestore --accept=socket,host=localhost,port=8100;urp
The following does the same thing as a macro. Since it comes with libreoffice, uno is imported You should be able to. It is assumed that a new calc is open. access the current document The following is the same content as the macro. Before that, there are still some parts that I don't understand. Execute with the python script name (free name).
# -*- coding: utf-8 -*-
import uno
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", localContext)
#connect to the running office
ctx = resolver.resolve( "uno:socket,host=localhost,port=8100;urp;StarOffice.ComponentContext" )
smgr = ctx.ServiceManager
# get the central desktop object
desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)
# access the current document ( calc )
doc = desktop.getCurrentComponent()
sheet = doc.getSheets().getByName('Sheet1')
A1 = sheet.getCellRangeByName('A1')
A1.Value = 999
Development is better than macros alone, as macros and the outside world can now do the same thing. Even though it is external, it is inconvenient because pip and ipython cannot be used because you have to use the libreoffice attachment (at the moment).
Recommended Posts