我知道我可以像这样创建Oxmlement:
OxmlElement("w:r")
但我不知道如何创建OXML元素树。 例如,我需要复制OXML树:
<mc:AlternateContent>
<mc:Choice Requires="wps">
<w:drawing>
<wp:inline distT="0" distB="20320" distL="0" distR="28575" wp14:anchorId="6F69A487">
<wp:extent cx="5573395" cy="742950"/>
<wp:effectExtent l="0" t="0" r="28575" b="20320"/>
<wp:docPr id="6" name="Shape3"/>
<a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
<wps:wsp>
<wps:cNvSpPr/>
<wps:spPr>
<a:xfrm>
<a:off x="0" y="0"/>
<a:ext cx="5572800" cy="742320"/>
</a:xfrm>
<a:prstGeom prst="roundRect">
<a:avLst>
<a:gd name="adj" fmla="val 4167"/>
</a:avLst>
</a:prstGeom>
<a:noFill/>
<a:ln w="19050">
<a:solidFill>
<a:srgbClr val="4472c4"/>
</a:solidFill>
</a:ln>
</wps:spPr>
<wps:style>
<a:lnRef idx="2">
<a:schemeClr val="accent1">
<a:shade val="50000"/>
</a:schemeClr>
</a:lnRef>
<a:fillRef idx="1">
<a:schemeClr val="accent1"/>
</a:fillRef>
<a:effectRef idx="0">
<a:schemeClr val="accent1"/>
</a:effectRef>
<a:fontRef idx="minor"/>
</wps:style>
<wps:txbx>
<w:txbxContent>
<w:p>
<w:pPr>
<w:pStyle w:val="FrameContents"/>
<w:spacing w:before="0" w:after="0"/>
<w:rPr>
<w:rStyle w:val="BookTitle"/>
</w:rPr>
</w:pPr>
<w:sdt>
<w:sdtPr>
<w:id w:val="1401119907"/>
</w:sdtPr>
<w:sdtContent>
<w:r>
<w:rPr>
<w:rStyle w:val="BookTitle"/>
</w:rPr>
<w:t xml:space="preserve">Click </w:t>
</w:r>
<w:r>
<w:rPr>
<w:rStyle w:val="BookTitle"/>
</w:rPr>
<w:t>and/or paste to write your block text</w:t>
</w:r>
</w:sdtContent>
</w:sdt>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val="FrameContents"/>
<w:spacing w:before="0" w:after="0"/>
<w:rPr>
<w:color w:val="4472C4" w:themeColor="accent1"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:rStyle w:val="Style11"/>
<w:color w:val="7F7F7F" w:themeColor="text1" w:themeTint="80"/>
<w:sz w:val="20"/>
<w:szCs w:val="20"/>
</w:rPr>
<w:t>Paste url here</w:t>
</w:r>
</w:p>
</w:txbxContent>
</wps:txbx>
<wps:bodyPr anchor="ctr">
<a:prstTxWarp prst="textNoShape"/>
<a:noAutofit/>
</wps:bodyPr>
</wps:wsp>
</a:graphicData>
</a:graphic>
</wp:inline>
</w:drawing>
</mc:Choice>
<mc:Fallback>
<w:pict/>
</mc:Fallback>
</mc:AlternateContent>
我不想逐行手动创建所有标记。 我能用这个函数吗?我需要像这样工作:
element = CreateOxmlElementByString("""
<w:r>
<w:t>text<w:t>
</w:r>
"""
print(element.xml) # result of print: "<w:r><w:t>text<w:t></w:r>"
也许PythonDocx已经有了一个函数,可以通过OXML字符串创建OxmlElement? 或者我需要自己创建这个函数? 谢谢
要解析XML,需要使用docx.oxml库中的parse_XML。 并使用此代码:
parse_xml()
函数在python-docx
中执行该任务:相关问题 更多 >
编程相关推荐