def styles_part(self): """ Instance of |StylesPart| for this document. Creates an empty styles part if one is not present. """ try: return self._document_part.part_related_by(RT.STYLES) except KeyError: styles_part = StylesPart.new() self._document_part.relate_to(styles_part, RT.STYLES) return styles_part
def styles_part(self): """ Instance of |StylesPart| for this document. Creates an empty styles part if one is not present. """ try: return self._document_part.part_related_by(RT.STYLES) except KeyError: styles_part = StylesPart.new() self._document_part.relate_to(styles_part, RT.STYLES) return styles_part @lazyproperty def header_part(self, section=None): """ Instance of |HeaderPart| for this document. Takes a section argument. If none is passed, assumes default (sentinel) Section. Creates an empty header part if one is not present. """ if not section: section = self.sections()[0] try: return self._document_part.part_related_by(RT.HEADER) except KeyError: header_part = HeaderPart.new() self._document_part.relate_to(header_part, RT.HEADER) return header_part @property def tables(self): """ A list of |Table| instances corresponding to the tables in the document, in document order. Note that tables within revision marks such as ``<w:ins>`` or ``<w:del>`` do not appear in this list. """ return self._document_part.tables @staticmethod def _open(docx): """ Return a (document_part, package) 2-tuple loaded from *docx*, where *docx* can be either a path to a ``.docx`` file (a string) or a file-like object. If *docx* is ``None``, the built-in default document "template" is loaded. """ docx = _default_docx_path if docx is None else docx package = Package.open(docx) document_part = package.main_document if document_part.content_type != CT.WML_DOCUMENT_MAIN: tmpl = "file '%s' is not a Word file, content type is '%s'" raise ValueError(tmpl % (docx, document_part.content_type)) return document_part, package