我正在尝试使用 odfpy 在 LibreOffice Writer (odt) 文档中插入一条水平线。(在Writer中:菜单->插入->水平线)
这是我的尝试(改编这个例子):
from odf import opendocument, chart, text, draw
drawdoc = opendocument.OpenDocumentDrawing() # Create the subdocument
maindoc = opendocument.OpenDocumentText() # Create the main document
dl = draw.Line(x1="1pt", x2="1pt", y1="100pt", y2="100pt", anchortype="paragraph")
maindoc.text.addElement(dl)
objectloc = maindoc.addObject(drawdoc)
do = draw.Object(href=objectloc)
dl.addElement(do)
maindoc.save("horizontalline.odt")
但我得到下一个错误:
Traceback (most recent call last):
File "pagebreak.py", line 9, in <module>
dl.addElement(do)
File "/usr/local/lib/python3.6/dist-packages/odf/element.py", line 427, in addElement
raise IllegalChild( "<%s> is not allowed in <%s>" % ( element.tagName, self.tagName))
odf.element.IllegalChild: <draw:object> is not allowed in <draw:line>
我正在学习 odfpy,但文档很少。我也尝试在 Writer 中创建文档,然后阅读style.xml
,content.xml
但我无法看到相关部分。