Adding quickparts to a word document using python

I have a document that has existing properties on it from sharepoint and I want to display those properties to the document content as quick parts using python.

@Mark030 You can use structured document tags with xml mapping for these purposes:

Thanks, do you also have a sample for this?

@Mark030 Here is an example:

doc = aw.Document(MY_DIR + "Structured document tags.docx")

xml_part_id = str(uuid.uuid4())
xml_part_content = "<root><text>Hello world!</text></root>"
xml_part = doc.custom_xml_parts.add(xml_part_id, xml_part_content)

# Add an XML schema association.
xml_part.schemas.add("http://www.w3.org/2001/XMLSchema")

# Create a structured document tag that will display our part's contents and insert it into the document body.
tag = aw.markup.StructuredDocumentTag(doc, aw.markup.SdtType.PLAIN_TEXT, aw.markup.MarkupLevel.BLOCK)
tag.xml_mapping.set_mapping(xml_part, "/root[1]/text[1]", "xmlns:ns3='249c057c-e0db-4a1d-bc8c-a0885a9bce06'")

doc.first_section.body.append_child(tag)

doc.save(ARTIFACTS_DIR + "StructuredDocumentTag.creating_custom_xml.docx")

Usefull links: