用VB或python编写OpenOffice窗体脚本

2024-05-20 13:44:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试编写我的OpenOffice文档(在我的例子中是Writer)来使用widgets做一些简单的事情。也就是说,我想把文本从widget复制到widget。为此,我想得到一个组件,然后从中获取文本。在

我一直想做这样的事:

document   = ThisComponent.CurrentController.Frame

oDocument      =  ThisComponent
oTextBoxFrom = document.getByName("Text Box 1")    # 1
oTextBoxFrom = oDocument.getByName("Text Box 1")   # 2

版本1和版本2都不起作用。VB编译器指出“文本框1”是不可访问的,但我的表单中有那个组件。我的猜测是我试图从一个错误的地方得到这个部件,例如,不是框架。我就是搞不懂文件的结构。在

这似乎是一个相当简单的任务,但是我找不到任何关于从VB或python访问OO-UNO对象的OpenOffice规范。在


Tags: text文档文本版本box组件widgetdocument
2条回答

我没有使用openoffice脚本的经验,但我发现了这些示例,注意它们从不在文档本身上使用getByName,而是总是在文档的某些部分使用getByName。在

docCalc = ThisComponent
maFeuille = docCalc.Sheets.getByName("leCSV")
....
for f = 0 to lesFamilles.Count -1' chaque famille
nomFam = lesFamilles.ElementNames(f)
uneFamille = lesFamilles.getByName(nomFam)
...
monDocument.TextTables.hasByName("Finances")
...
lesSections = monDocument.TextSections
sectA = lesSections.getByName("Aline")

你可以在http://oqei.free.fr/echange/VBA/Programmation_OpenOffice_org_3_ed1_v1.pdf上找到其余部分,它是法语,但代码是通用的,是吗? 希望有帮助。。在

再见。在

如果选择使用VB,则必须知道:

VBA : Compatibility between OpenOffice.org Basic and VBA relates to the OpenOffice.org Basic language as well as the runtime library. The OpenOffice.org API and the Dialog Editor are not compatible with VBA (standardizing these interfaces would have made many of the concepts provided in OpenOffice.org impossible).

如果是python

OpenOffice.org 3.1 ships with the Python scripting language, version 2.6.1. Older OpenOffice.org ships with Python version 2.3.4. This Python distribution comes with the Uno module, which connects the UNO API to the python scripting language. To run this version of Python on Linux, you can go directly to the OpenOffice.org PATH. And as one would expect with any distribution of Python, OOo-Python can be run from the command line as well. If you already have a separate Python 2.6 installation, you can import the uno module (the Python-UNO bridge) to it using these instructions. If you already have a different version of Python installed on Windows, you can also access the UNO API using the COM bridge instead of the Python bridge. Requires the add-on pywin32 module so Python can talk to COM. Note that while the UNO API is uniform, the implementation by the two bridges is slightly different, so the syntax required by each is also sometimes different.

Python UNO bridge

upd:ooobloger可能有助于您理解python和uno集成。在

相关问题 更多 >