SlideShare a Scribd company logo
1 of 60
OpenOffice
Application with
Python
imacat
imacat@mail.imacat.idv.tw
2014/5/17
“OpenOffice Application with Python” is created by imacat (Yang Shih-Ching),
and licensed under a Creative Commons Attribution 3.0 Unported License.
imacat
● A member of the Apache OpenOffice Project
Management Committee
● An OpenOffice committer
● The system administrator of the OpenOffice
forum and Wiki
● A PyLadies Taiwan organizer
● Graduated from National Taiwan Normal
University
Why OpenOffice?
Why OpenOffice?
● Free and open source
Why OpenOffice?
● Free and open source
● Cross platform – Windows, Mac, Linux, BSD
Why OpenOffice?
● Free and open source
● Cross platform – Windows, Mac, Linux, BSD
● Open and standard file format – ODF
Why OpenOffice?
● Free and open source
● Cross platform – Windows, Mac, Linux, BSD
● Open and standard file format – ODF
● Excellent API design
OpenOffice UNO API
OpenOffice UNO API
● Universal Network Object
OpenOffice UNO API
● Universal Network Object
– Universal among programming languages
OpenOffice UNO API
● Universal Network Object
– Universal among programming languages
– Networked API
OpenOffice Object System
OpenOffice ProgramOpenOffice Program
WriterWriter CalcCalc ImpressImpress
ApplicationsApplications
OpenOffice Object System
OpenOffice ProgramOpenOffice Program
WriterWriter CalcCalc ImpressImpress
ComponentsComponents
OpenOffice Object System
OpenOffice DesktopOpenOffice Desktop
Text
Document
Text
Document
Spreadsheet
Document
Spreadsheet
Document
Presentation
Document
Presentation
Document
ComponentsComponents
OpenOffice Object System
OpenOffice DesktopOpenOffice Desktop
Text
Document
Text
Document
Spreadsheet
Document
Spreadsheet
Document
Presentation
Document
Presentation
Document
ParagraphsParagraphs
Text RangesText Ranges
TablesTables
ShapesShapes ……
Text CursorsText Cursors
ComponentsComponents
OpenOffice Object System
OpenOffice DesktopOpenOffice Desktop
Text
Document
Text
Document
Spreadsheet
Document
Spreadsheet
Document
Presentation
Document
Presentation
Document
SpreadsheetsSpreadsheets
Sheet CellsSheet Cells ……Data PilotsData Pilots
Database RangesDatabase Ranges ChartsCharts
ComponentsComponents
OpenOffice Object System
OpenOffice DesktopOpenOffice Desktop
Text
Document
Text
Document
Spreadsheet
Document
Spreadsheet
Document
Presentation
Document
Presentation
Document
Draw PagesDraw Pages
ShapesShapes ……
ChartsChartsPresentationPresentation
Slide Show ControllerSlide Show Controller
OpenOffice UNO API
OpenOfficeOpenOffice
WriterWriter
CalcCalc
Impres
s
Impres
s
UNO
API
UNO
API
……
Language BindingLanguage Binding
OpenOffice UNO API
OpenOfficeOpenOffice
WriterWriter
CalcCalc
Impres
s
Impres
s
UNO
API
UNO
API
……
Language BindingLanguage Binding
OpenOffice UNO API
OpenOfficeOpenOffice
WriterWriter
CalcCalc
Impres
s
Impres
s
UNO
API
UNO
API
C++C++
JavaJava
……
PythonPython
Language BindingLanguage Binding
OpenOffice UNO API
OpenOfficeOpenOffice
WriterWriter
CalcCalc
Impres
s
Impres
s
UNO
API
UNO
API
C++C++
JavaJava
PerlPerl
PythonPython
……
Language BindingLanguage Binding
OpenOffice UNO API
OpenOfficeOpenOffice
WriterWriter
CalcCalc
Impres
s
Impres
s
UNO
API
UNO
API
C++C++
JavaJava
PerlPerl
PythonPython
OLEOLE
CLICLI
COMCOM……
Language BindingLanguage Binding
OpenOffice UNO API
OpenOfficeOpenOffice
WriterWriter
CalcCalc
Impres
s
Impres
s
UNO
API
UNO
API
C++C++
JavaJava
PerlPerl
PythonPython
……
C#C#
VB.NETVB.NET
OLEOLE
CLICLI
COMCOM……
Language BindingLanguage Binding
OpenOffice UNO API
OpenOfficeOpenOffice
WriterWriter
CalcCalc
Impres
s
Impres
s
UNO
API
UNO
API
C++C++
JavaJava
PerlPerl
PythonPython
Almost
Anything!
Almost
Anything!
……
C#C#
VB.NETVB.NET
OLEOLE
CLICLI
COMCOM……
Language BindingLanguage Binding
OpenOffice UNO API
OpenOfficeOpenOffice
WriterWriter
CalcCalc
Impres
s
Impres
s
UNO
API
UNO
API
C++C++
JavaJava
PerlPerl
PythonPython
Almost
Anything!
Almost
Anything!
……
C#C#
VB.NETVB.NET
OLEOLE
CLICLI
COMCOM……
Network
Socket
Network
Socket
Client Application AClient Application A
OpenOffice.org UNO
OpenOffice.orgOpenOffice.org
WriterWriter
CalcCalc
Impres
s
Impres
s
UNO
API
UNO
API
……
C++C++
Client Application AClient Application A
OpenOffice.org UNO
OpenOffice.orgOpenOffice.org
WriterWriter
CalcCalc
Impres
s
Impres
s
UNO
API
UNO
API
……
C++C++
Client Application BClient Application B
JavaJava
Client Application AClient Application A
OpenOffice.org UNO
OpenOffice.orgOpenOffice.org
WriterWriter
CalcCalc
Impres
s
Impres
s
UNO
API
UNO
API
……
C++C++
Client Application BClient Application B
JavaJava
Client Application CClient Application C
PythonPython
Client AClient A
ServerServer Client Application AClient Application A
OpenOffice.org UNO
OpenOffice.orgOpenOffice.org
WriterWriter
CalcCalc
Impres
s
Impres
s
UNO
API
UNO
API
……
C++C++
Client BClient B
Client Application BClient Application B
JavaJava
Client CClient C
Client Application CClient Application C
PythonPython
TCP/IP
Network
TCP/IP
Network
OpenOffice UNO API
● Universal Network Object
– Universal among programming languages
– Networked API
● Write your office application in your
favorite language!
But, which language to use?
Language BindingLanguage Binding
Choosing Language
for UNO Applications
OpenOfficeOpenOffice
WriterWriter
CalcCalc
Impres
s
Impres
s
UNO
API
UNO
API
C++C++
JavaJava
PerlPerl
PythonPython
Almost
Anything!
Almost
Anything!
……
C#C#
VB.NETVB.NET
OLEOLE
CLICLI
COMCOM……
Network
Socket
Network
Socket
Language BindingLanguage Binding
Directly Supported Languages
C++, Java and Python
OpenOfficeOpenOffice
WriterWriter
CalcCalc
Impres
s
Impres
s
UNO
API
UNO
API
C++C++
JavaJava
PerlPerl
PythonPython
Almost
Anything!
Almost
Anything!
……
C#C#
VB.NETVB.NET
OLEOLE
CLICLI
COMCOM……
Network
Socket
Network
Socket
Language BindingLanguage Binding
Dynamic Typed Language
Python
OpenOfficeOpenOffice
WriterWriter
CalcCalc
Impres
s
Impres
s
UNO
API
UNO
API
C++C++
JavaJava
PerlPerl
PythonPython
Almost
Anything!
Almost
Anything!
……
C#C#
VB.NETVB.NET
OLEOLE
CLICLI
COMCOM……
Network
Socket
Network
Socket
Choosing PyUNO
for OpenOffice UNO Applications
● Directly supported by OpenOffice itself
Choosing PyUNO
for OpenOffice UNO Applications
● Directly supported by OpenOffice itself
● Dynamic typing making everything easier
Connecting to OpenOffice
with Java UNO
● XComponentContext localContext = Bootstrap.createInitialComponentContext(null);
● XMultiComponentFactory localServiceManager = localContext.getServiceManager();
● Object unoUrlResolver = localServiceManager.createInstanceWithContext(
● "com.sun.star.bridge.UnoUrlResolver", localContext);
● XUnoUrlResolver xUnoUrlResolver = (XUnoUrlResolver) UnoRuntime.queryInterface(
● XUnoUrlResolver.class, unoUrlResolver);
● Object bootstrapContext = xUnoUrlResolver.resolve(String.format(
● "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext"));
● XComponentContext xBootstrapContext = (XComponentContext) UnoRuntime.queryInterface(
● XComponentContext.class, bootstrapContext);
● XMultiComponentFactory serviceManager = xBootstrapContext.getServiceManager();
● Object desktop = this.serviceManager.createInstanceWithContext(
● "com.sun.star.frame.Desktop", xBootstrapContext);
Connecting to OpenOffice
with PyUNO
● local_context = uno.getComponentContext()
● local_service_manager = local_context.getServiceManager()
● uno_url_resolver = local_service_manager.createInstanceWithContext(
● 'com.sun.star.bridge.UnoUrlResolver', local_context)
● bootstrap_context = uno_url_resolver.resolve(
● 'uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext')
● service_manager = bootstrap_context.getServiceManager()
● desktop = service_manager.createInstanceWithContext(
● 'com.sun.star.frame.Desktop', bootstrap_context)
Connecting to OpenOffice
with Java UNO vs. PyUNO
● // Java UNO
● XComponentContext localContext = …
● XMultiComponentFactory localSM = …
● Object unoUrlResolver = …
● XUnoUrlResolver xUnoUrlResolver = …
● Object bootstrapContext = …
● XComponentContext xBootstrapContext = …
● XMultiComponentFactory serviceManager = …
● Object desktop = …
● # PyUNO
● local_context = uno.getComponentContext()
● local_service_manager = …
● uno_url_resolver = …
●
● bootstrap_context = …
●
● service_manager = …
● desktop = …
Choosing PyUNO
for OpenOffice UNO Applications
● Directly supported by OpenOffice itself
● Dynamic typing making everything easier
– You don't need to obtain an object's type in order
to use it
Choosing PyUNO
for OpenOffice UNO Applications
● Directly supported by OpenOffice itself
● Dynamic typing making everything easier
– You don't need to obtain an object's type in order
to use it
– To read, write and maintain codes become a
lot easier
OpenOffice Python Support
● OpenOffice ship with a Python installation
OpenOffice Python Support
● OpenOffice ship with a Python installation
– Linux: /opt/openoffice4/program/python
OpenOffice Python Support
● OpenOffice ship with a Python installation
– Linux: /opt/openoffice4/program/python
– Windows: "C:Program Files (x86)OpenOffice
4programpython.exe"
OpenOffice Python Support
● OpenOffice ship with a Python installation
– Linux: /opt/openoffice4/program/python
– Windows: "C:Program Files (x86)OpenOffice
4programpython.exe"
– Version 2.7.6 as of OpenOffice 4.1
Simple
Example
Demonstration
● Running OpenOffice as a Server
● Connecting to OpenOffice
● OpenOffice Operation
Running OpenOffice
as a Server
● In Linux
– % /opt/openoffice4/program/soffice.bin 
– "-accept=socket,host=localhost,port=2002;urp;"
● In Windows
– C:>"C:Program Files (x86)OpenOffice 4programsoffice.exe"
– "-accept=socket,host=localhost,port=2002;urp;"
Connecting to OpenOffice
with PyUNO
● % /opt/openoffice4/program/python
● >>> import uno
● >>> local_context = uno.getComponentContext()
● >>> local_service_manager = local_context.getServiceManager()
● >>> uno_url_resolver = local_service_manager.createInstanceWithContext(
● ... 'com.sun.star.bridge.UnoUrlResolver', local_context)
● >>> bootstrap_context = uno_url_resolver.resolve(
● ... 'uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext')
● >>> service_manager = bootstrap_context.getServiceManager()
● >>> desktop = service_manager.createInstanceWithContext(
● ... 'com.sun.star.frame.Desktop', bootstrap_context)
● >>>
Checking the desktop Object
● >>> dir(desktop)
● ['ActiveFrame', 'ActiveTask',
'ComponentWindow', 'Components',
'ContainerWindow', 'Controller',
'Creator', 'CurrentComponent',
'CurrentFrame', …]
● >>>
Checking the Current Document
● >>> doc = desktop.CurrentComponent
● >>> dir(doc)
● ['ActionLocks', 'AllowMacroExecution',
'ApplyFormDesignMode', 'AreaLinks',
'Args', 'AutomaticControlFocus',
'AvailableServiceNames',
'AvailableViewControllerNames', …]
● >>>
Checking the Spreadsheets
● >>> sheets = doc.Sheets
● >>> dir(sheets)
● ['Count', 'ElementNames',
'ElementType', 'ImplementationId',
'ImplementationName',
'SupportedServiceNames', 'Types',
'copyByName', 'createEnumeration',
'getByIndex', 'getByName', …]
● >>>
Checking the First Sheet
● >>> sheet = sheets.getByIndex(0)
● >>> dir(sheet)
● ['AbsoluteName', 'Annotations',
'ArrayFormula', 'ArrayTokens',
'AsianVerticalMode',
'AutomaticPrintArea',
'BorderColor', 'BottomBorder',
'CellBackColor',
'CellFormatRanges', …]
● >>>
Checking A1
● >>> cell = sheet.getCellRangeByName('A1')
● >>> dir(cell)
● ['AbsoluteName', 'ActionLocks',
'Annotation', 'ArrayFormula',
'ArrayTokens', 'AsianVerticalMode',
'BottomBorder', 'CellAddress',
'CellBackColor', …]
● >>>
Updating A1
● >>> cell.CellBackColor = 0xFF0000
● >>> cell.String = 'Hello, world!'
● >>>
Updating A1, A2 and A3
● >>> sheet.getCellRangeByName('A1').String = 'Betty'
● >>> sheet.getCellRangeByName('A2').Value = 1630
● >>> sheet.getCellRangeByName('A3').Formula = '=A2*6'
● >>>
Creating a Multiplication Table
● >>> for i in range(1, 10):
● ... for j in range(1, 10):
● ... sheet.getCellByPosition(i-1, j-1).Value = i*j
● ...
● >>>
Writing Your Own UNO Application
is Easy!
Thank you.
Any questions?

