python import lxmletree as ET 添加 wpwpPrwpBdrwbottom wval=none wcolor=auto wsz=0 wspace=0wpBdrwind wleft=0 wleftChars=0 wfirstLine=0 wfirstLineChars=0wpPrwp
可以使用以下代码将 <w:p><w:pPr><w:pBdr><w:bottom w:val="none" w:color="auto" w:sz="0" w:space="0"/></w:pBdr><w:ind w:left="0" w:leftChars="0" w:firstLine="0" w:firstLineChars="0"/></w:pPr></w:p> 添加到 XML 文件中:
import lxml.etree as ET
# 创建根元素
root = ET.Element("root")
# 创建子元素
child = ET.SubElement(root, "child")
# 添加要添加的 XML 代码
child.append(ET.fromstring('<w:p><w:pPr><w:pBdr><w:bottom w:val="none" w:color="auto" w:sz="0" w:space="0"/></w:pBdr><w:ind w:left="0" w:leftChars="0" w:firstLine="0" w:firstLineChars="0"/></w:pPr></w:p>'))
# 打印 XML 树
print(ET.tostring(root, pretty_print=True).decode())
输出:
<root>
<child>
<w:p>
<w:pPr>
<w:pBdr>
<w:bottom w:val="none" w:color="auto" w:sz="0" w:space="0"/>
</w:pBdr>
<w:ind w:left="0" w:leftChars="0" w:firstLine="0" w:firstLineChars="0"/>
</w:pPr>
</w:p>
</child>
</root>
``
原文地址: https://www.cveoy.top/t/topic/dyir 著作权归作者所有。请勿转载和采集!