Hi all,
How do you access the internet with LibreOffice/OpenOffice Basic, what are the tools?
To be more precise: is it possible to fill a Calc file with data from a web page in JSON, XML, and why not HTLM format?
Thanks.
Internet in LO/OO BASIC
Internet in LO/OO BASIC
LibreOffice 5.3.3.2 - Lubuntu 16.10 - LxQt 0.11.0.3
-
- Posts: 310
- Joined: Sun Sep 06, 2020 8:27 am
Re: Internet in LO/OO BASIC
BASIC as a language is not aware of anything like the internet and will provide nothing. You may load files, if the OS or LibreOffice helps: You can use file:-URLs, but to parse any modern stuff like xml, json etc you are on your own or need a library.
Obviously there is library-code available for xml and html in UNO, because LO uses XML itself and can import html.
But actually I would start searching here, as there is a Calc-service, wich can import data to a Calc-grid and it may be easier to use the existing options:
https://wiki.documentfoundation.org/Doc ... WEBSERVICE
Obviously there is library-code available for xml and html in UNO, because LO uses XML itself and can import html.
But actually I would start searching here, as there is a Calc-service, wich can import data to a Calc-grid and it may be easier to use the existing options:
https://wiki.documentfoundation.org/Doc ... WEBSERVICE
OpenOffice 3.1 on Windows Vista
Re: Internet in LO/OO BASIC
Hi Mountainner,
Thank you for the WEBSERVICE link I did not know and it gives a starting point.
In fact for my extensions I use the Python Request API, one of the easiest HTTP request APIs to use.
As I use it from different extensions, I finally managed to port the Request API to UNO and should therefore also be accessible to BASIC.
This port of the Request API provides two new interfaces under UNO:
(with contenttype as a ContentType) allowing to suck web pages in Calc.
I have to create a dialog box to set the properties of XRequestParameter, that's not too complicated.
The Calc part is accessing the correct cell and injecting the data. For this part I cruelly lack skills.
Thank you for the WEBSERVICE link I did not know and it gives a starting point.
In fact for my extensions I use the Python Request API, one of the easiest HTTP request APIs to use.
As I use it from different extensions, I finally managed to port the Request API to UNO and should therefore also be accessible to BASIC.
This port of the Request API provides two new interfaces under UNO:
- com.sun.star.rest.XRequestParameter: which are the parameters that will be used when executing the HTTP request.
- com.sun.star.rest.XRequestResponse: which the result of the execution of the HTTP request
- To know the status of the HTTP request.
- To access the content of the request as a binary stream XEnumeration.
- To manage the tokens of the following pages found in the JSON or XLM APIs of google Drive API or Microsoft graph, allowing the execution of requests in a loop.
- Install the OAuth2OOo extension
- Create the UNO service:
Code: Select all
session = CreateUnoService("io.github.prrvchr.OAuth2OOo.OAuth2Service")
- If you want to use OAuth2 initialize session (optionnal):
Code: Select all
session.initializeSession(url, emailaddress)
- Get a Request Parameter:
Code: Select all
parameter = session.getRequestParameter("aname")
- Set a least an URL and the NoAuth properties (the default HTTP request method is GET):
Code: Select all
parameter.Url = "https://...."
Code: Select all
parameter.NoAuth = true
- Get the HTTP response from parameter:
Code: Select all
response = session.execute(parameter)
- do what you have to do with your response then:
Code: Select all
response.close()
Code: Select all
pullToCalc(XRequestParameter, ThisComponent, contenttype)
I have to create a dialog box to set the properties of XRequestParameter, that's not too complicated.
The Calc part is accessing the correct cell and injecting the data. For this part I cruelly lack skills.
LibreOffice 5.3.3.2 - Lubuntu 16.10 - LxQt 0.11.0.3