使用 VB 或 python 编写 OpenOffice 表单脚本

发布于 09-10 17:11 字数 535 浏览 13 评论 0原文

我正在尝试编写我的 OpenOffice 文档(在我的例子中为 Writer)的脚本来使用小部件执行一些简单的操作。也就是说,我想将文本从一个小部件复制到另一个小部件。为此,我想获取一个组件,然后从中获取文本。

我一直在尝试这样做:

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 规范。

I'm trying to script my OpenOffice document (Writer in my case) to do some simple things with widgets. Namely I'd like to copy text from widget to widget. For this I want to get one component and than get text from it.

I've been trying to do sth like this:

document   = ThisComponent.CurrentController.Frame

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

Neither version #1 nor #2 work. VB compiler spits out that "Text Box 1" is not accessible, however I have that component in my form. My guess is that I'm trying to get this component from a wrong place, eg. not it's frame. I just can't figure out what is the structure of the document.

This seems like a pretty easy task, however I'm unable to find any OpenOffice specification as for accessing OO UNO objects from VB, or python.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

悲念泪2024-09-17 17:11:41

再会。

如果你选择使用VB,你必须知道这一点:

VBA:OpenOffice.org Basic 和 VBA 之间的兼容性涉及
OpenOffice.org Basic 语言以及运行时库。这
OpenOffice.org API 和对话框编辑器与 VBA 不兼容
(标准化这些接口将使许多概念
OpenOffice.org 中不可能提供)。

如果是 python

OpenOffice.org 3.1 附带 Python 脚本语言版本
2.6.1.旧版 OpenOffice.org 附带 Python 版本 2.3.4。这个Python发行版附带了Uno模块,它连接UNO
Python 脚本语言的 API。运行此版本的 Python
Linux,您可以直接进入 OpenOffice.org PATH。并且作为一个
预计任何 Python 发行版都可以运行 OOo-Python
也可以从命令行。如果你已经有一个单独的Python
2.6 安装后,您可以使用这些说明将 uno 模块(Python-UNO 桥接器)导入其中。如果您已经有
Windows上安装的不同版本的Python,也可以访问
UNO API 使用 COM 桥而不是 Python 桥。
需要附加 pywin32 模块,以便 Python 可以与 COM 通信。笔记
虽然 UNO API 是统一的,但两者的实现
桥接略有不同,因此每个桥接所需的语法也有所不同
有时不同。

Python UNO 桥

更新:oooblogger 可能会帮助您了解 python 和 uno 集成。

Good day.

if you choose use a VB, you must know this:

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).

if it will be 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 might help you with understanding of python and uno integration.

£冰雨忧蓝°2024-09-17 17:11:41

我没有 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 找到此大型 pdf 中的其余部分/VBA/Programmation_OpenOffice_org_3_ed1_v1.pdf,它是法语,但代码是通用的,是吗?
希望有帮助..

i don't have experience with openoffice scripting but i found thes examples, note they never use getByName on the document itself but always on some part of it.

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")

you can find the rest in this large pdf at http://oqei.free.fr/echange/VBA/Programmation_OpenOffice_org_3_ed1_v1.pdf ,it's in french but code is universal eh ?
Hope it helps..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文