[Solved] Call macro Basic when executing a Python macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Math
Posts: 89
Joined: Mon Oct 29, 2018 6:32 pm

[Solved] Call macro Basic when executing a Python macro

Post by Math »

hello friends ,

I'm running the following Python macro in LibreOffice Calc , which is working correctly:

Code: Select all

import urllib.request
from html.parser import HTMLParser
class MyParser(HTMLParser):
    def __init__(self,target_tag):
        HTMLParser.__init__(self)
        self.targetTag=target_tag
        self.targetFound=False
        self.dataArray=[]
    def handle_starttag(self,tag,attrs):
        self.targetFound=False
        if (tag==self.targetTag):
            self.targetFound=True
    def handle_endtag(self,tag):
        if tag==self.targetTag:
            self.targetFound=False
    def handle_data(self, data):
        if (self.targetFound):
            self.dataArray.append(data)
#######   target URL   #######################
MyUrl='https://coinmarketcap.com/#currencies_wrapper'
OpenUrl=urllib.request.urlopen(MyUrl)
#######  get the html code   ################
responseHTML=OpenUrl.read().decode('utf-8')
parser=MyParser("a")
parser.feed(responseHTML)
# LibreOffice code #
activeSheet=XSCRIPTCONTEXT.getDocument().getCurrentController().getActiveSheet()
def LastMessage(*args):
    activeSheet.getCellRangeByName("A1").setString(parser.dataArray[45])
    activeSheet.getCellRangeByName("B1").setString(parser.dataArray[46])
    activeSheet.getCellRangeByName("A2").setString(parser.dataArray[47])
    activeSheet.getCellRangeByName("B2").setString(parser.dataArray[48])
at the end of this Python macro I want to call a Basic macro that is in the same file .

here is the Basic macro information I want to run at the end of the above python macro:
filename: connexion
library: Standard
module: Module1
macro: ajustar_colunas

I did search in the forum and found a python code, I also found another python code , but neither code is working for me .

I'm grateful now for all the Help .
Last edited by Math on Sat Apr 27, 2019 6:44 am, edited 1 time in total.
LibreOffice 5.4.4.2 on Windows 7
hubert lambert
Posts: 145
Joined: Mon Jun 13, 2016 10:50 am

Re: Call macro Basic when executing a Python macro

Post by hubert lambert »

Hi,

A quick example.
The basic macro:

Code: Select all

Sub Main(msg)
    msgbox(msg)
End Sub
The calling python code:

Code: Select all

def call_embedded_basic_macro(event=None):
    doc = XSCRIPTCONTEXT.getDocument()
    scriptprovider = doc.ScriptProvider
    basic_macro_uri = "vnd.sun.star.script:Standard.Module1.Main?language=Basic&location=document"
    basic_macro = scriptprovider.getScript(basic_macro_uri)
    basic_macro.invoke(("Well done!",),(),()) 
Regards.
Attachments
Math.ods
(11.54 KiB) Downloaded 151 times
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
Math
Posts: 89
Joined: Mon Oct 29, 2018 6:32 pm

[Solved] Call macro Basic when executing a Python macro

Post by Math »

greetings hubert lambert ,

Thank you very much for your help . :super:

the python macro worked perfectly . :bravo:

Friend hug .
LibreOffice 5.4.4.2 on Windows 7
Post Reply