More Related Content

What's hot

What's hot (20)

Elixir intro
Elixir introElixir intro
Elixir intro
 
Let's Graph
Let's GraphLet's Graph
Let's Graph
 
Relay: Seamless Syncing for React (VanJS)
Relay: Seamless Syncing for React (VanJS)Relay: Seamless Syncing for React (VanJS)
Relay: Seamless Syncing for React (VanJS)
 
Up and Running with the Typelevel Stack
Up and Running with the Typelevel StackUp and Running with the Typelevel Stack
Up and Running with the Typelevel Stack
 
I18nize Scala programs à la gettext
I18nize Scala programs à la gettextI18nize Scala programs à la gettext
I18nize Scala programs à la gettext
 
The future of templating and frameworks
The future of templating and frameworksThe future of templating and frameworks
The future of templating and frameworks
 
Golang #5: To Go or not to Go
Golang #5: To Go or not to GoGolang #5: To Go or not to Go
Golang #5: To Go or not to Go
 
RubyConf Taiwan 2016 - Large scale Rails applications
RubyConf Taiwan 2016 - Large scale Rails applicationsRubyConf Taiwan 2016 - Large scale Rails applications
RubyConf Taiwan 2016 - Large scale Rails applications
 
Functional Programming in Clojure
Functional Programming in ClojureFunctional Programming in Clojure
Functional Programming in Clojure
 
