Python-Makro, um nur ausgewählte Formeln in einem LibreOffice Writer-Dokument aufzuzählenPython

Python-Programme
Anonymous
 Python-Makro, um nur ausgewählte Formeln in einem LibreOffice Writer-Dokument aufzuzählen

Post by Anonymous »

Ich habe dieses LibreOffice-Python-Makro geschrieben, das (im ASPO-Terminal) den inneren Code jeder „Formel“ (d. h. des im LibreOffice Writer-Inhalt enthaltenen LibreOffice Math-Elements) meines LibreOffice Writer-Dokuments druckt.
Wie kann ich es ändern, um stattdessen nur für die Formeln in der aktuellen Auswahl das gleiche Ergebnis zu erhalten? Ich konnte alle Formen auf einer Seite abrufen, aber wie kann ich feststellen, ob eine bestimmte Form innerhalb der aktuellen Auswahl liegt?
Ich verwende LibreOffice 24.2.7.2 unter Linux Mint 22.2.

Code: Select all

import uno

def explore_objects_in_selection():
doc = XSCRIPTCONTEXT.getDocument()

selection = doc.getCurrentSelection()
# Useless variable in this code for now, equivalent to
#selection = doc.CurrentController.getSelection()

shapes = []
for draw_page in doc.getDrawPages():
# Maybe testing here if shape is in selection, but how?
for shape in draw_page:
shapes.append(shape)

for shape in shapes:
#if hasattr(shape, 'ShapeType'):
# In my doc, shape.ShapeType or shape.getShapeType()
# is 'FrameShape'
assert hasattr(shape.getEmbeddedObject(), 'Formula')
# Inner code of each formula in my doc
print(shape.getEmbeddedObject().Formula)
Wie ich oben sagte, werden vorerst alle Formeln gedruckt, auch wenn ich nur einen Teil des Writer-Dokuments auswähle. Mein Ziel ist es, nur diejenigen zu drucken, die im ausgewählten Bereich enthalten sind.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post