[Solved] Call macro Basic when executing a Python macro

Creating a macro - Writing a Script - Using the API

[Solved] Call macro Basic when executing a Python macro

Postby Math » Sun Apr 21, 2019 5:17 pm

hello friends ,

I'm running the following Python macro in LibreOffice Calc , which is working correctly:
Code: Select all   Expand viewCollapse view
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
Math
 
Posts: 86
Joined: Mon Oct 29, 2018 6:32 pm

Re: Call macro Basic when executing a Python macro

Postby hubert lambert » Mon Apr 22, 2019 5:38 pm

Hi,

A quick example.
The basic macro:
Code: Select all   Expand viewCollapse view
Sub Main(msg)
    msgbox(msg)
End Sub

The calling python code:
Code: Select all   Expand viewCollapse view
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 41 times
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
hubert lambert
 
Posts: 127
Joined: Mon Jun 13, 2016 10:50 am

[Solved] Call macro Basic when executing a Python macro

Postby Math » Mon Apr 22, 2019 8:28 pm

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
Math
 
Posts: 86
Joined: Mon Oct 29, 2018 6:32 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 7 guests