F# type providers
F# type providersF# type providers
F# type providers
 
Break Free with Managed Functional Programming: An Introduction to F#
Break Free with Managed Functional Programming: An Introduction to F#Break Free with Managed Functional Programming: An Introduction to F#
Break Free with Managed Functional Programming: An Introduction to F#
 
Break Free with Managed Functional Programming: An Introduction to F#
Break Free with Managed Functional Programming: An Introduction to F#Break Free with Managed Functional Programming: An Introduction to F#
Break Free with Managed Functional Programming: An Introduction to F#
 
Future of Kotlin - How agile can language development be?
Future of Kotlin - How agile can language development be?Future of Kotlin - How agile can language development be?
Future of Kotlin - How agile can language development be?
 
Fast Web Applications with Go
Fast Web Applications with Go Fast Web Applications with Go
Fast Web Applications with Go
 
LogiLogicless UI prototyping with Node.js | SuperSpeaker@CodeCamp Iasi, 2014
LogiLogicless UI prototyping with Node.js | SuperSpeaker@CodeCamp Iasi, 2014LogiLogicless UI prototyping with Node.js | SuperSpeaker@CodeCamp Iasi, 2014
LogiLogicless UI prototyping with Node.js | SuperSpeaker@CodeCamp Iasi, 2014
 
