Return a |Document| object loaded from `docx`, where `docx` can be either a path to a ``.docx`` file (a string) or a file-like object. If `docx` is missing or ``None``, the built-in default document "template" is loaded.
(docx: str | IO[bytes] | None = None)
| 17 | |
| 18 | |
| 19 | def Document(docx: str | IO[bytes] | None = None) -> DocumentObject: |
| 20 | """Return a |Document| object loaded from `docx`, where `docx` can be either a path |
| 21 | to a ``.docx`` file (a string) or a file-like object. |
| 22 | |
| 23 | If `docx` is missing or ``None``, the built-in default document "template" is |
| 24 | loaded. |
| 25 | """ |
| 26 | docx = _default_docx_path() if docx is None else docx |
| 27 | document_part = cast("DocumentPart", Package.open(docx).main_document_part) |
| 28 | if document_part.content_type != CT.WML_DOCUMENT_MAIN: |
| 29 | tmpl = "file '%s' is not a Word file, content type is '%s'" |
| 30 | raise ValueError(tmpl % (docx, document_part.content_type)) |
| 31 | return document_part.document |
| 32 | |
| 33 | |
| 34 | def _default_docx_path(): |
searching dependent graphs…