OpenOffice.orgã®ãã¯ããPythonã§è¨è¿°ãã¦åãã(æ¦è¦,ãã¡ã¤ã«é ç½®,ãã¤ã¢ãã°ã®è¡¨ç¤º)
OpenOffice.orgã«ã¯å°ç¨ã®ãOpenOffice.org Basicãã¨ããè¨èªãããããã¯ããè¨é²ããã¨ãã«ã¯ãã®è¨èªã§æ¸ãåºãããã®ã ãããã¯ãã¯Pythonã§è¨è¿°ãããã¨ãã§ããã
ããã§ã¯ãå¿
è¦ãªããã±ã¼ã¸,ã¹ã¯ãªããã®é
ç½®,ç°¡åãªãã¤ã¢ãã°ã®è¡¨ç¤ºã¾ã§ãæ±ãã
å¿ è¦ãªããã±ã¼ã¸
ããã§ã¯ãã£ã¹ããªãããã±ã¼ã¸ã¨ãã¦ç¨æããOpenOffice.orgã«ã¤ãã¦ãæ±ããæ¬å®¶(www.openoffice.org)çã§ã¯ãªãGo-oo(go-oo.org)çãç¨ãããã¦ãããã£ã¹ããªãå¤ãã
Pythonã®ãã¯ããOpenOffice.orgã§ç¨ããã«ã¯ãã®ä»²ç«ã¡*1ãããã½ããã¦ã§ã¢(ããªãã¸)ã®ããã±ã¼ã¸(Python-UNO*2ãããã¯Py-UNOã¨å¼ã°ãã)ãå¥ã«ã¤ã³ã¹ãã¼ã«ããå¿
è¦ããããããã±ã¼ã¸åã¯ãã£ã¹ããªã«ãã£ã¦ç°ãªããããpython(py)ããunoããopenoffice.org(ooo)ãã¨ãã£ãåèªãé¢ä¿ãã¦ããã
- Mandriva Linuxã§ã¯ãopenoffice.org-pyunoã
- Debian/Ubuntuã§ã¯ãpython-unoã
æ¬å®¶çã®ããã±ã¼ã¸ã§ã¯å¹¾ã¤ãããã±ã¼ã¸ãåããã¦ããä¸ã®1ã¤ã¨ãã¦Python-UNOã®ããã±ã¼ã¸ããããPythonæ¬ä½ãããã«å梱ãããå½¢ã¨ãªã£ã¦ãã(ã·ã¹ãã ã®Pythonã¯ç¨ããããªã)ãWindowsçã§ãPythonã¯åãããã«ãã¦ä»å±ããããã (æªç¢ºèª)ãOpenOffice.orgã®ãã¼ã¸ã§ã³3.2ç³»ã®æç¹ã§ã¯ä»å±ããPythonã®ãã¼ã¸ã§ã³ã¯2.6ç³»ã¨ãªã£ã¦ããã
ã¹ã¯ãªããã®é ç½®
${HOME}/[OOoã®ã¦ã¼ã¶ãã£ã¬ã¯ããª]/user/Scripts/ãã£ã¬ã¯ããªã®ä¸ã«pythonã¨ãããã£ã¬ã¯ããªãä½æãããã®ä¸ã«ã¹ã¯ãªãããé
ç½®ãããå®è¡å±æ§ã¯ä¸è¦ã
ã¦ã¼ã¶ãã£ã¬ã¯ããªã®ååã¯ä½¿ç¨ãã¦ããOpenOffice.orgã«ãã£ã¦ç°ãªãå ´åããããMandriva Linux 2010.0ã®Go-ooçã®å ´åãã¹ã¯ãªããã®é
ç½®å ´æã¯${HOME}/.ooo3/user/Scripts/python/[ã¹ã¯ãªãã].pyã®ããã«ãªã£ã¦ãããã¦ã¼ã¶ãã£ã¬ã¯ããªã¯èªåçã«ä½æãããã®ã§ãé ããã¡ã¤ã«/ãã£ã¬ã¯ããªã表示ããããã«ãã¦èªåã®ãã¼ã ãã£ã¬ã¯ããªãè¦ãã°ã©ãã«å
¥ããã°ããããåããã
ç°¡åãªä¾
ã¾ãã¯ä¸ã®å
容ã®ã¹ã¯ãªãããä¸ã®ãã£ã¬ã¯ããªã«é
ç½®ããã
[ä»»æ]ãã¡ã¤ã«å: [OOoã¦ã¼ã¶ãã£ã¬ã¯ããª]/user/Scripts/python/hello.py
# -*- mode: python; coding: utf-8 -*- import uno #import unohelper # ãã®ã³ã¼ãã§ã¯æªä½¿ç¨ class Bridge(object): """ Pythonã¨OOoã®ä»²ç«ã¡ãããå種ãªãã¸ã§ã¯ã㨠ãããç¨ããå¹¾ã¤ãã®æä½ãæä¾ """ def __init__(self): """ å種ãªãã¸ã§ã¯ãã®åå¾ """ # http://api.openoffice.org/docs/common/ref/com/sun/star/script/provider/XScriptContext.html # http://api.openoffice.org/docs/common/ref/com/sun/star/uno/XComponentContext.html self._context = XSCRIPTCONTEXT.getComponentContext() # self._manager = self._context.ServiceManager # ãã®ã³ã¼ãã§ã¯æªä½¿ç¨ self._desktop = XSCRIPTCONTEXT.getDesktop() # self._document = XSCRIPTCONTEXT.getDocument() # ãã®ã³ã¼ãã§ã¯æªä½¿ç¨ # http://api.openoffice.org/docs/common/ref/com/sun/star/frame/XDesktop.html self._frame = self._desktop.CurrentFrame # http://api.openoffice.org/docs/common/ref/com/sun/star/frame/XFrame.html self._window = self._frame.ContainerWindow self._toolkit = self._window.Toolkit def run_infodialog(self, title='', message=''): """ æ å ±ãã¤ã¢ãã°ã表示ãã http://api.openoffice.org/docs/common/ref/com/sun/star/awt/XMessageBoxFactory.html http://hermione.s41.xrea.com/pukiwiki/pukiwiki.php?OOoPython%2FOverView """ msgbox = self._toolkit.createMessageBox(self._window, uno.createUnoStruct('com.sun.star.awt.Rectangle'), # ãã¤ã¢ãã°ã®ç¨®é¡ãæå®ããæåå # infobox,warningbox,errorbox, # querybox,messboxã®ãããã 'infobox', 1, title, message) msgbox.execute() msgbox.dispose() def hello(): """ ããã«è¨è¿°ããæååããã¯ãé¸æãã¤ã¢ãã°ãã説æã¨ãã¦è¡¨ç¤ºããã """ # ãã¯ãã¨ãã¦ã®å¦çã¯é¢æ°ã®å é ããå§ã¾ã pyuno = Bridge() pyuno.run_infodialog(title='Test ãã¹ã', message='Python UNO Test\nãã¤ã½ã³ ã¦ã¼ã㦠ãã¹ã') # ãã®ã¿ãã«ã«ååãæ¸ããé¢æ°ã®ã¿ãã¯ãé¸æãã¤ã¢ãã°ããå®è¡ã§ãã # g_exportedScriptsãè¨è¿°ããªãå ´åã¯å ¨ã¦å®è¡å¯ g_exportedScripts = (hello,)
ãã®å¾ã¡ãã¥ã¼ããã¼ã« - ãã¯ã - ãã¯ããå®è¡ãã§ãã©ã¤ãã©ãª - ãã¤ãã¯ã - [ãã¡ã¤ã«å]ããé¸æããã¨å³ã«ãhelloããåºãã®ã§ãããé¸æãããå®è¡ããæ¼ãã
ããã¨
ãã®ãããªãã¤ã¢ãã°ãåºããã¢ã¤ã³ã³ã¯ã¢ã¤ã³ã³ãã¼ãã®è¨å®ã«ãã£ã¦ç°ãªãã
(2010/3/15)ä¸é¨ã¡ã³ãé¢æ°ãããããã£ã«ç½®ãæã
ã¡ã¢
å¦çã®éå§
ãã¯ãã®å¦çã¯ã¹ã¯ãªããä¸ã®ããããã®é¢æ°(ã¯ã©ã¹ã®ã¡ã³ãé¢æ°ã§ã¯ãªã)ããå§ã¾ãã
æ¢å®ã§ã¯ã¹ã¯ãªããä¸ã«è¨è¿°ããå
¨ã¦ã®é¢æ°ãé¸æå¯ã¨ãªãããg_exportedScriptsã¨ããã¿ãã«ã«é¢æ°åãè¨è¿°ããã¨ããã以å¤ã®é¢æ°åããã¯ãã®ä¸è¦§ã«è¡¨ç¤ºãããªã(éå§ä½ç½®ã¨ãã¦æå®ã§ããªã)ããã«ã§ããã
Python-UNOã®å種ãªãã¸ã§ã¯ã
ãã¯ãã¨ãã¦å®è¡ããã¨ãã«XSCRIPTCONTEXTã¨ãããªãã¸ã§ã¯ããå©ç¨å¯è½ã¨ãªããããããåå¾ã§ããå¹¾ã¤ãã®ãªãã¸ã§ã¯ãããæ´ã«å¥ã®ãªãã¸ã§ã¯ããå¾ãã¨ããå½¢ã§OpenOffice.orgå´ã¨ã®ããã¨ããããããã®è²ã
ãªãªãã¸ã§ã¯ããå¾ãã¨ããæµãããããããã¯Python-UNOãç¨ããã¹ã¯ãªããã§ã¯æ±ºã¾ã£ãæµãã®1ã¤ã§ãä¸ã®ä¾ã§ã¯ãããã£ããªãã¸ã§ã¯ãã¯ã¯ã©ã¹(ãBridgeãã¨ãã)ã®ã¡ã³ãã¨ãã¦ã¾ã¨ãã¦ãã¾ããããããç¨ããå¦çã¯ãã®ã¯ã©ã¹ã®ã¡ã³ãé¢æ°ã«ããã
XSCRIPTCONTEXTãªã©ã®å種ãªãã¸ã§ã¯ãã®è©³ããé¨åã¯ææ¡ã§ãã¦ããªãã
ã¡ãã»ã¼ã¸ãã¤ã¢ãã°ã®è¡¨ç¤º
ã¡ãã»ã¼ã¸ãã¤ã¢ãã°ã表示ããã«ã¯æ±ºã¾ã£ãæµãããã
http://hermione.s41.xrea.com/pukiwiki/pukiwiki.php?OOoPython%2FOverView
ãåèã«ããããã®æµãã®ä¸ã§ã¯XSCRIPTCONTEXTããåå¾ããå¹¾ã¤ãã®ãªãã¸ã§ã¯ããç¨ãã¦ãããä¸ã®ä¾ã§ã¯Bridgeã¯ã©ã¹ã®ã¡ã³ãé¢æ°ã«ããã
ãã¯ãã®èª¬ææåå
é¢æ°ã®ããã¥ã¡ã³ãã¼ã·ã§ã³æååããã¯ãä¸è¦§ã®ãã¤ã¢ãã°ã®ä¸ã§èª¬æã¨ãã¦è¡¨ç¤ºããããé¢æ°å(ãã¯ãåã¨ãªã)ã«æ¥æ¬èªã¯ä½¿ããªãããã®èª¬æã«ã¯æ¥æ¬èªãè¨è¿°ã§ããã
(2010/3/12)ããã¥ã¡ã³ãã¼ã·ã§ã³æååã®æåã«æ¹è¡ãããã¨è¡¨ç¤ºãæ¹è¡ãããè¡ã®å
é ã«ã¹ãã¼ã¹ãããã¨ãããåæ ãããã表示ãæãã³ã³ãã¯ãã«ããã«ã¯
def hello(): "ããã«è¨è¿°ããæååããã¯ãé¸æãã¤ã¢ãã°ãã説æã¨ãã¦è¡¨ç¤ºããã"
ã®ããã«ããã®ãè¯ã(è¤æ°è¡ã®å ´åã¯æ¹è¡ã«æ³¨æ)ããæ¹è¡ãã¨ã¹ã±ã¼ããã¦
def hello(): """\ ããã«è¨è¿°ããæååããã¯ãé¸æãã¤ã¢ãã°ãã説æã¨ãã¦è¡¨ç¤ºããã """
ã®ããã«ããããè²ã
ãªæ¸ãæ¹ã¯ã§ããããã ãä¸ã®ä¾ã§ã¯è¡é ã®ã¹ãã¼ã¹(ã«å ããå®éã¯è¦ããªããæå¾ã®æ¹è¡ã)ã¯èª¬æã®ä¸ã«å
¥ã£ã¦ãã¾ãã
ããããããã»ã©èª¬æãé·ããªããªããã°ããã¾ãæ°ã«ããå¿
è¦ã¯ãªããããããªãã
åèã«ããURLãªã©ã«ã¤ãã¦
- http://hermione.s41.xrea.com/pukiwiki/pukiwiki.php?OOoPython - æãæ å ±ãå å®ã»Basicã®ãã¼ã¸ãåèã«ã§ãã
- http://d.hatena.ne.jp/fgshun/archive ã®ãOpenOfficeã
- http://d.hatena.ne.jp/hanya_orz/20091214/p1
- http://psyto.s26.xrea.com/python/ooomacro_dialog.html - ä»åã¯ãã®å 容ã¨ã¯ãã¾ãé¢ä¿ããªããåèã¨ãã¦
ãªã©ã
å®è¡ããã¡ã³ãé¢æ°ã®ååãåãã£ã¦ãã¦ãã®è©³ç´°ã調ã¹ããã¨ããã¨ãã«ã¯é¢æ°å*3ãæ¤ç´¢ã¨ã³ã¸ã³ã§èª¿ã¹ãã
http://api.openoffice.org/
ã®æ¤ç´¢ããã¯ã¹ã«é¢æ°åãå
¥åããçµæã®ãHTML ã³ã³ãã³ãããããã®èª¬æã«ãªã£ã¦ãããã¼ã¸ãæ¢ãã¦éãã
ã©ã®ãããªãã¨ãã§ãããã¯è²ã
ãªãµã³ãã«ãåèã«ããã®ãè¯ãããã§ãBasicãç¨ãããã®ã«é¢ãããã¼ã¸ã§ããå ´åã«ãã£ã¦ã¯èãæ¹ãå¦çã®æµãã«ã¤ãã¦ã®è¨è¿°ããã£ãããã¦åèã«ãªããã¨ããããBasicã®ã³ã¼ãã«ã¤ãã¦ãé¨åçã«åèã«ã§ããé¨åãããå ´åãå¤ãã
é¢é£è¨äº:
- OpenOffice.orgのマクロをPythonで記述して動かす(Calc上でマクロが動作しているかのチェックと全シートのオブジェクトの取得に関するメモ)
- OpenOffice.orgのマクロをPythonで記述して動かす(Calcのシート追加に関するメモとシート追加のコード例)
- OpenOffice.orgのマクロをPythonで記述して動かす(Calc上でマクロが動作しているかのチェックを改善)
- OpenOffice.orgのマクロをPythonで記述して動かす(Calcのアクティブもしくは任意のシートとセルのオブジェクトの取得)
- OpenOffice.orgのマクロをPythonで記述して動かす(Calcのセル内容へのアクセスについてとセル内容の操作に関する例)
使ç¨ãããã¼ã¸ã§ã³(ããããMandriva Linux 2010.0ã®ããã±ã¼ã¸):
- OpenOffice.org(Go-oo) 3.1.1
- Python 2.6.4
*1:OpenOffice.org APIãæ±ãããã®ãã®ã§ãããOpenOffice.orgãæã¤æ©è½ã®å¤§é¨åãæ±ããä»çµã¿ã«ãªã£ã¦ãã
*2:ãUNOãã®èªã¿æ¹ã¯ãã¦ã¼ãã¦ãã§ãããã¦ãããã¦ã¼ãããã¦ãã¦ããã¦ã¼ãããªã©ã¯ééãã»UNOã¯OpenOffice.orgã®æ©è½ãç¨ããããã®ä»çµã¿
*3:ãã¼ã¯ã¼ããapiããªã©ã¨çµã¿åããã¦ããã