Whats next in templating
Whats next in templatingWhats next in templating
Whats next in templating
 
Java to scala
Java to scalaJava to scala
Java to scala
 
Functional js class
Functional js classFunctional js class
Functional js class
 
Bringing TensorFlow to Android - a War Story
Bringing TensorFlow to Android - a War StoryBringing TensorFlow to Android - a War Story
Bringing TensorFlow to Android - a War Story
 
Play! with rest
Play! with restPlay! with rest
Play! with rest
 

Viewers also liked

Kaila presentation
Kaila presentationKaila presentation
Kaila presentation
ifcaonline
 
Presentation version strategic 2 map 08 30-11
Presentation version strategic 2 map 08 30-11Presentation version strategic 2 map 08 30-11
Presentation version strategic 2 map 08 30-11
Brandon Williams
 
2011 covoad conference present
2011 covoad conference present2011 covoad conference present
2011 covoad conference present
Brandon Williams
 
Hindi presentation ayush saklani
Hindi presentation ayush saklaniHindi presentation ayush saklani
Hindi presentation ayush saklani
Ayush Saklani
 

Viewers also liked (20)

Anja Enggaard - Call Me og tal ordentligt
Anja Enggaard - Call Me og tal ordentligtAnja Enggaard - Call Me og tal ordentligt
Anja Enggaard - Call Me og tal ordentligt
 
Lead Management in SugarCRM Series: Lead Routing with Workflows
Lead Management in SugarCRM Series: Lead Routing with WorkflowsLead Management in SugarCRM Series: Lead Routing with Workflows
Lead Management in SugarCRM Series: Lead Routing with Workflows
 
Kaila presentation
Kaila presentationKaila presentation
Kaila presentation
 
Vitus Vestergaard, Samarbejder mellem museer og universiteter
Vitus Vestergaard, Samarbejder mellem museer og universiteterVitus Vestergaard, Samarbejder mellem museer og universiteter
Vitus Vestergaard, Samarbejder mellem museer og universiteter
 
Axel Johnsen, Det er meget nemmere med kopier og private samlinger! Et nødråb...
Axel Johnsen, Det er meget nemmere med kopier og private samlinger! Et nødråb...Axel Johnsen, Det er meget nemmere med kopier og private samlinger! Et nødråb...
Axel Johnsen, Det er meget nemmere med kopier og private samlinger! Et nødråb...
 
Final presentation
Final presentationFinal presentation
Final presentation
 
Presentation version strategic 2 map 08 30-11
Presentation version strategic 2 map 08 30-11Presentation version strategic 2 map 08 30-11
Presentation version strategic 2 map 08 30-11
 
Mosaic Fun with OpenOffice Calc
Mosaic Fun with OpenOffice CalcMosaic Fun with OpenOffice Calc
Mosaic Fun with OpenOffice Calc
 
Arne Kvorning - Horsens Statsfængsel
Arne Kvorning  - Horsens StatsfængselArne Kvorning  - Horsens Statsfængsel
Arne Kvorning - Horsens Statsfængsel
 
Morten Søvsø - grave og bebyggelse i emporiet ribe
Morten Søvsø - grave og bebyggelse i emporiet ribeMorten Søvsø - grave og bebyggelse i emporiet ribe
Morten Søvsø - grave og bebyggelse i emporiet ribe
 
10x7 09 Odense Bysmuseer Ellen Warring
10x7 09 Odense Bysmuseer Ellen Warring10x7 09 Odense Bysmuseer Ellen Warring
10x7 09 Odense Bysmuseer Ellen Warring
 
Anni Mogensen - Opløs skellet mellem sær- og permanente udstillinger
Anni Mogensen  - Opløs skellet mellem sær- og permanente udstillingerAnni Mogensen  - Opløs skellet mellem sær- og permanente udstillinger
Anni Mogensen - Opløs skellet mellem sær- og permanente udstillinger
 
Per Ethelberg Danmarks laengste soegegroeft
Per Ethelberg Danmarks laengste soegegroeftPer Ethelberg Danmarks laengste soegegroeft
Per Ethelberg Danmarks laengste soegegroeft
 
2011 covoad conference present
2011 covoad conference present2011 covoad conference present
2011 covoad conference present
 
