[Solved] Add Math object to Writer by Python code
Posted: Sat Jul 28, 2018 9:17 pm
how to write a code/macro in python to add math formula object?
User community support forum for Apache OpenOffice, LibreOffice and all the OpenOffice.org derivatives
https://forum.openoffice.org/en/forum/
Code: Select all
Sub InsertEquationAtViewCursor'(oDoc, sFormula$)
Dim oVC
Dim oObj
oDoc = ThisComponent
sFormula = "x over y"
oVC = oDoc.CurrentController.getViewCursor()
oVC.gotoRange(oVC.getEnd(), False)
oObj = oDoc.CreateInstance("com.sun.star.text.TextEmbeddedObject")
oObj.CLSID = "078B7ABA-54FC-457F-8551-6147e776a997"
oObj.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
oVC.Text.insertTextContent(oVC, oObj, False)
oObj.EmbeddedObject.Component.formula = sFormula
End Sub
Code: Select all
from com.sun.star.text.TextContentAnchorType import AS_CHARACTER
Code: Select all
from com.sun.star.text.TextContentAnchorType import AS_CHARACTER
Code: Select all
oObj.AnchorType = AS_CHARACTER