odt 문서에 수학 공식을 추가해야합니다. 나는 그것을하는 방법의 예를 찾지 못했습니다. 다음 코드를 시도했습니다. 그러나 그것은 빈 공식을 생성합니다. c = a + b와 같이 추가하는 방법을 모르겠습니다. 누군가 비슷한 문제를 해결 했나요? 수식은 MathML 코드로 작성해야합니다. 그러나 여기에 삽입 할 위치를 모릅니다.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import odf
import odf.opendocument
import odf.math
import odf.text
def main():
doc = odf.opendocument.OpenDocumentText()
p = odf.text.P(text=u'text')
df = odf.draw.Frame( zindex=0, anchortype='as-char')
p.addElement(df)
doc.text.addElement(p)
math = odf.math.Math()
do = odf.draw.Object()
do.addElement(math)
df.addElement(do)
outputfile = u'result'
doc.save(outputfile, True)
if __name__ == '__main__':
main()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import odf
from odf.opendocument import OpenDocumentText
from odf.element import Element
from odf.text import P
from odf.math import Math
from namespaces import MATHNS
def main():
doc = OpenDocumentText()
p = P(text=u'text')
df = odf.draw.Frame( zindex=0, anchortype='as-char')
p.addElement(df)
doc.text.addElement(p)
formula =u'c=sqrt(a^2+b^2)'
math = Math()
annot = Element(qname = (MATHNS,u'annotation'))
annot.addText(formula, check_grammar=False)
annot.setAttribute((MATHNS,'encoding'), 'StarMath 5.0', check_grammar=False)
math.addElement(annot)
do = odf.draw.Object()
do.addElement(math)
df.addElement(do)
outputfile = u'result'
doc.save(outputfile, True)
if __name__ == '__main__':
main()
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다