Svend Illum Hansen
Svend Illum HansenSvend Illum Hansen
Svend Illum Hansen
 
3 Lars Jørgensen, KUM Forskningsudvalg
3 Lars Jørgensen, KUM Forskningsudvalg3 Lars Jørgensen, KUM Forskningsudvalg
3 Lars Jørgensen, KUM Forskningsudvalg
 
15 charlotte bh_andersen_hillerslev i thy
15 charlotte bh_andersen_hillerslev i thy15 charlotte bh_andersen_hillerslev i thy
15 charlotte bh_andersen_hillerslev i thy
 
Hindi presentation ayush saklani
Hindi presentation ayush saklaniHindi presentation ayush saklani
Hindi presentation ayush saklani
 
Charlie Christensen noerrekaer
Charlie Christensen noerrekaerCharlie Christensen noerrekaer
Charlie Christensen noerrekaer
 
Katja Niere - gradueret konservering
Katja Niere -  gradueret konserveringKatja Niere -  gradueret konservering
Katja Niere - gradueret konservering
 

Similar to OpenOffice Application with Python

Introduction to Django (GDays 2014)
Introduction to Django (GDays 2014) Introduction to Django (GDays 2014)
Introduction to Django (GDays 2014)
Edem Kumodzi
 

Similar to OpenOffice Application with Python (20)

OpenOffice UNO Application on Android
OpenOffice UNO Application on AndroidOpenOffice UNO Application on Android
OpenOffice UNO Application on Android
 
CocoaConf DC - Automate with Swift - Tony Ingraldi
CocoaConf DC -  Automate with Swift - Tony IngraldiCocoaConf DC -  Automate with Swift - Tony Ingraldi
CocoaConf DC - Automate with Swift - Tony Ingraldi
 
Pyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdfPyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdf
 
COMPUTER LANGUAGES AND THERE DIFFERENCE
COMPUTER LANGUAGES AND THERE DIFFERENCE COMPUTER LANGUAGES AND THERE DIFFERENCE
COMPUTER LANGUAGES AND THERE DIFFERENCE
 
Introduction python
Introduction pythonIntroduction python
Introduction python
 
Python tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academyPython tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academy
 
Python Tutorial | Python Programming Language
Python Tutorial | Python Programming LanguagePython Tutorial | Python Programming Language
Python Tutorial | Python Programming Language
 
Symfony4: A new way to develop applications | Antonio Peric | CODEiD
Symfony4: A new way to develop applications | Antonio Peric | CODEiDSymfony4: A new way to develop applications | Antonio Peric | CODEiD
Symfony4: A new way to develop applications | Antonio Peric | CODEiD
 
Introduction to Django (GDays 2014)
Introduction to Django (GDays 2014) Introduction to Django (GDays 2014)
Introduction to Django (GDays 2014)
 
A quick overview of why to use and how to set up iPython notebooks for research
A quick overview of why to use and how to set up iPython notebooks for researchA quick overview of why to use and how to set up iPython notebooks for research
A quick overview of why to use and how to set up iPython notebooks for research
 
Introduction to python for Beginners
Introduction to python for Beginners Introduction to python for Beginners
Introduction to python for Beginners
 
Introduction to Python Programing
Introduction to Python ProgramingIntroduction to Python Programing
Introduction to Python Programing
 
Research paper on python by Rj
Research paper on python by RjResearch paper on python by Rj
Research paper on python by Rj
 
Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)
 
Beginning python programming
Beginning python programmingBeginning python programming
Beginning python programming
 
Java vs Python: Comparison, Features & Applications
Java vs Python: Comparison, Features & ApplicationsJava vs Python: Comparison, Features & Applications
Java vs Python: Comparison, Features & Applications
 
Introduction To Python
Introduction To PythonIntroduction To Python
Introduction To Python
 
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPCBuild Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPC
 
Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!
 
Phython Programming Language
Phython Programming LanguagePhython Programming Language
Phython Programming Language
 

More from imacat .

Welcome to Apache OpenOffice 3.4
Welcome to Apache OpenOffice 3.4Welcome to Apache OpenOffice 3.4
Welcome to Apache OpenOffice 3.4
imacat .
 

More from imacat . (20)

A Room of WikiWomen's Own
A Room of WikiWomen's OwnA Room of WikiWomen's Own
A Room of WikiWomen's Own
 
Office寶可夢GO IV計算機
Office寶可夢GO IV計算機Office寶可夢GO IV計算機
Office寶可夢GO IV計算機
 
從doc、docx、odt到Google Docs
從doc、docx、odt到Google Docs從doc、docx、odt到Google Docs
從doc、docx、odt到Google Docs
 
More Girls – Creating a Community of Diversity
More Girls – Creating a Community of DiversityMore Girls – Creating a Community of Diversity
More Girls – Creating a Community of Diversity
 
OpenOffice, Open Business
OpenOffice, Open BusinessOpenOffice, Open Business
OpenOffice, Open Business
 
Multimedia Fun with OpenOffice Calc
Multimedia Fun with OpenOffice CalcMultimedia Fun with OpenOffice Calc
Multimedia Fun with OpenOffice Calc
 
Welcome to Apache OpenOffice 3.4 COSCUP 2012
Welcome to Apache OpenOffice 3.4 COSCUP 2012Welcome to Apache OpenOffice 3.4 COSCUP 2012
Welcome to Apache OpenOffice 3.4 COSCUP 2012
 
GNU Autoconf / Automake #4
GNU Autoconf / Automake #4GNU Autoconf / Automake #4
GNU Autoconf / Automake #4
 
GNU Autoconf / Automake #1
GNU Autoconf / Automake #1GNU Autoconf / Automake #1
GNU Autoconf / Automake #1
 
Solitaire with Greenfoot #3
Solitaire with Greenfoot #3Solitaire with Greenfoot #3
Solitaire with Greenfoot #3
 
Solitaire with Greenfoot #1
Solitaire with Greenfoot #1Solitaire with Greenfoot #1
Solitaire with Greenfoot #1
 
Solitaire with Greenfoot #4
Solitaire with Greenfoot #4Solitaire with Greenfoot #4
Solitaire with Greenfoot #4
 
Solitaire with Greenfoot #2
Solitaire with Greenfoot #2Solitaire with Greenfoot #2
Solitaire with Greenfoot #2
 
Solitaire with Greenfoot #2/4
Solitaire with Greenfoot #2/4Solitaire with Greenfoot #2/4
Solitaire with Greenfoot #2/4
 
Object-Oriented Programming Design with Greenfoot 02
Object-Oriented Programming Design with Greenfoot 02Object-Oriented Programming Design with Greenfoot 02
Object-Oriented Programming Design with Greenfoot 02
 
Object-Oriented Programming Design with Greenfoot 01
Object-Oriented Programming Design with Greenfoot 01Object-Oriented Programming Design with Greenfoot 01
Object-Oriented Programming Design with Greenfoot 01
 
Welcome to Apache OpenOffice 3.4
Welcome to Apache OpenOffice 3.4Welcome to Apache OpenOffice 3.4
Welcome to Apache OpenOffice 3.4
 
OpenOffice.org Magic Sandbox
OpenOffice.org Magic SandboxOpenOffice.org Magic Sandbox
OpenOffice.org Magic Sandbox
 
Mailing Lists and IRC
Mailing Lists and IRCMailing Lists and IRC
Mailing Lists and IRC
 
GNU Build System
GNU Build SystemGNU Build System
GNU Build System
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 

