Error in calling a Python script from a Basic function in LO Calc
Error in calling a Python script from a Basic function in LO Calc
I am new in Python and Basic. I am trying to replicate the ImportHtml function from Google Sheets in Libre Office (LO) Calc. In a a nutshell, I want to create a GetHtmTable( Url, Table Index) Basic function in Calc which will call a Python script to do the heavy work.
So based on Villeroy great example, https://forum.openoffice.org/en/forum/viewtopic.php?f=45&t=73145&p=329658, I implemented in LO 5.1.6.2. the Basic SOUNDEX function which calls the Python script sheetFunctions.py
to get familiar with the process. My environment is Linux Mint 18, I use Python3, I imported all kind of libraries such as Uno, PIP etc.. I use PycharmProjects
as a Python editor.
sheetFunctions.py
PycharmProjects
I see clearly under the LO Calc menu tools->macro->organize macros->python the sheetFunctions.py
python script, which indeed is in the folder /usr/lib/libreoffice/share/Scripts/python
.
sheetFunctions.py
/usr/lib/libreoffice/share/Scripts/python
Whenever, I run the SOUNDEX Basic function I get the following error message:
BASIC runtime error.
An exception occurred
Type: com.sun.star.script.provider.ScriptFrameworkErrorException
Message: <class 'pythonscript.com.sun.star.ucb.InteractiveAugmentedIOException'>: an error occurred during file opening
/usr/lib/libreoffice/program/pythonscript.py:429 in function getModuleByUrl() [lastRead = self.sfa.getDateTimeModified( url )]
/usr/lib/libreoffice/program/pythonscript.py:993 in function getScript() [mod = self.provCtx.getModuleByUrl( fileUri )]
I tried to debug the SOUNDEX basic function and found out the blocking point is when the program runs getScript("vnd.sun.star.script:sheetFunctions.py$soundex?language=Python&location=user")
.
getScript("vnd.sun.star.script:sheetFunctions.py$soundex?language=Python&location=user")
I've been trying for days now to overcome this error, unsuccessfully I must confess. I wonder if I need to bring some extra extensions in the Basic environment or a missing add-in in the Linux/Python one? I changed the location=user by location=document and got stuck again. I added recently libreoffice-script-provider-python thanks to the command sudo apt-get install libreoffice-script-provider-python
but this did not help. I also embedded in the calc document the Python script but same this did not solve the issue.
sudo apt-get install libreoffice-script-provider-python
1 Answer
1
The location name does not match. The standard place for self-written scripts is under the user directory. This is location=user
, for example ~/.config/libreoffice/4/user/Scripts/python
.
location=user
~/.config/libreoffice/4/user/Scripts/python
Then there is location=share
, which refers to the path in your question. These parameters are described under Python Script in the URI Specification.
location=share
See also my answer to this question. Be sure to try the APSO extension if you haven't yet. Especially, APSO helps when using location=document
, because embedding requires several steps including editing manifest.xml.
location=document
Thanks a ton Jim, it worked. Never thought about location, great learnings.
– Chris
Jun 30 at 10:34
@Chris: Glad it helped. Please accept the answer.
– Jim K
Jun 30 at 17:19
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Minor point: The question should say imported uno, not implemented uno.
– Jim K
Jun 30 at 7:40