Пример #1
0
 def _update_part(self):
     if self.part is None:
         # Create a new part for custom properties
         partname = PackURI('/docProps/custom.xml')
         self.part = Part(partname, CT.OFC_CUSTOM_PROPERTIES,
                          serialize_part_xml(self._element),
                          self.doc.part.package)
         self.doc.part.package.relate_to(self.part, RT.CUSTOM_PROPERTIES)
         self._element = parse_xml(self.part.blob)
     else:
         self.part._blob = serialize_part_xml(self._element)
Пример #2
-1
    def add_footnotes(self, doc, element):
        """Add footnotes from the given document used in the given element."""
        footnotes_refs = element.findall('.//w:footnoteReference', NS)

        if not footnotes_refs:
            return

        footnote_part = doc.part.rels.part_with_reltype(RT.FOOTNOTES)

        my_footnote_part = self.footnote_part()

        footnotes = parse_xml(my_footnote_part.blob)
        next_id = len(footnotes) + 1

        for ref in footnotes_refs:
            id_ = ref.get('{%s}id' % NS['w'])
            element = parse_xml(footnote_part.blob)
            footnote = deepcopy(
                element.find('.//w:footnote[@w:id="%s"]' % id_, NS))
            footnotes.append(footnote)
            footnote.set('{%s}id' % NS['w'], str(next_id))
            ref.set('{%s}id' % NS['w'], str(next_id))
            next_id += 1

        self.add_referenced_parts(footnote_part, my_footnote_part, element)

        my_footnote_part._blob = serialize_part_xml(footnotes)