LibreOffice how to recup the current element

蓝咒 提交于 2021-01-28 20:16:39

问题


I want to retrieve the current element in LibreOffice Impress to apply changes to it.

For example, I'm trying to retrieve this shape to change the text in it with macros.

I tried to find information with the X-ray tool but without success.


回答1:


To get the currently selected shape:

oSel = ThisComponent.getCurrentController.getSelection()
oShape = oSel.getByIndex(0)
Print oShape.getString()

To iterate through all shapes in the slide, start with ThisComponent.getDrawPages() and then use XrayTool.

You may also find the following snippet of python code helpful:

def iterate_draw_shapes():
    oDrawPage = oDrawPages.getByIndex(1)
    for oShape in oDrawPage:
        if oShape.supportsService("com.sun.star.drawing.TextShape"):
            oTexts = oShape.createEnumeration()
            while oTexts.hasMoreElements():
                oText = oTexts.nextElement()
                oTextPortions = oText.createEnumeration()
                while oTextPortions.hasMoreElements():
                    oTextPortion = oTextPortions.nextElement()


来源:https://stackoverflow.com/questions/59922201/libreoffice-how-to-recup-the-current-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!