问题
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