Application¶
Remember, always import library.
import easymacro as app
Create instances¶
Instances without context
toolkit = app.create_instance("com.sun.star.awt.Toolkit")
Instances with context
service = 'com.sun.star.awt.DialogProvider2'
dialog = app.create_instance(service, True)
Get desktop
desktop1 = app.create_instance('com.sun.star.frame.Desktop', True)
# ~ or
desktop2 = app.get_desktop()
app.msgbox(desktop1 == desktop2)
Current doc¶
doc = app.active
app.msgbox(doc.title)
Iter docs¶
for doc in app.docs:
app.msgbox(doc.title)
Count¶
count = len(app.docs)
app.msgbox(count)
Get by name¶
name = 'MyDoc.ods'
if name in app.docs:
doc = app.docs[name]
app.msgbox(doc.title)
If contain¶
result = 'myfile.ods' in app.docs
app.msgbox(result)
New¶
For default create new Calc document.
doc = app.docs.new()
app.msgbox(doc.type)
For new Writer document.
doc = app.docs.new('writer')
app.msgbox(doc.type)
With arguments.
args= {'Hidden': True}
doc = app.docs.new('writer', args)
msg = f'{doc.type} - {doc.title}'
app.msgbox(msg)
doc.visible = True
Other documents.
doc = app.docs.new('draw')
app.msgbox(doc.type)
doc = app.docs.new('impress')
app.msgbox(doc.type)
Open¶
path = '/home/mau/MyDoc.ods'
doc = app.docs.open(path)
While LibreOffice support format, you can open arbitrary file.
path = '/home/mau/example.xlsx'
doc = app.docs.open(path)
With arguments.
path = '/home/mau/example.odt'
args = {'Password': 'letmein'}
doc = app.docs.open(path, args)
Save¶
path = '/home/mau/myfile.ods'
doc = app.docs.new()
doc.save(path)
If previously open and modify any file.
doc.save()
Open exists file and save with other name.
path = '/home/mau/myfile.ods'
doc = app.docs.open(path)
new_path = '/srv/mau/other_name.ods'
doc.save(new_path)
Close¶
doc = app.docs.new()
app.msgbox(doc.title)
doc.close()
To PDF¶
Save in path
doc = app.active
path = '/home/mau/test.pdf'
doc.to_pdf(path)
Save in memory
doc = app.active
pdf = doc.to_pdf()
Export¶
Fonst¶
Get all fonts
fonts = app.get_fonts()
for f in fonts:
print(f'Name: {f.Name} - StyleName: {f.StyleName}')
Filters¶
Get all support filters
filters = app.get_filters()
ds = []
for f in filters:
data = f"UI Name: {f['UIName']} - Name: {f['Name']} - Type: {f['Type']}"
app.debug(data)
Call dispatch¶
You can call any dispatch command used only if property or method no exists in original object or in easymacro.py
doc = app.active
command = '.uno:Gallery'
app.call_dispatch(doc, command)
Properties¶
Title¶
doc = app.active
app.msgbox(doc.title)