3

Python uno can communicate with libreoffice-calc via socket,the common way is to launch libreOffice-calc from the shell:

soffice --calc --accept="socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"

soffice can communicate python-uno with socket and port:2002.

sudo netstat -anp  |grep  soffice
tcp        0      0 127.0.0.1:2002          0.0.0.0:*               LISTEN      3115/soffice.bin    
unix  2      [ ACC ]     STREAM     LISTENING     45712    3115/soffice.bin     /tmp/OSL_PIPE_1000_SingleOfficeIPC_7fb3858dfd518f4aa054b3e7cf720
unix  3      [ ]         STREAM     CONNECTED     45702    3115/soffice.bin     
unix  3      [ ]         STREAM     CONNECTED     45716    3115/soffice.bin    

Then you can open a python shell ,import uno to manipulate calc.

Now i open an calc from menu:

enter image description here

When you start soffice from menu:

sudo netstat -anp  |grep  soffice
unix  2      [ ACC ]     STREAM     LISTENING     49386    3200/soffice.bin     /tmp/OSL_PIPE_1000_SingleOfficeIPC_7fb3858dfd518f4aa054b3e7cf720
unix  3      [ ]         STREAM     CONNECTED     49390    3200/soffice.bin     
unix  3      [ ]         STREAM     CONNECTED     48919    3200/soffice.bin  

soffice can not communicate python-uno with socket ,the port:2002 is not opened.

How can manipulate the calc with python-uno when lilbreoffice-calc started from menu?

showkey
  • 482
  • 42
  • 140
  • 295
  • Is the issue that you want to start LibreOffice Calc from the menu, with the same parameters as when you launched from the shell? – Karl Sep 02 '20 at 08:21
  • Without the same parameters,how to revjise it then? – showkey Sep 03 '20 at 00:48

1 Answers1

0

This is not really a Python question but you need to modify the .desktop file for LibreOffice Calc and add the configuration parameters. You could for example open a terminal window and type:

sudo nano /usr/share/applications/libreoffice-calc.desktop

Then find the row Exec which probably looks like this: libreoffice --calc %U Add your parameters:

libreoffice --calc --accept="socket,host=localhost,port=2002;urp;StarOffice.ServiceManager" %U

Be sure to keep the %U at the end of the command to keep it functioning as before.

Save, and now it should work!

Karl
  • 331
  • 1
  • 6
  • Kindly thank to your attention,edit calc.desktop only bypass the issue,instead of solving it directly. – showkey Sep 03 '20 at 05:55
  • If you want to interact with LibreOffice via UNO you must launch the application in this way. It does not listen to any resources by default for security reasons. – Karl Sep 03 '20 at 06:17