21.12.2022 Views

python_para_desenvolvedores_2ed

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

314 BrOffice.org

Exemplo de geração de relatório em PDF através do editor de texto (Writer),

através da Python UNO Bridge:

# -*- coding: latin1 -*-

# Para iniciar o BrOffice.org como servidor:

# swriter.exe -headless

# "-accept=pipe,name=py;urp;StarOffice.ServiceManager"

import os

import uno

from com.sun.star.beans import PropertyValue

# Dados...

mus = [('Artista', 'Faixa'),

('King Crimson', 'Starless'), ('Yes', 'Siberian Khatru'),

('Led Zeppellin', 'No Quarter'), ('Genesis', 'Supper\'s Ready')]

# Obtêm o número e o tamanho dos registros

rows = len(mus)

cols = len(mus[0])

# Inicio do "Boiler Plate"...

# Contexto de componente local

loc = uno.getComponentContext()

# Para resolver URLs

res = loc.ServiceManager.createInstanceWithContext(

'com.sun.star.bridge.UnoUrlResolver', loc)

# Contexto para a URL

con = res.resolve('uno:pipe,name=py;urp;StarOffice.ComponentContext')

# Documento corrente

desktop = con.ServiceManager.createInstanceWithContext(

'com.sun.star.frame.Desktop', con)

# Fim do "Boiler Plate"...

# Cria um documento novo no Writer

doc = desktop.loadComponentFromURL('private:factory/swriter',

'_blank', 0, ())

# Cursor de texto

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!