OpenOffice Application with Python

  • 2. “OpenOffice Application with Python” is created by imacat (Yang Shih-Ching), and licensed under a Creative Commons Attribution 3.0 Unported License.
  • 3. imacat ● A member of the Apache OpenOffice Project Management Committee ● An OpenOffice committer ● The system administrator of the OpenOffice forum and Wiki ● A PyLadies Taiwan organizer ● Graduated from National Taiwan Normal University
  • 5. Why OpenOffice? ● Free and open source
  • 6. Why OpenOffice? ● Free and open source ● Cross platform – Windows, Mac, Linux, BSD
  • 7. Why OpenOffice? ● Free and open source ● Cross platform – Windows, Mac, Linux, BSD ● Open and standard file format – ODF
  • 8. Why OpenOffice? ● Free and open source ● Cross platform – Windows, Mac, Linux, BSD ● Open and standard file format – ODF ● Excellent API design
  • 10. OpenOffice UNO API ● Universal Network Object
  • 11. OpenOffice UNO API ● Universal Network Object – Universal among programming languages
  • 12. OpenOffice UNO API ● Universal Network Object – Universal among programming languages – Networked API
  • 13. OpenOffice Object System OpenOffice ProgramOpenOffice Program WriterWriter CalcCalc ImpressImpress
  • 14. ApplicationsApplications OpenOffice Object System OpenOffice ProgramOpenOffice Program WriterWriter CalcCalc ImpressImpress
  • 15. ComponentsComponents OpenOffice Object System OpenOffice DesktopOpenOffice Desktop Text Document Text Document Spreadsheet Document Spreadsheet Document Presentation Document Presentation Document
  • 16. ComponentsComponents OpenOffice Object System OpenOffice DesktopOpenOffice Desktop Text Document Text Document Spreadsheet Document Spreadsheet Document Presentation Document Presentation Document ParagraphsParagraphs Text RangesText Ranges TablesTables ShapesShapes …… Text CursorsText Cursors
  • 17. ComponentsComponents OpenOffice Object System OpenOffice DesktopOpenOffice Desktop Text Document Text Document Spreadsheet Document Spreadsheet Document Presentation Document Presentation Document SpreadsheetsSpreadsheets Sheet CellsSheet Cells ……Data PilotsData Pilots Database RangesDatabase Ranges ChartsCharts
  • 18. ComponentsComponents OpenOffice Object System OpenOffice DesktopOpenOffice Desktop Text Document Text Document Spreadsheet Document Spreadsheet Document Presentation Document Presentation Document Draw PagesDraw Pages ShapesShapes …… ChartsChartsPresentationPresentation Slide Show ControllerSlide Show Controller
  • 20. Language BindingLanguage Binding OpenOffice UNO API OpenOfficeOpenOffice WriterWriter CalcCalc Impres s Impres s UNO API UNO API ……
  • 21. Language BindingLanguage Binding OpenOffice UNO API OpenOfficeOpenOffice WriterWriter CalcCalc Impres s Impres s UNO API UNO API C++C++ JavaJava …… PythonPython
  • 22. Language BindingLanguage Binding OpenOffice UNO API OpenOfficeOpenOffice WriterWriter CalcCalc Impres s Impres s UNO API UNO API C++C++ JavaJava PerlPerl PythonPython ……
  • 23. Language BindingLanguage Binding OpenOffice UNO API OpenOfficeOpenOffice WriterWriter CalcCalc Impres s Impres s UNO API UNO API C++C++ JavaJava PerlPerl PythonPython OLEOLE CLICLI COMCOM……
  • 24. Language BindingLanguage Binding OpenOffice UNO API OpenOfficeOpenOffice WriterWriter CalcCalc Impres s Impres s UNO API UNO API C++C++ JavaJava PerlPerl PythonPython …… C#C# VB.NETVB.NET OLEOLE CLICLI COMCOM……
  • 25. Language BindingLanguage Binding OpenOffice UNO API OpenOfficeOpenOffice WriterWriter CalcCalc Impres s Impres s UNO API UNO API C++C++ JavaJava PerlPerl PythonPython Almost Anything! Almost Anything! …… C#C# VB.NETVB.NET OLEOLE CLICLI COMCOM……
  • 26. Language BindingLanguage Binding OpenOffice UNO API OpenOfficeOpenOffice WriterWriter CalcCalc Impres s Impres s UNO API UNO API C++C++ JavaJava PerlPerl PythonPython Almost Anything! Almost Anything! …… C#C# VB.NETVB.NET OLEOLE CLICLI COMCOM…… Network Socket Network Socket
  • 27. Client Application AClient Application A OpenOffice.org UNO OpenOffice.orgOpenOffice.org WriterWriter CalcCalc Impres s Impres s UNO API UNO API …… C++C++
  • 28. Client Application AClient Application A OpenOffice.org UNO OpenOffice.orgOpenOffice.org WriterWriter CalcCalc Impres s Impres s UNO API UNO API …… C++C++ Client Application BClient Application B JavaJava
  • 29. Client Application AClient Application A OpenOffice.org UNO OpenOffice.orgOpenOffice.org WriterWriter CalcCalc Impres s Impres s UNO API UNO API …… C++C++ Client Application BClient Application B JavaJava Client Application CClient Application C PythonPython
  • 30. Client AClient A ServerServer Client Application AClient Application A OpenOffice.org UNO OpenOffice.orgOpenOffice.org WriterWriter CalcCalc Impres s Impres s UNO API UNO API …… C++C++ Client BClient B Client Application BClient Application B JavaJava Client CClient C Client Application CClient Application C PythonPython TCP/IP Network TCP/IP Network
  • 31. OpenOffice UNO API ● Universal Network Object – Universal among programming languages – Networked API ● Write your office application in your favorite language!
  • 33. Language BindingLanguage Binding Choosing Language for UNO Applications OpenOfficeOpenOffice WriterWriter CalcCalc Impres s Impres s UNO API UNO API C++C++ JavaJava PerlPerl PythonPython Almost Anything! Almost Anything! …… C#C# VB.NETVB.NET OLEOLE CLICLI COMCOM…… Network Socket Network Socket
  • 34. Language BindingLanguage Binding Directly Supported Languages C++, Java and Python OpenOfficeOpenOffice WriterWriter CalcCalc Impres s Impres s UNO API UNO API C++C++ JavaJava PerlPerl PythonPython Almost Anything! Almost Anything! …… C#C# VB.NETVB.NET OLEOLE CLICLI COMCOM…… Network Socket Network Socket
  • 35. Language BindingLanguage Binding Dynamic Typed Language Python OpenOfficeOpenOffice WriterWriter CalcCalc Impres s Impres s UNO API UNO API C++C++ JavaJava PerlPerl PythonPython Almost Anything! Almost Anything! …… C#C# VB.NETVB.NET OLEOLE CLICLI COMCOM…… Network Socket Network Socket
  • 36. Choosing PyUNO for OpenOffice UNO Applications ● Directly supported by OpenOffice itself
  • 37. Choosing PyUNO for OpenOffice UNO Applications ● Directly supported by OpenOffice itself ● Dynamic typing making everything easier
  • 38. Connecting to OpenOffice with Java UNO ● XComponentContext localContext = Bootstrap.createInitialComponentContext(null); ● XMultiComponentFactory localServiceManager = localContext.getServiceManager(); ● Object unoUrlResolver = localServiceManager.createInstanceWithContext( ● "com.sun.star.bridge.UnoUrlResolver", localContext); ● XUnoUrlResolver xUnoUrlResolver = (XUnoUrlResolver) UnoRuntime.queryInterface( ● XUnoUrlResolver.class, unoUrlResolver); ● Object bootstrapContext = xUnoUrlResolver.resolve(String.format( ● "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")); ● XComponentContext xBootstrapContext = (XComponentContext) UnoRuntime.queryInterface( ● XComponentContext.class, bootstrapContext); ● XMultiComponentFactory serviceManager = xBootstrapContext.getServiceManager(); ● Object desktop = this.serviceManager.createInstanceWithContext( ● "com.sun.star.frame.Desktop", xBootstrapContext);
  • 39. Connecting to OpenOffice with PyUNO ● local_context = uno.getComponentContext() ● local_service_manager = local_context.getServiceManager() ● uno_url_resolver = local_service_manager.createInstanceWithContext( ● 'com.sun.star.bridge.UnoUrlResolver', local_context) ● bootstrap_context = uno_url_resolver.resolve( ● 'uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext') ● service_manager = bootstrap_context.getServiceManager() ● desktop = service_manager.createInstanceWithContext( ● 'com.sun.star.frame.Desktop', bootstrap_context)
  • 40. Connecting to OpenOffice with Java UNO vs. PyUNO ● // Java UNO ● XComponentContext localContext = … ● XMultiComponentFactory localSM = … ● Object unoUrlResolver = … ● XUnoUrlResolver xUnoUrlResolver = … ● Object bootstrapContext = … ● XComponentContext xBootstrapContext = … ● XMultiComponentFactory serviceManager = … ● Object desktop = … ● # PyUNO ● local_context = uno.getComponentContext() ● local_service_manager = … ● uno_url_resolver = … ● ● bootstrap_context = … ● ● service_manager = … ● desktop = …
  • 41. Choosing PyUNO for OpenOffice UNO Applications ● Directly supported by OpenOffice itself ● Dynamic typing making everything easier – You don't need to obtain an object's type in order to use it
  • 42. Choosing PyUNO for OpenOffice UNO Applications ● Directly supported by OpenOffice itself ● Dynamic typing making everything easier – You don't need to obtain an object's type in order to use it – To read, write and maintain codes become a lot easier
  • 43. OpenOffice Python Support ● OpenOffice ship with a Python installation
  • 44. OpenOffice Python Support ● OpenOffice ship with a Python installation – Linux: /opt/openoffice4/program/python
  • 45. OpenOffice Python Support ● OpenOffice ship with a Python installation – Linux: /opt/openoffice4/program/python – Windows: "C:Program Files (x86)OpenOffice 4programpython.exe"
  • 46. OpenOffice Python Support ● OpenOffice ship with a Python installation – Linux: /opt/openoffice4/program/python – Windows: "C:Program Files (x86)OpenOffice 4programpython.exe" – Version 2.7.6 as of OpenOffice 4.1
  • 48. Demonstration ● Running OpenOffice as a Server ● Connecting to OpenOffice ● OpenOffice Operation
  • 49. Running OpenOffice as a Server ● In Linux – % /opt/openoffice4/program/soffice.bin – "-accept=socket,host=localhost,port=2002;urp;" ● In Windows – C:>"C:Program Files (x86)OpenOffice 4programsoffice.exe" – "-accept=socket,host=localhost,port=2002;urp;"
  • 50. Connecting to OpenOffice with PyUNO ● % /opt/openoffice4/program/python ● >>> import uno ● >>> local_context = uno.getComponentContext() ● >>> local_service_manager = local_context.getServiceManager() ● >>> uno_url_resolver = local_service_manager.createInstanceWithContext( ● ... 'com.sun.star.bridge.UnoUrlResolver', local_context) ● >>> bootstrap_context = uno_url_resolver.resolve( ● ... 'uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext') ● >>> service_manager = bootstrap_context.getServiceManager() ● >>> desktop = service_manager.createInstanceWithContext( ● ... 'com.sun.star.frame.Desktop', bootstrap_context) ● >>>
  • 51. Checking the desktop Object ● >>> dir(desktop) ● ['ActiveFrame', 'ActiveTask', 'ComponentWindow', 'Components', 'ContainerWindow', 'Controller', 'Creator', 'CurrentComponent', 'CurrentFrame', …] ● >>>
  • 52. Checking the Current Document ● >>> doc = desktop.CurrentComponent ● >>> dir(doc) ● ['ActionLocks', 'AllowMacroExecution', 'ApplyFormDesignMode', 'AreaLinks', 'Args', 'AutomaticControlFocus', 'AvailableServiceNames', 'AvailableViewControllerNames', …] ● >>>
  • 53. Checking the Spreadsheets ● >>> sheets = doc.Sheets ● >>> dir(sheets) ● ['Count', 'ElementNames', 'ElementType', 'ImplementationId', 'ImplementationName', 'SupportedServiceNames', 'Types', 'copyByName', 'createEnumeration', 'getByIndex', 'getByName', …] ● >>>
  • 54. Checking the First Sheet ● >>> sheet = sheets.getByIndex(0) ● >>> dir(sheet) ● ['AbsoluteName', 'Annotations', 'ArrayFormula', 'ArrayTokens', 'AsianVerticalMode', 'AutomaticPrintArea', 'BorderColor', 'BottomBorder', 'CellBackColor', 'CellFormatRanges', …] ● >>>
  • 55. Checking A1 ● >>> cell = sheet.getCellRangeByName('A1') ● >>> dir(cell) ● ['AbsoluteName', 'ActionLocks', 'Annotation', 'ArrayFormula', 'ArrayTokens', 'AsianVerticalMode', 'BottomBorder', 'CellAddress', 'CellBackColor', …] ● >>>
  • 56. Updating A1 ● >>> cell.CellBackColor = 0xFF0000 ● >>> cell.String = 'Hello, world!' ● >>>
  • 57. Updating A1, A2 and A3 ● >>> sheet.getCellRangeByName('A1').String = 'Betty' ● >>> sheet.getCellRangeByName('A2').Value = 1630 ● >>> sheet.getCellRangeByName('A3').Formula = '=A2*6' ● >>>
  • 58. Creating a Multiplication Table ● >>> for i in range(1, 10): ● ... for j in range(1, 10): ● ... sheet.getCellByPosition(i-1, j-1).Value = i*j ● ... ● >>>
  • 59. Writing Your Own UNO Application is Easy!