[Solved] Add Math object to Writer by Python code
[Solved] Add Math object to Writer by Python code
how to write a code/macro in python to add math formula object?
Last edited by barak1969 on Sun Jul 29, 2018 11:18 am, edited 1 time in total.
openoffice 4.1.5 on windows10
Re: add math object to writer by python code
This Basic code from an old post works for me.
Python code should be very similar.
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
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: add math object to writer by python code
thanks but the line:
oObj.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
is not recognizing com
oObj.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
is not recognizing com
openoffice 4.1.5 on windows10
Re: add math object to writer by python code
I think you have to import the AS_CHARACTER
I can't find a code example at the moment and I have to go. Try a search and I will be back later.
Code: Select all
from com.sun.star.text.TextContentAnchorType import AS_CHARACTER
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Add Math object to Writer by Python code
Looking at some old code, you should put
at the top of your code and set
farther down in the code.
Code: Select all
from com.sun.star.text.TextContentAnchorType import AS_CHARACTER
Code: Select all
oObj.AnchorType = AS_CHARACTER
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Add Math object to Writer by Python code
it works like magic. thanks
openoffice 4.1.5 on windows10