简体   繁体   English

使用pyUNO从Office文档中提取宏

[英]Extract macro from Office document using pyUNO

I've got a Microsoft Word document with an embedded macro. 我有一个带有嵌入式宏的Microsoft Word文档。 I've managed to load a document using this example Loading a document on OpenOffice using an external Python program 我已经使用此示例成功加载了文档,使用外部Python程序在OpenOffice上加载了文档

Now I'm trying to get macros code from my document, but can't figure, how to do this. 现在,我正在尝试从文档中获取宏代码,但无法确定如何执行此操作。 I've stumbled upon interface that probably can be used ( http://www.openoffice.org/api/docs/common/ref/com/sun/star/document/XEmbeddedScripts.html ) though it's unclear to me how to use it in Python. 尽管我不清楚如何使用,但我偶然发现了可能可以使用的界面( http://www.openoffice.org/api/docs/common/ref/com/sun/star/document/XEmbeddedScripts.html )它在Python中。

So how can I extract macros text from document using Python UNO? 那么如何使用Python UNO从文档中提取宏文本?

Which version of LO you are using? 您正在使用哪个版本的LO? Normally, i would do something like 通常,我会做类似的事情

doc = desktop.loadComponentFromURL(url, "_blank", 0, () )


# the Basic Script Library/Libraries
the_basic_libs = doc.BasicLibraries

if the_basic_libs.hasElements():
    the_standard = the_basic_libs.getByName("Standard")

    the_one = the_standard.getByName("Module1")

    print(the_one)

But my version (LO 4.1.3.2) gives me a "no such element exception", though I can see and access the element using MRI (or the GUI). 但是我的版本(LO 4.1.3.2)为我提供了“没有这样的元素异常”,尽管我可以使用MRI(或GUI)查看和访问该元素。

Maybe a flaw in LO, uno ... or the fact, that we test with a *.doc 也许是LO的缺陷,或者……我们用* .doc测试的事实

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM