Connecting to an open libreoffice spreadsheet

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Connecting to an open libreoffice spreadsheet

Post by braunbaer » 27 Sep 2021, 09:55

Hi!

I have found a few threads regarding how to automate calc, but i was not able to get something running at all.
Get the error message:

Code: Select all

---------------------------
Myscript.ahk
---------------------------
Error in #include file "c:\Bat\TestCalc.ahk":
     0x80080005 - Starten des Servers fehlgeschlagen

	Line#
	185: Sleep,%t%
	186: if !debugsleep  
	187: Return
	188: Sleep,%debugsleep%
	189: ToolTip
	190: }
	192: {
--->	193: objServiceManager := ComObjCreate("com.sun.star.ServiceManager")
	194: objCoreReflection := objServiceManager.createInstance("com.sun.star.reflection.CoreReflection")
	195: oDesk := objServiceManager.createInstance("com.sun.star.frame.Desktop")
	196: args := ComObjArray(VT_VARIANT := 12, 2)
	197: oDoc := oDesk.loadComponentFromURL("private:factory/scalc", "_blank", 0, args)
	198: oSheets := oDoc.getSheets()
	199: }
	072: {

Continue running the script?
---------------------------
Ja   Nein   
---------------------------
I would be glad if someone could post a simple script that does the following tasks:
connect to a currently open calc window
find out which cell is currently focused
read the numeric content of that cell (even if the cell contains a formula)
Multiply by 2 and write the numeric result (no formula) into the cell immediately below
Save the modified spreadsheet without closing it.

thank you!

User avatar
mikeyww
Posts: 26600
Joined: 09 Sep 2014, 18:38

Re: Connecting to an open libreoffice spreadsheet

Post by mikeyww » 27 Sep 2021, 13:01

This gets part of the way there, but still with problems: opens a new copy, seems to use previously saved selection, does not save.

Code: Select all

file    = file:///%A_ScriptDir%\test.ods
oSM    := ComObjCreate("com.sun.star.ServiceManager")
oDesk  := oSM.createInstance("com.sun.star.frame.Desktop")
oArray := ComObjArray(VT_VARIANT := 0xC, 2)
oDoc   := oDesk.loadComponentFromURL(file, "_blank", 0, oArray)
oSheet := oDoc.CurrentController.ActiveSheet
sel    := oDoc.getCurrentSelection(), col := sel.CellAddress.Column, row := sel.CellAddress.Row
oSheet.getCellByPosition(col, row + 1).Value := sel.Value * 2
Perhaps it is still a step in the right direction.

viewtopic.php?style=17&t=68057

In case needed to adjust locking: Tools -> Options -> Advanced -> Open Expert Configuration -> UseLocking -> False

braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Re: Connecting to an open libreoffice spreadsheet

Post by braunbaer » 27 Sep 2021, 15:19

Thank you for your answer.
The problem that I have now is more fundamental: Already the first statement oSM := ComObjCreate("com.sun.star.ServiceManager") fails and produces the error message that I showed in the entry post.

I use LibroOffice, but as far as I understood, the COM interface should be compatible.

Code: Select all

Error in #include file "c:\Bat\TestCalc.ahk":
     0x80080005 - Starten des Servers fehlgeschlagen

...     
--->	193: objServiceManager := ComObjCreate("com.sun.star.ServiceManager")
...

User avatar
mikeyww
Posts: 26600
Joined: 09 Sep 2014, 18:38

Re: Connecting to an open libreoffice spreadsheet

Post by mikeyww » 27 Sep 2021, 16:11

What version of AHK?

If you create test.ods and run my script with no other code, do any errors appear?

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Connecting to an open libreoffice spreadsheet

Post by swagfag » 27 Sep 2021, 16:57

what bitness of ahk, more like. idk if this works for x64

User avatar
mikeyww
Posts: 26600
Joined: 09 Sep 2014, 18:38

Re: Connecting to an open libreoffice spreadsheet

Post by mikeyww » 27 Sep 2021, 17:18

I'm on x64 running U64.

Post Reply

Return to “Ask for Help (v1)”