├── .gitignore ├── .readthedocs.yaml ├── .travis.yml ├── HISTORY.md ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.md ├── docs ├── Makefile ├── _static │ ├── .gitignore │ └── img │ │ ├── example-docx-01.png │ │ ├── hdrftr-01.png │ │ ├── hdrftr-02.png │ │ └── oss.png ├── _templates │ ├── layout.html │ └── sidebarlinks.html ├── _themes │ └── armstrong │ │ ├── LICENSE │ │ ├── layout.html │ │ ├── rtd-themes.conf │ │ ├── static │ │ └── rtd.css_t │ │ ├── theme.conf │ │ └── theme.conf.orig ├── api │ ├── dml.rst │ ├── document.rst │ ├── enum │ │ ├── MsoColorType.rst │ │ ├── MsoThemeColorIndex.rst │ │ ├── WdAlignParagraph.rst │ │ ├── WdBuiltinStyle.rst │ │ ├── WdCellVerticalAlignment.rst │ │ ├── WdColorIndex.rst │ │ ├── WdLineSpacing.rst │ │ ├── WdOrientation.rst │ │ ├── WdRowAlignment.rst │ │ ├── WdRowHeightRule.rst │ │ ├── WdSectionStart.rst │ │ ├── WdStyleType.rst │ │ ├── WdTabAlignment.rst │ │ ├── WdTabLeader.rst │ │ ├── WdTableDirection.rst │ │ ├── WdUnderline.rst │ │ └── index.rst │ ├── section.rst │ ├── settings.rst │ ├── shape.rst │ ├── shared.rst │ ├── style.rst │ ├── table.rst │ └── text.rst ├── conf.py ├── dev │ └── analysis │ │ ├── features │ │ ├── coreprops.rst │ │ ├── header.rst │ │ ├── numbering.rst │ │ ├── sections.rst │ │ ├── settings.rst │ │ ├── shapes │ │ │ ├── index.rst │ │ │ ├── picture.rst │ │ │ ├── shapes-inline-size.rst │ │ │ └── shapes-inline.rst │ │ ├── styles │ │ │ ├── character-style.rst │ │ │ ├── index.rst │ │ │ ├── latent-styles.rst │ │ │ ├── paragraph-style.rst │ │ │ ├── style.rst │ │ │ └── styles.rst │ │ ├── table │ │ │ ├── cell-merge.rst │ │ │ ├── index.rst │ │ │ ├── table-cell.rst │ │ │ ├── table-props.rst │ │ │ └── table-row.rst │ │ └── text │ │ │ ├── breaks.rst │ │ │ ├── font-color.rst │ │ │ ├── font-highlight-color.rst │ │ │ ├── font.rst │ │ │ ├── index.rst │ │ │ ├── paragraph-format.rst │ │ │ ├── run-content.rst │ │ │ ├── tab-stops.rst │ │ │ └── underline.rst │ │ ├── index.rst │ │ └── schema │ │ ├── ct_body.rst │ │ ├── ct_document.rst │ │ └── ct_p.rst ├── index.rst ├── requirements.txt └── user │ ├── api-concepts.rst │ ├── custom-properties.rst │ ├── custom-xml.rst │ ├── documents.rst │ ├── hdrftr.rst │ ├── install.rst │ ├── quickstart.rst │ ├── sections.rst │ ├── shapes.rst │ ├── styles-understanding.rst │ ├── styles-using.rst │ └── text.rst ├── docx ├── __init__.py ├── api.py ├── blkcntnr.py ├── compat.py ├── dml │ ├── __init__.py │ └── color.py ├── document.py ├── enum │ ├── __init__.py │ ├── base.py │ ├── dml.py │ ├── section.py │ ├── shape.py │ ├── style.py │ ├── table.py │ └── text.py ├── exceptions.py ├── image │ ├── __init__.py │ ├── bmp.py │ ├── constants.py │ ├── emf.py │ ├── exceptions.py │ ├── gif.py │ ├── helpers.py │ ├── image.py │ ├── jpeg.py │ ├── png.py │ ├── svg.py │ └── tiff.py ├── opc │ ├── __init__.py │ ├── compat.py │ ├── constants.py │ ├── coreprops.py │ ├── customprops.py │ ├── exceptions.py │ ├── oxml.py │ ├── package.py │ ├── packuri.py │ ├── part.py │ ├── parts │ │ ├── __init__.py │ │ ├── coreprops.py │ │ └── customprops.py │ ├── phys_pkg.py │ ├── pkgreader.py │ ├── pkgwriter.py │ ├── rel.py │ ├── shared.py │ └── spec.py ├── oxml │ ├── __init__.py │ ├── coreprops.py │ ├── customprops.py │ ├── document.py │ ├── exceptions.py │ ├── ns.py │ ├── numbering.py │ ├── section.py │ ├── settings.py │ ├── shape.py │ ├── shared.py │ ├── simpletypes.py │ ├── styles.py │ ├── table.py │ ├── text │ │ ├── __init__.py │ │ ├── font.py │ │ ├── paragraph.py │ │ ├── parfmt.py │ │ └── run.py │ └── xmlchemy.py ├── package.py ├── parts │ ├── __init__.py │ ├── customxml.py │ ├── document.py │ ├── hdrftr.py │ ├── image.py │ ├── numbering.py │ ├── settings.py │ ├── story.py │ └── styles.py ├── section.py ├── settings.py ├── shape.py ├── shared.py ├── styles │ ├── __init__.py │ ├── latent.py │ ├── style.py │ └── styles.py ├── table.py ├── templates │ ├── default-docx-template │ │ ├── [Content_Types].xml │ │ ├── _rels │ │ │ └── .rels │ │ ├── customXml │ │ │ ├── _rels │ │ │ │ └── item1.xml.rels │ │ │ ├── item1.xml │ │ │ └── itemProps1.xml │ │ ├── docProps │ │ │ ├── app.xml │ │ │ ├── core.xml │ │ │ └── thumbnail.jpeg │ │ └── word │ │ │ ├── _rels │ │ │ └── document.xml.rels │ │ │ ├── document.xml │ │ │ ├── fontTable.xml │ │ │ ├── numbering.xml │ │ │ ├── settings.xml │ │ │ ├── styles.xml │ │ │ ├── stylesWithEffects.xml │ │ │ ├── theme │ │ │ └── theme1.xml │ │ │ └── webSettings.xml │ ├── default-footer.xml │ ├── default-header.xml │ ├── default-numbering.xml │ ├── default-settings.xml │ ├── default-styles.xml │ └── default.docx └── text │ ├── __init__.py │ ├── font.py │ ├── paragraph.py │ ├── parfmt.py │ ├── run.py │ └── tabstops.py ├── features ├── api-open-document.feature ├── blk-add-paragraph.feature ├── blk-add-table.feature ├── cel-add-table.feature ├── cel-text.feature ├── doc-access-collections.feature ├── doc-access-sections.feature ├── doc-add-heading.feature ├── doc-add-page-break.feature ├── doc-add-paragraph.feature ├── doc-add-picture.feature ├── doc-add-section.feature ├── doc-add-table.feature ├── doc-coreprops.feature ├── doc-customprops.feature ├── doc-settings.feature ├── doc-styles.feature ├── environment.py ├── hdr-header-footer.feature ├── img-characterize-image.feature ├── num-access-numbering-part.feature ├── par-access-parfmt.feature ├── par-add-run.feature ├── par-alignment-prop.feature ├── par-clear-paragraph.feature ├── par-insert-paragraph.feature ├── par-set-text.feature ├── par-style-prop.feature ├── run-access-content.feature ├── run-access-font.feature ├── run-add-content.feature ├── run-add-picture.feature ├── run-char-style.feature ├── run-clear-run.feature ├── run-enum-props.feature ├── sct-section.feature ├── shp-inline-shape-access.feature ├── shp-inline-shape-size.feature ├── steps │ ├── api.py │ ├── block.py │ ├── cell.py │ ├── coreprops.py │ ├── customprops.py │ ├── document.py │ ├── font.py │ ├── hdrftr.py │ ├── helpers.py │ ├── image.py │ ├── numbering.py │ ├── paragraph.py │ ├── parfmt.py │ ├── section.py │ ├── settings.py │ ├── shape.py │ ├── shared.py │ ├── styles.py │ ├── table.py │ ├── tabstops.py │ ├── test_files │ │ ├── blk-containing-table.docx │ │ ├── court-exif.jpg │ │ ├── doc-access-sections.docx │ │ ├── doc-add-section.docx │ │ ├── doc-coreprops.docx │ │ ├── doc-customprops.docx │ │ ├── doc-default.docx │ │ ├── doc-no-coreprops.docx │ │ ├── doc-no-customprops.docx │ │ ├── doc-odd-even-hdrs.docx │ │ ├── doc-word-default-blank.docx │ │ ├── fnt-color.docx │ │ ├── hdr-header-footer.docx │ │ ├── jfif-300-dpi.jpg │ │ ├── jpeg420exif.jpg │ │ ├── lena.bmp │ │ ├── lena.gif │ │ ├── lena.tif │ │ ├── lena_std.jpg │ │ ├── monty-truth.png │ │ ├── mountain.bmp │ │ ├── num-having-numbering-part.docx │ │ ├── par-alignment.docx │ │ ├── par-known-paragraphs.docx │ │ ├── par-known-styles.docx │ │ ├── python-icon.jpeg │ │ ├── run-char-style.docx │ │ ├── run-enumerated-props.docx │ │ ├── sample.tif │ │ ├── sct-first-page-hdrftr.docx │ │ ├── sct-section-props.docx │ │ ├── set-no-settings-part.docx │ │ ├── shp-inline-shape-access.docx │ │ ├── sty-behav-props.docx │ │ ├── sty-having-no-styles-part.docx │ │ ├── sty-having-styles-part.docx │ │ ├── sty-known-styles.docx │ │ ├── tab-stops.docx │ │ ├── tbl-2x2-table.docx │ │ ├── tbl-cell-access.docx │ │ ├── tbl-col-props.docx │ │ ├── tbl-having-applied-style.docx │ │ ├── tbl-having-tables.docx │ │ ├── tbl-on-off-props.docx │ │ ├── tbl-props.docx │ │ ├── test.png │ │ ├── txt-font-highlight-color.docx │ │ └── txt-font-props.docx │ └── text.py ├── sty-access-font.feature ├── sty-access-latent-styles.feature ├── sty-access-parfmt.feature ├── sty-add-style.feature ├── sty-delete-style.feature ├── sty-latent-add-del.feature ├── sty-latent-props.feature ├── sty-style-props.feature ├── tab-access-tabs.feature ├── tab-tabstop-props.feature ├── tbl-add-row-or-col.feature ├── tbl-cell-access.feature ├── tbl-cell-props.feature ├── tbl-col-props.feature ├── tbl-item-access.feature ├── tbl-merge-cells.feature ├── tbl-props.feature ├── tbl-row-props.feature ├── tbl-style.feature ├── txt-add-break.feature ├── txt-font-color.feature ├── txt-font-props.feature └── txt-parfmt-props.feature ├── ref ├── ISO-IEC-29500-1.pdf ├── ISO-IEC-29500-2.pdf ├── ISO-IEC-29500-3.pdf ├── ISO-IEC-29500-4.pdf ├── rnc │ ├── DrawingML_Chart.rnc │ ├── DrawingML_Chart_Drawing.rnc │ ├── DrawingML_Diagram_Colors.rnc │ ├── DrawingML_Diagram_Data.rnc │ ├── DrawingML_Diagram_Layout_Definition.rnc │ ├── DrawingML_Diagram_Style.rnc │ ├── DrawingML_Table_Styles.rnc │ ├── DrawingML_Theme.rnc │ ├── DrawingML_Theme_Override.rnc │ ├── PresentationML_Comment_Authors.rnc │ ├── PresentationML_Comments.rnc │ ├── PresentationML_Handout_Master.rnc │ ├── PresentationML_Notes_Master.rnc │ ├── PresentationML_Notes_Slide.rnc │ ├── PresentationML_Presentation.rnc │ ├── PresentationML_Presentation_Properties.rnc │ ├── PresentationML_Slide.rnc │ ├── PresentationML_Slide_Layout.rnc │ ├── PresentationML_Slide_Master.rnc │ ├── PresentationML_Slide_Synchronization_Data.rnc │ ├── PresentationML_User-Defined_Tags.rnc │ ├── PresentationML_View_Properties.rnc │ ├── Shared_Additional_Characteristics.rnc │ ├── Shared_Bibliography.rnc │ ├── Shared_Custom_File_Properties.rnc │ ├── Shared_Custom_XML_Data_Storage_Properties.rnc │ ├── Shared_Extended_File_Properties.rnc │ ├── SpreadsheetML_Calculation_Chain.rnc │ ├── SpreadsheetML_Chartsheet.rnc │ ├── SpreadsheetML_Comments.rnc │ ├── SpreadsheetML_Connections.rnc │ ├── SpreadsheetML_Custom_XML_Mappings.rnc │ ├── SpreadsheetML_Dialogsheet.rnc │ ├── SpreadsheetML_Drawing.rnc │ ├── SpreadsheetML_External_Workbook_References.rnc │ ├── SpreadsheetML_Metadata.rnc │ ├── SpreadsheetML_Pivot_Table.rnc │ ├── SpreadsheetML_Pivot_Table_Cache_Definition.rnc │ ├── SpreadsheetML_Pivot_Table_Cache_Records.rnc │ ├── SpreadsheetML_Query_Table.rnc │ ├── SpreadsheetML_Shared_String_Table.rnc │ ├── SpreadsheetML_Shared_Workbook_Revision_Headers.rnc │ ├── SpreadsheetML_Shared_Workbook_Revision_Log.rnc │ ├── SpreadsheetML_Shared_Workbook_User_Data.rnc │ ├── SpreadsheetML_Single_Cell_Table_Definitions.rnc │ ├── SpreadsheetML_Styles.rnc │ ├── SpreadsheetML_Table_Definitions.rnc │ ├── SpreadsheetML_Volatile_Dependencies.rnc │ ├── SpreadsheetML_Workbook.rnc │ ├── SpreadsheetML_Worksheet.rnc │ ├── VML_Drawing.rnc │ ├── WordprocessingML_Comments.rnc │ ├── WordprocessingML_Document_Settings.rnc │ ├── WordprocessingML_Endnotes.rnc │ ├── WordprocessingML_Font_Table.rnc │ ├── WordprocessingML_Footer.rnc │ ├── WordprocessingML_Footnotes.rnc │ ├── WordprocessingML_Glossary_Document.rnc │ ├── WordprocessingML_Header.rnc │ ├── WordprocessingML_Mail_Merge_Recipient_Data.rnc │ ├── WordprocessingML_Main_Document.rnc │ ├── WordprocessingML_Numbering_Definitions.rnc │ ├── WordprocessingML_Style_Definitions.rnc │ ├── WordprocessingML_Web_Settings.rnc │ ├── any.rnc │ ├── dml-chart.rnc │ ├── dml-chartDrawing.rnc │ ├── dml-diagram.rnc │ ├── dml-lockedCanvas.rnc │ ├── dml-main.rnc │ ├── dml-picture.rnc │ ├── dml-spreadsheetDrawing.rnc │ ├── dml-wordprocessingDrawing.rnc │ ├── pml.rnc │ ├── shared-additionalCharacteristics.rnc │ ├── shared-bibliography.rnc │ ├── shared-commonSimpleTypes.rnc │ ├── shared-customXmlDataProperties.rnc │ ├── shared-customXmlSchemaProperties.rnc │ ├── shared-documentPropertiesCustom.rnc │ ├── shared-documentPropertiesExtended.rnc │ ├── shared-documentPropertiesVariantTypes.rnc │ ├── shared-math.rnc │ ├── shared-relationshipReference.rnc │ ├── sml.rnc │ ├── vml-main.rnc │ ├── vml-officeDrawing.rnc │ ├── vml-presentationDrawing.rnc │ ├── vml-spreadsheetDrawing.rnc │ ├── vml-wordprocessingDrawing.rnc │ ├── wml.rnc │ └── xml.rnc ├── styles.xml └── xsd │ ├── dml-chart.xsd │ ├── dml-chartDrawing.xsd │ ├── dml-diagram.xsd │ ├── dml-lockedCanvas.xsd │ ├── dml-main.xsd │ ├── dml-picture.xsd │ ├── dml-spreadsheetDrawing.xsd │ ├── dml-wordprocessingDrawing.xsd │ ├── opc-xsd │ ├── opc-contentTypes.xsd │ ├── opc-coreProperties.xsd │ ├── opc-digSig.xsd │ └── opc-relationships.xsd │ ├── pml.xsd │ ├── shared-additionalCharacteristics.xsd │ ├── shared-bibliography.xsd │ ├── shared-commonSimpleTypes.xsd │ ├── shared-customXmlDataProperties.xsd │ ├── shared-customXmlSchemaProperties.xsd │ ├── shared-documentPropertiesCustom.xsd │ ├── shared-documentPropertiesExtended.xsd │ ├── shared-documentPropertiesVariantTypes.xsd │ ├── shared-math.xsd │ ├── shared-relationshipReference.xsd │ ├── sml.xsd │ ├── vml-main.xsd │ ├── vml-officeDrawing.xsd │ ├── vml-presentationDrawing.xsd │ ├── vml-spreadsheetDrawing.xsd │ ├── vml-wordprocessingDrawing.xsd │ └── wml.xsd ├── requirements-dev.txt ├── requirements.txt ├── setup.py ├── tests ├── __init__.py ├── dml │ ├── __init__.py │ └── test_color.py ├── image │ ├── __init__.py │ ├── test_bmp.py │ ├── test_emf.py │ ├── test_gif.py │ ├── test_helpers.py │ ├── test_image.py │ ├── test_jpeg.py │ ├── test_png.py │ ├── test_svg.py │ └── test_tiff.py ├── opc │ ├── __init__.py │ ├── parts │ │ ├── __init__.py │ │ ├── test_coreprops.py │ │ └── test_customprops.py │ ├── test_coreprops.py │ ├── test_customprops.py │ ├── test_oxml.py │ ├── test_package.py │ ├── test_packuri.py │ ├── test_part.py │ ├── test_phys_pkg.py │ ├── test_pkgreader.py │ ├── test_pkgwriter.py │ ├── test_rel.py │ └── unitdata │ │ ├── __init__.py │ │ ├── rels.py │ │ └── types.py ├── oxml │ ├── __init__.py │ ├── parts │ │ ├── __init__.py │ │ ├── test_document.py │ │ └── unitdata │ │ │ ├── __init__.py │ │ │ └── document.py │ ├── test__init__.py │ ├── test_ns.py │ ├── test_styles.py │ ├── test_table.py │ ├── test_xmlchemy.py │ ├── text │ │ ├── __init__.py │ │ └── test_run.py │ └── unitdata │ │ ├── __init__.py │ │ ├── dml.py │ │ ├── numbering.py │ │ ├── section.py │ │ ├── shared.py │ │ ├── styles.py │ │ ├── table.py │ │ └── text.py ├── parts │ ├── __init__.py │ ├── test_customxml.py │ ├── test_document.py │ ├── test_hdrftr.py │ ├── test_image.py │ ├── test_numbering.py │ ├── test_settings.py │ ├── test_story.py │ └── test_styles.py ├── styles │ ├── __init__.py │ ├── test_latent.py │ ├── test_style.py │ └── test_styles.py ├── test_api.py ├── test_blkcntnr.py ├── test_document.py ├── test_enum.py ├── test_files │ ├── 150-dpi.png │ ├── 300-dpi.TIF │ ├── 300-dpi.jpg │ ├── 300-dpi.png │ ├── 72-dpi.tiff │ ├── CVS_LOGO.WMF │ ├── exif-420-dpi.jpg │ ├── expanded_docx │ │ ├── [Content_Types].xml │ │ ├── _rels │ │ │ └── .rels │ │ ├── customXml │ │ │ ├── _rels │ │ │ │ └── item1.xml.rels │ │ │ ├── item1.xml │ │ │ └── itemProps1.xml │ │ ├── docProps │ │ │ ├── app.xml │ │ │ ├── core.xml │ │ │ └── thumbnail.jpeg │ │ └── word │ │ │ ├── _rels │ │ │ └── document.xml.rels │ │ │ ├── document.xml │ │ │ ├── fontTable.xml │ │ │ ├── numbering.xml │ │ │ ├── settings.xml │ │ │ ├── styles.xml │ │ │ ├── stylesWithEffects.xml │ │ │ ├── theme │ │ │ └── theme1.xml │ │ │ └── webSettings.xml │ ├── having-images.docx │ ├── jfif-iguana.jpg │ ├── little-endian.tif │ ├── monty-truth.png │ ├── python-icon.jpeg │ ├── python-icon.png │ ├── python-powered.png │ ├── python.bmp │ ├── snippets │ │ ├── add-row-col.txt │ │ ├── inline.txt │ │ ├── new-tbl.txt │ │ └── tbl-cells.txt │ ├── sonic.gif │ └── test.docx ├── test_package.py ├── test_section.py ├── test_settings.py ├── test_shape.py ├── test_shared.py ├── test_table.py ├── text │ ├── __init__.py │ ├── test_font.py │ ├── test_paragraph.py │ ├── test_parfmt.py │ ├── test_run.py │ └── test_tabstops.py ├── unitdata.py └── unitutil │ ├── __init__.py │ ├── cxml.py │ ├── file.py │ └── mock.py └── tox.ini /.gitignore: -------------------------------------------------------------------------------- 1 | local.txt 2 | .coverage 3 | /dist/ 4 | /docs/.build/ 5 | /*.egg-info 6 | *.pyc 7 | .pytest_cache/ 8 | _scratch/ 9 | Session.vim 10 | /.tox/ 11 | /build/ 12 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | build: 4 | os: "ubuntu-22.04" 5 | tools: 6 | python: "3.12" 7 | 8 | python: 9 | install: 10 | - requirements: docs/requirements.txt 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "3.8" 4 | - "3.9" 5 | - "3.10" 6 | install: pip install -r requirements.txt 7 | script: pytest 8 | -------------------------------------------------------------------------------- /HISTORY.md: -------------------------------------------------------------------------------- 1 | ## Release History 2 | 3 | **0.0.9 (2024-11-26)** 4 | 5 | - svg file support in add_picture. #27 6 | - update docs. 7 | 8 | **0.0.8 (2024-11-22)** 9 | 10 | - EastAsia font support fixes. #25 11 | - Update README.md. #26 12 | 13 | **0.0.7 (2022-10-29)** 14 | 15 | - add emf image file support. #24 16 | 17 | **0.0.6 (2022-10-21)** 18 | 19 | - change default custom xml file name to item1. #23 20 | 21 | **0.0.5 (2022-8-08)** 22 | 23 | - minor refactor custom-properties. 24 | - add add_float_picture in Document. #21 25 | 26 | **0.0.4 (2022-7-21)** 27 | 28 | - public python-docx-oss docs @ readthedocs. 29 | - add delete_item in CustomXmlPart. #17 30 | 31 | **0.0.3 (2022-7-01)** 32 | 33 | - Change method text to texts in CT_R. #14 34 | - Add external target_ref setter. #15 35 | - Blacken all Python files. 36 | 37 | **0.0.2 (2022-06-24)** 38 | 39 | - Add custom xml support. #10 40 | - Add Part **eq**. 41 | - Add Part element setter. 42 | - Add Relationships parts_with_reltype. 43 | 44 | **0.0.1 (2022-06-16)** 45 | 46 | - Only support Python3.8, 3.9 and 3.10. 47 | - Add custom properties support. #2 48 | - Add drop_rels in Package. #5 49 | - Add drop_rels in Part. #5 50 | - Add default NumberingPart. #4 51 | - Fix Python3.8+ **dict** TypeError. #6 52 | - Add some typehint. 53 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2022 Ethan St. Lee, https://github.com/lsaint 3 | Copyright (c) 2013 Steve Canny, https://github.com/scanny 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include HISTORY.md LICENSE README.md tox.ini 2 | graft docx/templates 3 | graft features 4 | graft tests 5 | graft docs 6 | prune docs/.build 7 | global-exclude .DS_Store 8 | global-exclude __pycache__ 9 | global-exclude *.py[co] 10 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | BEHAVE = behave 2 | MAKE = make 3 | PYTHON = python 4 | TWINE = twine 5 | SETUP = $(PYTHON) ./setup.py 6 | 7 | .PHONY: accept clean coverage docs readme register build test upload 8 | 9 | help: 10 | @echo "Please use \`make ' where is one or more of" 11 | @echo " accept run acceptance tests using behave" 12 | @echo " clean delete intermediate work product and start fresh" 13 | @echo " cleandocs delete intermediate documentation files" 14 | @echo " coverage run nosetests with coverage" 15 | @echo " docs generate documentation" 16 | @echo " opendocs open browser to local version of documentation" 17 | @echo " register update metadata (README.rst) on PyPI" 18 | @echo " build generate a source distribution into dist/" 19 | @echo " upload upload distribution tarball to PyPI" 20 | 21 | accept: 22 | $(BEHAVE) --stop 23 | 24 | clean: 25 | find . -type f -name \*.pyc -exec rm {} \; 26 | rm -rf dist *.egg-info .coverage .DS_Store 27 | 28 | cleandocs: 29 | $(MAKE) -C docs clean 30 | 31 | coverage: 32 | pytest --cov-report term-missing --cov=docx tests/ 33 | 34 | docs: 35 | $(MAKE) -C docs html 36 | 37 | opendocs: 38 | open docs/.build/html/index.html 39 | 40 | register: 41 | $(SETUP) register 42 | 43 | build: 44 | $(SETUP) sdist 45 | 46 | upload: 47 | $(TWINE) upload dist/* 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | oss 3 |

4 | 5 | _As a Brazilian jiu-jitsu player, OSS means anything and everything. It's a term used in BJJ that is a way of greeting and demonstrating respect to others._ 6 | 7 | **_python-docx-oss_** is a Python library for CRUD Microsoft Word (.docx) files. It fork from [python-docx](https://github.com/python-openxml/python-docx). 8 | 9 |

10 | PyPI 11 | 12 | Code style: black 13 | License: MIT 14 |

15 | 16 | --- 17 | 18 | ### FAQ 19 | 20 | **Q: What's New?** 21 | 22 | **A:** [HISTORY](https://github.com/lsaint/python-docx-oss/blob/master/HISTORY.md) 23 | 24 | --- 25 | 26 | More information is available in the [python-docx-oss documentation](https://python-docx-oss.readthedocs.io/en/latest/) 27 | 28 | This project is based on the original work by [Steve Canny](https://github.com/scanny) and has been modified by [Ethan St. Lee](https://github.com/lsaint). 29 | -------------------------------------------------------------------------------- /docs/_static/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsaint/python-docx-oss/fc5ed80737542afd073dc0e8f4276f1f7f96d732/docs/_static/.gitignore -------------------------------------------------------------------------------- /docs/_static/img/example-docx-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsaint/python-docx-oss/fc5ed80737542afd073dc0e8f4276f1f7f96d732/docs/_static/img/example-docx-01.png -------------------------------------------------------------------------------- /docs/_static/img/hdrftr-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsaint/python-docx-oss/fc5ed80737542afd073dc0e8f4276f1f7f96d732/docs/_static/img/hdrftr-01.png -------------------------------------------------------------------------------- /docs/_static/img/hdrftr-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsaint/python-docx-oss/fc5ed80737542afd073dc0e8f4276f1f7f96d732/docs/_static/img/hdrftr-02.png -------------------------------------------------------------------------------- /docs/_static/img/oss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsaint/python-docx-oss/fc5ed80737542afd073dc0e8f4276f1f7f96d732/docs/_static/img/oss.png -------------------------------------------------------------------------------- /docs/_templates/layout.html: -------------------------------------------------------------------------------- 1 | {% extends "!layout.html" %} 2 | {% block footer %} {{ super() }} 3 | 4 | 7 | 8 | {% endblock %} 9 | -------------------------------------------------------------------------------- /docs/_templates/sidebarlinks.html: -------------------------------------------------------------------------------- 1 |

Useful Links

2 | 7 | -------------------------------------------------------------------------------- /docs/_themes/armstrong/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Bay Citizen & Texas Tribune 2 | 3 | Original ReadTheDocs.org code 4 | Copyright (c) 2010 Charles Leifer, Eric Holscher, Bobby Grace 5 | 6 | Permission is hereby granted, free of charge, to any person 7 | obtaining a copy of this software and associated documentation 8 | files (the "Software"), to deal in the Software without 9 | restriction, including without limitation the rights to use, 10 | copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following 13 | conditions: 14 | 15 | The above copyright notice and this permission notice shall be 16 | included in all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | OTHER DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /docs/_themes/armstrong/rtd-themes.conf: -------------------------------------------------------------------------------- 1 | [theme] 2 | inherit = default 3 | stylesheet = rtd.css 4 | pygment_style = default 5 | show_sphinx = False 6 | 7 | [options] 8 | show_rtd = True 9 | 10 | white = #ffffff 11 | almost_white = #f8f8f8 12 | barely_white = #f2f2f2 13 | dirty_white = #eeeeee 14 | almost_dirty_white = #e6e6e6 15 | dirtier_white = #dddddd 16 | lighter_gray = #cccccc 17 | gray_a = #aaaaaa 18 | gray_9 = #999999 19 | light_gray = #888888 20 | gray_7 = #777777 21 | gray = #666666 22 | dark_gray = #444444 23 | gray_2 = #222222 24 | black = #111111 25 | light_color = #e8ecef 26 | light_medium_color = #DDEAF0 27 | medium_color = #8ca1af 28 | medium_color_link = #86989b 29 | medium_color_link_hover = #a6b8bb 30 | dark_color = #465158 31 | 32 | h1 = #000000 33 | h2 = #465158 34 | h3 = #6c818f 35 | 36 | link_color = #444444 37 | link_color_decoration = #CCCCCC 38 | 39 | medium_color_hover = #697983 40 | green_highlight = #8ecc4c 41 | 42 | 43 | positive_dark = #609060 44 | positive_medium = #70a070 45 | positive_light = #e9ffe9 46 | 47 | negative_dark = #900000 48 | negative_medium = #b04040 49 | negative_light = #ffe9e9 50 | negative_text = #c60f0f 51 | 52 | ruler = #abc 53 | 54 | viewcode_bg = #f4debf 55 | viewcode_border = #ac9 56 | 57 | highlight = #ffe080 58 | 59 | code_background = #eeeeee 60 | 61 | background = #465158 62 | background_link = #ffffff 63 | background_link_half = #ffffff 64 | background_text = #eeeeee 65 | background_text_link = #86989b 66 | -------------------------------------------------------------------------------- /docs/_themes/armstrong/theme.conf: -------------------------------------------------------------------------------- 1 | [theme] 2 | inherit = default 3 | stylesheet = rtd.css 4 | pygment_style = default 5 | show_sphinx = False 6 | 7 | [options] 8 | show_rtd = True 9 | 10 | white = #ffffff 11 | almost_white = #f8f8f8 12 | barely_white = #f2f2f2 13 | dirty_white = #eeeeee 14 | almost_dirty_white = #e6e6e6 15 | dirtier_white = #dddddd 16 | lighter_gray = #cccccc 17 | gray_a = #aaaaaa 18 | gray_9 = #999999 19 | light_gray = #888888 20 | gray_7 = #777777 21 | gray = #666666 22 | dark_gray = #444444 23 | gray_2 = #222222 24 | black = #111111 25 | light_color = #e8ecef 26 | light_medium_color = #DDEAF0 27 | medium_color = #8ca1af 28 | medium_color_link = #86989b 29 | medium_color_link_hover = #a6b8bb 30 | dark_color = #465158 31 | 32 | h1 = #000000 33 | h2 = #465158 34 | h3 = #6c818f 35 | 36 | link_color = #444444 37 | link_color_decoration = #CCCCCC 38 | 39 | medium_color_hover = #697983 40 | green_highlight = #8ecc4c 41 | 42 | 43 | positive_dark = #609060 44 | positive_medium = #70a070 45 | positive_light = #e9ffe9 46 | 47 | negative_dark = #900000 48 | negative_medium = #b04040 49 | negative_light = #ffe9e9 50 | negative_text = #c60f0f 51 | 52 | ruler = #abc 53 | 54 | viewcode_bg = #f4debf 55 | viewcode_border = #ac9 56 | 57 | highlight = #ffe080 58 | 59 | code_background = #eeeeee 60 | 61 | background = #465158 62 | background_link = #ffffff 63 | background_link_half = #ffffff 64 | background_text = #eeeeee 65 | background_text_link = #86989b 66 | -------------------------------------------------------------------------------- /docs/api/dml.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _dml_api: 3 | 4 | DrawingML objects 5 | ================= 6 | 7 | Low-level drawing elements like color that appear in various document 8 | contexts. 9 | 10 | 11 | |ColorFormat| objects 12 | --------------------- 13 | 14 | .. autoclass:: docx.dml.color.ColorFormat() 15 | :members: 16 | :undoc-members: 17 | -------------------------------------------------------------------------------- /docs/api/enum/MsoColorType.rst: -------------------------------------------------------------------------------- 1 | .. _MsoColorType: 2 | 3 | ``MSO_COLOR_TYPE`` 4 | ================== 5 | 6 | Specifies the color specification scheme 7 | 8 | Example:: 9 | 10 | from docx.enum.dml import MSO_COLOR_TYPE 11 | 12 | assert font.color.type == MSO_COLOR_TYPE.THEME 13 | 14 | ---- 15 | 16 | RGB 17 | Color is specified by an |RGBColor| value. 18 | 19 | THEME 20 | Color is one of the preset theme colors. 21 | 22 | AUTO 23 | Color is determined automatically be the application. 24 | -------------------------------------------------------------------------------- /docs/api/enum/MsoThemeColorIndex.rst: -------------------------------------------------------------------------------- 1 | .. _MsoThemeColorIndex: 2 | 3 | ``MSO_THEME_COLOR_INDEX`` 4 | ========================= 5 | 6 | Indicates the Office theme color, one of those shown in the color gallery on 7 | the formatting ribbon. 8 | 9 | Alias: ``MSO_THEME_COLOR`` 10 | 11 | Example:: 12 | 13 | from docx.enum.dml import MSO_THEME_COLOR 14 | 15 | font.color.theme_color = MSO_THEME_COLOR.ACCENT_1 16 | 17 | ---- 18 | 19 | NOT_THEME_COLOR 20 | Indicates the color is not a theme color. 21 | 22 | ACCENT_1 23 | Specifies the Accent 1 theme color. 24 | 25 | ACCENT_2 26 | Specifies the Accent 2 theme color. 27 | 28 | ACCENT_3 29 | Specifies the Accent 3 theme color. 30 | 31 | ACCENT_4 32 | Specifies the Accent 4 theme color. 33 | 34 | ACCENT_5 35 | Specifies the Accent 5 theme color. 36 | 37 | ACCENT_6 38 | Specifies the Accent 6 theme color. 39 | 40 | BACKGROUND_1 41 | Specifies the Background 1 theme color. 42 | 43 | BACKGROUND_2 44 | Specifies the Background 2 theme color. 45 | 46 | DARK_1 47 | Specifies the Dark 1 theme color. 48 | 49 | DARK_2 50 | Specifies the Dark 2 theme color. 51 | 52 | FOLLOWED_HYPERLINK 53 | Specifies the theme color for a clicked hyperlink. 54 | 55 | HYPERLINK 56 | Specifies the theme color for a hyperlink. 57 | 58 | LIGHT_1 59 | Specifies the Light 1 theme color. 60 | 61 | LIGHT_2 62 | Specifies the Light 2 theme color. 63 | 64 | TEXT_1 65 | Specifies the Text 1 theme color. 66 | 67 | TEXT_2 68 | Specifies the Text 2 theme color. 69 | 70 | MIXED 71 | Indicates multiple theme colors are used. 72 | -------------------------------------------------------------------------------- /docs/api/enum/WdAlignParagraph.rst: -------------------------------------------------------------------------------- 1 | .. _WdParagraphAlignment: 2 | 3 | ``WD_PARAGRAPH_ALIGNMENT`` 4 | ========================== 5 | 6 | alias: **WD_ALIGN_PARAGRAPH** 7 | 8 | Specifies paragraph justification type. 9 | 10 | Example:: 11 | 12 | from docx.enum.text import WD_ALIGN_PARAGRAPH 13 | 14 | paragraph = document.add_paragraph() 15 | paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER 16 | 17 | ---- 18 | 19 | LEFT 20 | Left-aligned 21 | 22 | CENTER 23 | Center-aligned. 24 | 25 | RIGHT 26 | Right-aligned. 27 | 28 | JUSTIFY 29 | Fully justified. 30 | 31 | DISTRIBUTE 32 | Paragraph characters are distributed to fill the entire width of the 33 | paragraph. 34 | 35 | JUSTIFY_MED 36 | Justified with a medium character compression ratio. 37 | 38 | JUSTIFY_HI 39 | Justified with a high character compression ratio. 40 | 41 | JUSTIFY_LOW 42 | Justified with a low character compression ratio. 43 | 44 | THAI_JUSTIFY 45 | Justified according to Thai formatting layout. 46 | -------------------------------------------------------------------------------- /docs/api/enum/WdCellVerticalAlignment.rst: -------------------------------------------------------------------------------- 1 | .. _WdCellVerticalAlignment: 2 | 3 | ``WD_CELL_VERTICAL_ALIGNMENT`` 4 | ============================== 5 | 6 | alias: **WD_ALIGN_VERTICAL** 7 | 8 | Specifies the vertical alignment of text in one or more cells of a table. 9 | 10 | Example:: 11 | 12 | from docx.enum.table import WD_ALIGN_VERTICAL 13 | 14 | table = document.add_table(3, 3) 15 | table.cell(0, 0).vertical_alignment = WD_ALIGN_VERTICAL.BOTTOM 16 | 17 | ---- 18 | 19 | TOP 20 | Text is aligned to the top border of the cell. 21 | 22 | CENTER 23 | Text is aligned to the center of the cell. 24 | 25 | BOTTOM 26 | Text is aligned to the bottom border of the cell. 27 | 28 | BOTH 29 | This is an option in the OpenXml spec, but not in Word itself. It's not 30 | clear what Word behavior this setting produces. If you find out please let 31 | us know and we'll update this documentation. Otherwise, probably best to 32 | avoid this option. 33 | -------------------------------------------------------------------------------- /docs/api/enum/WdColorIndex.rst: -------------------------------------------------------------------------------- 1 | .. _WdColorIndex: 2 | 3 | ``WD_COLOR_INDEX`` 4 | ================== 5 | 6 | alias: **WD_COLOR** 7 | 8 | Specifies a standard preset color to apply. Used for font highlighting and 9 | perhaps other applications. 10 | 11 | ---- 12 | 13 | AUTO 14 | Automatic color. Default; usually black. 15 | 16 | BLACK 17 | Black color. 18 | 19 | BLUE 20 | Blue color 21 | 22 | BRIGHT_GREEN 23 | Bright green color. 24 | 25 | DARK_BLUE 26 | Dark blue color. 27 | 28 | DARK_RED 29 | Dark red color. 30 | 31 | DARK_YELLOW 32 | Dark yellow color. 33 | 34 | GRAY_25 35 | 25% shade of gray color. 36 | 37 | GRAY_50 38 | 50% shade of gray color. 39 | 40 | GREEN 41 | Green color. 42 | 43 | PINK 44 | Pink color. 45 | 46 | RED 47 | Red color. 48 | 49 | TEAL 50 | Teal color. 51 | 52 | TURQUOISE 53 | Turquoise color. 54 | 55 | VIOLET 56 | Violet color. 57 | 58 | WHITE 59 | White color. 60 | 61 | YELLOW 62 | Yellow color. 63 | -------------------------------------------------------------------------------- /docs/api/enum/WdLineSpacing.rst: -------------------------------------------------------------------------------- 1 | .. _WdLineSpacing: 2 | 3 | ``WD_LINE_SPACING`` 4 | =================== 5 | 6 | Specifies a line spacing format to be applied to a paragraph. 7 | 8 | Example:: 9 | 10 | from docx.enum.text import WD_LINE_SPACING 11 | 12 | paragraph = document.add_paragraph() 13 | paragraph.paragraph_format.line_spacing_rule = WD_LINE_SPACING.EXACTLY 14 | 15 | ---- 16 | 17 | ONE_POINT_FIVE 18 | Space-and-a-half line spacing. 19 | 20 | AT_LEAST 21 | Line spacing is always at least the specified amount. The amount is 22 | specified separately. 23 | 24 | DOUBLE 25 | Double spaced. 26 | 27 | EXACTLY 28 | Line spacing is exactly the specified amount. The amount is specified 29 | separately. 30 | 31 | MULTIPLE 32 | Line spacing is specified as a multiple of line heights. Changing the font 33 | size will change the line spacing proportionately. 34 | 35 | SINGLE 36 | Single spaced (default). 37 | -------------------------------------------------------------------------------- /docs/api/enum/WdOrientation.rst: -------------------------------------------------------------------------------- 1 | .. _WdOrientation: 2 | 3 | ``WD_ORIENTATION`` 4 | ================== 5 | 6 | alias: **WD_ORIENT** 7 | 8 | Specifies the page layout orientation. 9 | 10 | Example:: 11 | 12 | from docx.enum.section import WD_ORIENT 13 | 14 | section = document.sections[-1] 15 | section.orientation = WD_ORIENT.LANDSCAPE 16 | 17 | ---- 18 | 19 | PORTRAIT 20 | Portrait orientation. 21 | 22 | LANDSCAPE 23 | Landscape orientation. 24 | -------------------------------------------------------------------------------- /docs/api/enum/WdRowAlignment.rst: -------------------------------------------------------------------------------- 1 | .. _WdRowAlignment: 2 | 3 | ``WD_TABLE_ALIGNMENT`` 4 | ====================== 5 | 6 | Specifies table justification type. 7 | 8 | Example:: 9 | 10 | from docx.enum.table import WD_TABLE_ALIGNMENT 11 | 12 | table = document.add_table(3, 3) 13 | table.alignment = WD_TABLE_ALIGNMENT.CENTER 14 | 15 | ---- 16 | 17 | LEFT 18 | Left-aligned 19 | 20 | CENTER 21 | Center-aligned. 22 | 23 | RIGHT 24 | Right-aligned. 25 | -------------------------------------------------------------------------------- /docs/api/enum/WdRowHeightRule.rst: -------------------------------------------------------------------------------- 1 | .. _WdRowHeightRule: 2 | 3 | ``WD_ROW_HEIGHT_RULE`` 4 | ====================== 5 | 6 | alias: **WD_ROW_HEIGHT** 7 | 8 | Specifies the rule for determining the height of a table row 9 | 10 | Example:: 11 | 12 | from docx.enum.table import WD_ROW_HEIGHT_RULE 13 | 14 | table = document.add_table(3, 3) 15 | table.rows[0].height_rule = WD_ROW_HEIGHT_RULE.EXACTLY 16 | 17 | ---- 18 | 19 | AUTO 20 | The row height is adjusted to accommodate the tallest value in the row. 21 | 22 | AT_LEAST 23 | The row height is at least a minimum specified value. 24 | 25 | EXACTLY 26 | The row height is an exact value. 27 | -------------------------------------------------------------------------------- /docs/api/enum/WdSectionStart.rst: -------------------------------------------------------------------------------- 1 | .. _WdSectionStart: 2 | 3 | ``WD_SECTION_START`` 4 | ==================== 5 | 6 | alias: **WD_SECTION** 7 | 8 | Specifies the start type of a section break. 9 | 10 | Example:: 11 | 12 | from docx.enum.section import WD_SECTION 13 | 14 | section = document.sections[0] 15 | section.start_type = WD_SECTION.NEW_PAGE 16 | 17 | ---- 18 | 19 | CONTINUOUS 20 | Continuous section break. 21 | 22 | NEW_COLUMN 23 | New column section break. 24 | 25 | NEW_PAGE 26 | New page section break. 27 | 28 | EVEN_PAGE 29 | Even pages section break. 30 | 31 | ODD_PAGE 32 | Section begins on next odd page. 33 | -------------------------------------------------------------------------------- /docs/api/enum/WdStyleType.rst: -------------------------------------------------------------------------------- 1 | .. _WdStyleType: 2 | 3 | ``WD_STYLE_TYPE`` 4 | ================= 5 | 6 | Specifies one of the four style types: paragraph, character, list, or 7 | table. 8 | 9 | Example:: 10 | 11 | from docx import Document 12 | from docx.enum.style import WD_STYLE_TYPE 13 | 14 | styles = Document().styles 15 | assert styles[0].type == WD_STYLE_TYPE.PARAGRAPH 16 | 17 | ---- 18 | 19 | CHARACTER 20 | Character style. 21 | 22 | LIST 23 | List style. 24 | 25 | PARAGRAPH 26 | Paragraph style. 27 | 28 | TABLE 29 | Table style. 30 | -------------------------------------------------------------------------------- /docs/api/enum/WdTabAlignment.rst: -------------------------------------------------------------------------------- 1 | .. _WdTabAlignment: 2 | 3 | ``WD_TAB_ALIGNMENT`` 4 | ==================== 5 | 6 | Specifies the tab stop alignment to apply. 7 | 8 | ---- 9 | 10 | LEFT 11 | Left-aligned. 12 | 13 | CENTER 14 | Center-aligned. 15 | 16 | RIGHT 17 | Right-aligned. 18 | 19 | DECIMAL 20 | Decimal-aligned. 21 | 22 | BAR 23 | Bar-aligned. 24 | 25 | LIST 26 | List-aligned. (deprecated) 27 | 28 | CLEAR 29 | Clear an inherited tab stop. 30 | 31 | END 32 | Right-aligned. (deprecated) 33 | 34 | NUM 35 | Left-aligned. (deprecated) 36 | 37 | START 38 | Left-aligned. (deprecated) 39 | -------------------------------------------------------------------------------- /docs/api/enum/WdTabLeader.rst: -------------------------------------------------------------------------------- 1 | .. _WdTabLeader: 2 | 3 | ``WD_TAB_LEADER`` 4 | ================= 5 | 6 | Specifies the character to use as the leader with formatted tabs. 7 | 8 | ---- 9 | 10 | SPACES 11 | Spaces. Default. 12 | 13 | DOTS 14 | Dots. 15 | 16 | DASHES 17 | Dashes. 18 | 19 | LINES 20 | Double lines. 21 | 22 | HEAVY 23 | A heavy line. 24 | 25 | MIDDLE_DOT 26 | A vertically-centered dot. 27 | -------------------------------------------------------------------------------- /docs/api/enum/WdTableDirection.rst: -------------------------------------------------------------------------------- 1 | .. _WdTableDirection: 2 | 3 | ``WD_TABLE_DIRECTION`` 4 | ====================== 5 | 6 | Specifies the direction in which an application orders cells in the 7 | specified table or row. 8 | 9 | Example:: 10 | 11 | from docx.enum.table import WD_TABLE_DIRECTION 12 | 13 | table = document.add_table(3, 3) 14 | table.direction = WD_TABLE_DIRECTION.RTL 15 | 16 | ---- 17 | 18 | LTR 19 | The table or row is arranged with the first column in the leftmost 20 | position. 21 | 22 | RTL 23 | The table or row is arranged with the first column in the rightmost 24 | position. 25 | -------------------------------------------------------------------------------- /docs/api/enum/WdUnderline.rst: -------------------------------------------------------------------------------- 1 | .. _WdUnderline: 2 | 3 | ``WD_UNDERLINE`` 4 | ================ 5 | 6 | Specifies the style of underline applied to a run of characters. 7 | 8 | ---- 9 | 10 | NONE 11 | No underline. This setting overrides any inherited underline value, so can 12 | be used to remove underline from a run that inherits underlining from its 13 | containing paragraph. Note this is not the same as assigning |None| to 14 | Run.underline. |None| is a valid assignment value, but causes the run to 15 | inherit its underline value. Assigning ``WD_UNDERLINE.NONE`` causes 16 | underlining to be unconditionally turned off. 17 | 18 | SINGLE 19 | A single line. Note that this setting is write-only in the sense that 20 | |True| (rather than ``WD_UNDERLINE.SINGLE``) is returned for a run having 21 | this setting. 22 | 23 | WORDS 24 | Underline individual words only. 25 | 26 | DOUBLE 27 | A double line. 28 | 29 | DOTTED 30 | Dots. 31 | 32 | THICK 33 | A single thick line. 34 | 35 | DASH 36 | Dashes. 37 | 38 | DOT_DASH 39 | Alternating dots and dashes. 40 | 41 | DOT_DOT_DASH 42 | An alternating dot-dot-dash pattern. 43 | 44 | WAVY 45 | A single wavy line. 46 | 47 | DOTTED_HEAVY 48 | Heavy dots. 49 | 50 | DASH_HEAVY 51 | Heavy dashes. 52 | 53 | DOT_DASH_HEAVY 54 | Alternating heavy dots and heavy dashes. 55 | 56 | DOT_DOT_DASH_HEAVY 57 | An alternating heavy dot-dot-dash pattern. 58 | 59 | WAVY_HEAVY 60 | A heavy wavy line. 61 | 62 | DASH_LONG 63 | Long dashes. 64 | 65 | WAVY_DOUBLE 66 | A double wavy line. 67 | 68 | DASH_LONG_HEAVY 69 | Long heavy dashes. 70 | -------------------------------------------------------------------------------- /docs/api/enum/index.rst: -------------------------------------------------------------------------------- 1 | 2 | Enumerations 3 | ============ 4 | 5 | Documentation for the various enumerations used for |docx| property settings 6 | can be found here: 7 | 8 | .. toctree:: 9 | :titlesonly: 10 | 11 | MsoColorType 12 | MsoThemeColorIndex 13 | WdAlignParagraph 14 | WdBuiltinStyle 15 | WdCellVerticalAlignment 16 | WdColorIndex 17 | WdLineSpacing 18 | WdOrientation 19 | WdRowAlignment 20 | WdRowHeightRule 21 | WdSectionStart 22 | WdStyleType 23 | WdTabAlignment 24 | WdTabLeader 25 | WdTableDirection 26 | WdUnderline 27 | -------------------------------------------------------------------------------- /docs/api/section.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _section_api: 3 | 4 | 5 | Section objects 6 | =============== 7 | 8 | Provides access to section properties such as margins and page orientation. 9 | 10 | 11 | |Sections| objects 12 | ------------------ 13 | 14 | .. currentmodule:: docx.section 15 | 16 | .. autoclass:: Sections 17 | :members: 18 | 19 | 20 | |Section| objects 21 | ----------------- 22 | 23 | 24 | .. autoclass:: Section 25 | :members: 26 | 27 | 28 | |_Header| and |_Footer| objects 29 | ------------------------------- 30 | 31 | 32 | .. autoclass:: _Header() 33 | :inherited-members: 34 | :members: 35 | :exclude-members: part 36 | 37 | 38 | .. autoclass:: _Footer() 39 | :inherited-members: 40 | :members: 41 | :exclude-members: part 42 | -------------------------------------------------------------------------------- /docs/api/settings.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _settings_api: 3 | 4 | Document |Settings| objects 5 | --------------------------- 6 | 7 | .. currentmodule:: docx.settings 8 | 9 | .. autoclass:: Settings() 10 | :members: 11 | :inherited-members: 12 | :exclude-members: 13 | part 14 | -------------------------------------------------------------------------------- /docs/api/shape.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _shape_api: 3 | 4 | Shape-related objects 5 | ===================== 6 | 7 | .. currentmodule:: docx.shape 8 | 9 | 10 | |InlineShapes| objects 11 | ---------------------- 12 | 13 | .. autoclass:: InlineShapes 14 | :members: 15 | :exclude-members: add_picture 16 | 17 | 18 | |InlineShape| objects 19 | --------------------- 20 | 21 | The ``width`` and ``height`` property of |InlineShape| provide a length object 22 | that is an instance of |Length|. These instances behave like an int, but also 23 | have built-in units conversion properties, e.g.:: 24 | 25 | >>> inline_shape.height 26 | 914400 27 | >>> inline_shape.height.inches 28 | 1.0 29 | 30 | .. autoclass:: InlineShape 31 | :members: height, type, width 32 | -------------------------------------------------------------------------------- /docs/api/shared.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _shared_api: 3 | 4 | Shared classes 5 | ============== 6 | 7 | .. currentmodule:: docx.shared 8 | 9 | 10 | Length objects 11 | -------------- 12 | 13 | Length values in |docx| are expressed as a standardized |Length| value object. 14 | |Length| is a subclass of |int|, having all the behavior of an |int|. In 15 | addition, it has built-in units conversion properties, e.g.:: 16 | 17 | >>> inline_shape.height 18 | 914400 19 | >>> inline_shape.height.inches 20 | 1.0 21 | 22 | Length objects are constructed using a selection of convenience constructors, 23 | allowing values to be expressed in the units most appropriate to the context. 24 | 25 | .. autoclass:: Length 26 | :members: 27 | :member-order: bysource 28 | 29 | .. autoclass:: Inches 30 | :members: 31 | 32 | .. autoclass:: Cm 33 | :members: 34 | 35 | .. autoclass:: Mm 36 | :members: 37 | 38 | .. autoclass:: Pt 39 | :members: 40 | 41 | .. autoclass:: Twips 42 | :members: 43 | 44 | .. autoclass:: Emu 45 | :members: 46 | 47 | 48 | |RGBColor| objects 49 | ------------------ 50 | 51 | .. autoclass:: RGBColor(r, g, b) 52 | :members: 53 | :undoc-members: 54 | 55 | *r*, *g*, and *b* are each an integer in the range 0-255 inclusive. Using 56 | the hexidecimal integer notation, e.g. `0x42` may enhance readability 57 | where hex RGB values are in use:: 58 | 59 | >>> lavender = RGBColor(0xff, 0x99, 0xcc) 60 | -------------------------------------------------------------------------------- /docs/api/table.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _table_api: 3 | 4 | Table objects 5 | ================ 6 | 7 | Table objects are constructed using the ``add_table()`` method on |Document|. 8 | 9 | 10 | .. currentmodule:: docx.table 11 | 12 | 13 | |Table| objects 14 | --------------- 15 | 16 | .. autoclass:: Table 17 | :members: 18 | :exclude-members: table 19 | 20 | 21 | |_Cell| objects 22 | ------------------------ 23 | 24 | .. autoclass:: _Cell 25 | :members: 26 | 27 | 28 | |_Row| objects 29 | -------------- 30 | 31 | .. autoclass:: _Row 32 | :members: 33 | 34 | 35 | |_Column| objects 36 | ----------------- 37 | 38 | .. autoclass:: _Column 39 | :members: 40 | 41 | 42 | |_Rows| objects 43 | --------------- 44 | 45 | .. autoclass:: _Rows 46 | :members: 47 | 48 | 49 | |_Columns| objects 50 | ------------------ 51 | 52 | .. autoclass:: _Columns 53 | :members: 54 | -------------------------------------------------------------------------------- /docs/api/text.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _text_api: 3 | 4 | Text-related objects 5 | ==================== 6 | 7 | 8 | |Paragraph| objects 9 | ------------------- 10 | 11 | .. autoclass:: docx.text.paragraph.Paragraph() 12 | :members: 13 | 14 | 15 | |ParagraphFormat| objects 16 | ------------------------- 17 | 18 | .. autoclass:: docx.text.parfmt.ParagraphFormat() 19 | :members: 20 | 21 | 22 | |Run| objects 23 | ------------- 24 | 25 | .. autoclass:: docx.text.run.Run() 26 | :members: 27 | 28 | 29 | |Font| objects 30 | -------------- 31 | 32 | .. autoclass:: docx.text.run.Font() 33 | :members: 34 | 35 | 36 | |TabStop| objects 37 | ----------------- 38 | 39 | .. autoclass:: docx.text.tabstops.TabStop() 40 | :members: 41 | 42 | 43 | |TabStops| objects 44 | ------------------ 45 | 46 | .. autoclass:: docx.text.tabstops.TabStops() 47 | :members: clear_all 48 | 49 | .. automethod:: docx.text.tabstops.TabStops.add_tab_stop(position, alignment=WD_TAB_ALIGNMENT.LEFT, leader=WD_TAB_LEADER.SPACES) 50 | -------------------------------------------------------------------------------- /docs/dev/analysis/features/text/index.rst: -------------------------------------------------------------------------------- 1 | 2 | Text 3 | ==== 4 | 5 | .. toctree:: 6 | :titlesonly: 7 | 8 | tab-stops 9 | font-highlight-color 10 | paragraph-format 11 | font 12 | font-color 13 | underline 14 | run-content 15 | breaks 16 | -------------------------------------------------------------------------------- /docs/dev/analysis/index.rst: -------------------------------------------------------------------------------- 1 | 2 | Analysis 3 | ======== 4 | 5 | Documentation of studies undertaken in support of API and code design. 6 | 7 | Feature Analysis 8 | ---------------- 9 | 10 | .. toctree:: 11 | :titlesonly: 12 | 13 | features/header 14 | features/settings 15 | features/text/index 16 | features/table/index 17 | features/styles/index 18 | features/shapes/index 19 | features/coreprops 20 | features/numbering 21 | features/sections 22 | 23 | 24 | Schema Analysis 25 | --------------- 26 | 27 | Collected bits and pieces from the XML Schema docs, MSDN web pages, and the 28 | ISO/IEC 29500 spec. 29 | 30 | .. toctree:: 31 | :maxdepth: 1 32 | 33 | schema/ct_document 34 | schema/ct_body 35 | schema/ct_p 36 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | lxml>=4.6.5 2 | sphinx-book-theme 3 | -------------------------------------------------------------------------------- /docs/user/api-concepts.rst: -------------------------------------------------------------------------------- 1 | 2 | API basics 3 | ========== 4 | 5 | The API for |docx| is designed to make doing simple things simple, while 6 | allowing more complex results to be achieved with a modest and incremental 7 | investment of understanding. 8 | 9 | It's possible to create a basic document using only a single object, the 10 | |api-Document| object returned when opening a file. The methods on 11 | |api-Document| allow *block-level* objects to be added to the end of the 12 | document. Block-level objects include paragraphs, inline pictures, and tables. 13 | Headings, bullets, and numbered lists are simply paragraphs with a particular 14 | style applied. 15 | 16 | In this way, a document can be "written" from top to bottom, roughly like 17 | a person would if they knew exactly what they wanted to say This basic use 18 | case, where content is always added to the end of the document, is expected to 19 | account for perhaps 80% of actual use cases, so it's a priority to make it as 20 | simple as possible without compromising the power of the overall API. 21 | 22 | 23 | Inline objects 24 | -------------- 25 | 26 | Each block-level method on |api-Document|, such as ``add_paragraph()``, returns 27 | the block-level object created. Often the reference is unneeded; but when 28 | inline objects must be created individually, you'll need the block-item 29 | reference to do it. 30 | 31 | ... add example here as API solidifies ... 32 | -------------------------------------------------------------------------------- /docs/user/custom-properties.rst: -------------------------------------------------------------------------------- 1 | .. _custom_properties: 2 | 3 | Working with custom properties 4 | ============================== 5 | The custom properties can be accessed/modified by navigating to 6 | File menu --> Properties --> Advanced properties --> Customization in Word. 7 | These properties are stored in the ``/docProps/custom.xml`` file. 8 | 9 | we can CRUD them via python-docx-oss:: 10 | 11 | from docx import Document 12 | document = Document() 13 | 14 | >>> print(document.custom_properties["not-exist-key"]) 15 | None 16 | 17 | >>> document.custom_properties["bjj"] = "oss" 18 | >>> print(document.custom_properties["bjj"]) 19 | oss 20 | 21 | >>> document.custom_properties["bjj"] = "rnc" 22 | >>> print(document.custom_properties["bjj"]) 23 | rnc 24 | 25 | >>> document.custom_properties["bjj"] = None 26 | >>> print(document.custom_properties["bjj"]) 27 | None 28 | 29 | Be careful, users also can see & modify these properties in Word. 30 | Use :ref:`customXml` if you need them hidden. 31 | -------------------------------------------------------------------------------- /docs/user/install.rst: -------------------------------------------------------------------------------- 1 | .. _install: 2 | 3 | Installing 4 | ========== 5 | 6 | |docx| is hosted on `PyPI `_, 7 | so installation is relatively simple, and just 8 | depends on what installation utilities you have installed. 9 | 10 | |docx| may be installed with ``pip`` if you have it available:: 11 | 12 | pip install python-docx-oss 13 | 14 | It can be installed manually by downloading the distribution from PyPI, unpacking the tarball, 15 | and running ``setup.py``:: 16 | 17 | tar xvzf python-docx-{version}.tar.gz 18 | cd python-docx-oss-{version} 19 | python setup.py install 20 | 21 | |docx| depends on the ``lxml`` package. 22 | ``pip`` will take care of satisfying those dependencies for you, 23 | but if you use this last method you will need to install those yourself. 24 | 25 | 26 | Dependencies 27 | ------------ 28 | 29 | * Python >= 3.10 30 | * lxml >= 4.6.5 31 | -------------------------------------------------------------------------------- /docs/user/shapes.rst: -------------------------------------------------------------------------------- 1 | 2 | Understanding pictures and other shapes 3 | ======================================= 4 | 5 | Conceptually, Word documents have two *layers*, a *text layer* and a *drawing 6 | layer*. In the text layer, text objects are flowed from left to right and from 7 | top to bottom, starting a new page when the prior one is filled. In the drawing 8 | layer, drawing objects, called *shapes*, are placed at arbitrary positions. 9 | These are sometimes referred to as *floating* shapes. 10 | 11 | A picture is a shape that can appear in either the text or drawing layer. When 12 | it appears in the text layer it is called an *inline shape*, or more 13 | specifically, an *inline picture*. 14 | 15 | Inline shapes are treated like a big text character (a *character glyph*). The 16 | line height is increased to accomodate the shape and the shape is wrapped to 17 | a line it will fit on width-wise, just like text. Inserting text in front of it 18 | will cause it to move to the right. Often, a picture is placed in a paragraph 19 | by itself, but this is not required. It can have text before and after it in 20 | the paragraph in which it's placed. 21 | 22 | The ``Document.add_picture()`` method adds a specified picture 23 | to the end of the document in a paragraph of its own. However, by digging 24 | a little deeper into the API you can place text on either side of the picture 25 | in its paragraph, or both. 26 | 27 | If width and height are not specified in svg, the default size is *72px*. 28 | The ratio of width and height is kept the same as viewbox attribute. 29 | -------------------------------------------------------------------------------- /docx/api.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | """ 4 | Directly exposed API functions and classes, :func:`Document` for now. 5 | Provides a syntactically more convenient API for interacting with the 6 | OpcPackage graph. 7 | """ 8 | 9 | from __future__ import absolute_import, division, print_function 10 | 11 | import os 12 | 13 | from docx.opc.constants import CONTENT_TYPE as CT 14 | from docx.package import Package 15 | 16 | 17 | def Document(docx=None): 18 | """ 19 | Return a |Document| object loaded from *docx*, where *docx* can be 20 | either a path to a ``.docx`` file (a string) or a file-like object. If 21 | *docx* is missing or ``None``, the built-in default document "template" 22 | is loaded. 23 | """ 24 | docx = _default_docx_path() if docx is None else docx 25 | document_part = Package.open(docx).main_document_part 26 | if document_part.content_type != CT.WML_DOCUMENT_MAIN: 27 | tmpl = "file '%s' is not a Word file, content type is '%s'" 28 | raise ValueError(tmpl % (docx, document_part.content_type)) 29 | return document_part.document 30 | 31 | 32 | def _default_docx_path(): 33 | """ 34 | Return the path to the built-in default .docx package. 35 | """ 36 | _thisdir = os.path.split(__file__)[0] 37 | return os.path.join(_thisdir, "templates", "default.docx") 38 | -------------------------------------------------------------------------------- /docx/compat.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | """ 4 | Provides Python 2/3 compatibility objects 5 | """ 6 | 7 | from __future__ import absolute_import, division, print_function, unicode_literals 8 | 9 | import sys 10 | 11 | # =========================================================================== 12 | # Python 3 versions 13 | # =========================================================================== 14 | 15 | if sys.version_info >= (3, 0): 16 | 17 | from collections.abc import Sequence 18 | from io import BytesIO 19 | 20 | def is_string(obj): 21 | """Return True if *obj* is a string, False otherwise.""" 22 | return isinstance(obj, str) 23 | 24 | Unicode = str 25 | 26 | # =========================================================================== 27 | # Python 2 versions 28 | # =========================================================================== 29 | 30 | else: 31 | 32 | from collections import Sequence # noqa 33 | from StringIO import StringIO as BytesIO # noqa 34 | 35 | def is_string(obj): 36 | """Return True if *obj* is a string, False otherwise.""" 37 | return isinstance(obj, basestring) # noqa 38 | 39 | Unicode = unicode # noqa 40 | -------------------------------------------------------------------------------- /docx/dml/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsaint/python-docx-oss/fc5ed80737542afd073dc0e8f4276f1f7f96d732/docx/dml/__init__.py -------------------------------------------------------------------------------- /docx/enum/__init__.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | """ 4 | Enumerations used in python-docx 5 | """ 6 | 7 | from __future__ import absolute_import, print_function, unicode_literals 8 | 9 | 10 | class Enumeration(object): 11 | @classmethod 12 | def from_xml(cls, xml_val): 13 | return cls._xml_to_idx[xml_val] 14 | 15 | @classmethod 16 | def to_xml(cls, enum_val): 17 | return cls._idx_to_xml[enum_val] 18 | -------------------------------------------------------------------------------- /docx/enum/shape.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | """ 4 | Enumerations related to DrawingML shapes in WordprocessingML files 5 | """ 6 | 7 | from __future__ import absolute_import, print_function, unicode_literals 8 | 9 | 10 | class WD_INLINE_SHAPE_TYPE(object): 11 | """ 12 | Corresponds to WdInlineShapeType enumeration 13 | http://msdn.microsoft.com/en-us/library/office/ff192587.aspx 14 | """ 15 | 16 | CHART = 12 17 | LINKED_PICTURE = 4 18 | PICTURE = 3 19 | SMART_ART = 15 20 | NOT_IMPLEMENTED = -6 21 | 22 | 23 | WD_INLINE_SHAPE = WD_INLINE_SHAPE_TYPE 24 | -------------------------------------------------------------------------------- /docx/exceptions.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | """ 4 | Exceptions used with python-docx. 5 | 6 | The base exception class is PythonDocxError. 7 | """ 8 | 9 | 10 | class PythonDocxError(Exception): 11 | """ 12 | Generic error class. 13 | """ 14 | 15 | 16 | class InvalidSpanError(PythonDocxError): 17 | """ 18 | Raised when an invalid merge region is specified in a request to merge 19 | table cells. 20 | """ 21 | 22 | 23 | class InvalidXmlError(PythonDocxError): 24 | """ 25 | Raised when invalid XML is encountered, such as on attempt to access a 26 | missing required child element 27 | """ 28 | -------------------------------------------------------------------------------- /docx/image/__init__.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | """ 4 | Provides objects that can characterize image streams as to content type and 5 | size, as a required step in including them in a document. 6 | """ 7 | 8 | from __future__ import absolute_import, division, print_function, unicode_literals 9 | 10 | from docx.image.bmp import Bmp 11 | from docx.image.emf import Emf 12 | from docx.image.gif import Gif 13 | from docx.image.jpeg import Exif, Jfif 14 | from docx.image.png import Png 15 | from docx.image.svg import Svg 16 | from docx.image.tiff import Tiff 17 | 18 | 19 | SIGNATURES = ( 20 | # class, offset, signature_bytes 21 | (Png, 0, b"\x89PNG\x0D\x0A\x1A\x0A"), 22 | (Jfif, 6, b"JFIF"), 23 | (Exif, 6, b"Exif"), 24 | (Gif, 0, b"GIF87a"), 25 | (Gif, 0, b"GIF89a"), 26 | (Tiff, 0, b"MM\x00*"), # big-endian (Motorola) TIFF 27 | (Tiff, 0, b"II*\x00"), # little-endian (Intel) TIFF 28 | (Bmp, 0, b"BM"), 29 | (Emf, 0, b"\x01\x00\x00\x00"), 30 | (Svg, 0, b"= (3, 0): 16 | 17 | def cls_method_fn(cls, method_name): 18 | """ 19 | Return the function object associated with the method of *cls* having 20 | *method_name*. 21 | """ 22 | return getattr(cls, method_name) 23 | 24 | def is_string(obj): 25 | """ 26 | Return True if *obj* is a string, False otherwise. 27 | """ 28 | return isinstance(obj, str) 29 | 30 | 31 | # =========================================================================== 32 | # Python 2 versions 33 | # =========================================================================== 34 | 35 | else: 36 | 37 | def cls_method_fn(cls, method_name): 38 | """ 39 | Return the function object associated with the method of *cls* having 40 | *method_name*. 41 | """ 42 | unbound_method = getattr(cls, method_name) 43 | return unbound_method.__func__ 44 | 45 | def is_string(obj): 46 | """ 47 | Return True if *obj* is a string, False otherwise. 48 | """ 49 | return isinstance(obj, basestring) # noqa 50 | -------------------------------------------------------------------------------- /docx/opc/exceptions.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | """ 4 | Exceptions specific to python-opc 5 | 6 | The base exception class is OpcError. 7 | """ 8 | 9 | 10 | class OpcError(Exception): 11 | """ 12 | Base error class for python-opc 13 | """ 14 | 15 | 16 | class PackageNotFoundError(OpcError): 17 | """ 18 | Raised when a package cannot be found at the specified path. 19 | """ 20 | -------------------------------------------------------------------------------- /docx/opc/parts/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsaint/python-docx-oss/fc5ed80737542afd073dc0e8f4276f1f7f96d732/docx/opc/parts/__init__.py -------------------------------------------------------------------------------- /docx/opc/shared.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | """ 4 | Objects shared by opc modules. 5 | """ 6 | 7 | from __future__ import absolute_import, print_function, unicode_literals 8 | 9 | 10 | class CaseInsensitiveDict(dict): 11 | """ 12 | Mapping type that behaves like dict except that it matches without respect 13 | to the case of the key. E.g. cid['A'] == cid['a']. Note this is not 14 | general-purpose, just complete enough to satisfy opc package needs. It 15 | assumes str keys, and that it is created empty; keys passed in constructor 16 | are not accounted for 17 | """ 18 | 19 | def __contains__(self, key): 20 | return super(CaseInsensitiveDict, self).__contains__(key.lower()) 21 | 22 | def __getitem__(self, key): 23 | return super(CaseInsensitiveDict, self).__getitem__(key.lower()) 24 | 25 | def __setitem__(self, key, value): 26 | return super(CaseInsensitiveDict, self).__setitem__(key.lower(), value) 27 | 28 | 29 | def lazyproperty(f): 30 | """ 31 | @lazyprop decorator. Decorated method will be called only on first access 32 | to calculate a cached property value. After that, the cached value is 33 | returned. 34 | """ 35 | cache_attr_name = "_%s" % f.__name__ # like '_foobar' for prop 'foobar' 36 | docstring = f.__doc__ 37 | 38 | def get_prop_value(obj): 39 | try: 40 | return getattr(obj, cache_attr_name) 41 | except AttributeError: 42 | value = f(obj) 43 | setattr(obj, cache_attr_name, value) 44 | return value 45 | 46 | return property(get_prop_value, doc=docstring) 47 | -------------------------------------------------------------------------------- /docx/opc/spec.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | """ 4 | Provides mappings that embody aspects of the Open XML spec ISO/IEC 29500. 5 | """ 6 | 7 | from .constants import CONTENT_TYPE as CT 8 | 9 | 10 | default_content_types = ( 11 | ("bin", CT.PML_PRINTER_SETTINGS), 12 | ("bin", CT.SML_PRINTER_SETTINGS), 13 | ("bin", CT.WML_PRINTER_SETTINGS), 14 | ("bmp", CT.BMP), 15 | ("emf", CT.X_EMF), 16 | ("fntdata", CT.X_FONTDATA), 17 | ("gif", CT.GIF), 18 | ("jpe", CT.JPEG), 19 | ("jpeg", CT.JPEG), 20 | ("jpg", CT.JPEG), 21 | ("png", CT.PNG), 22 | ("rels", CT.OPC_RELATIONSHIPS), 23 | ("tif", CT.TIFF), 24 | ("tiff", CT.TIFF), 25 | ("wdp", CT.MS_PHOTO), 26 | ("wmf", CT.X_WMF), 27 | ("xlsx", CT.SML_SHEET), 28 | ("xml", CT.XML), 29 | ) 30 | -------------------------------------------------------------------------------- /docx/oxml/exceptions.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | """ 4 | Exceptions for oxml sub-package 5 | """ 6 | 7 | 8 | class XmlchemyError(Exception): 9 | """Generic error class.""" 10 | 11 | 12 | class InvalidXmlError(XmlchemyError): 13 | """ 14 | Raised when invalid XML is encountered, such as on attempt to access a 15 | missing required child element 16 | """ 17 | -------------------------------------------------------------------------------- /docx/oxml/text/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsaint/python-docx-oss/fc5ed80737542afd073dc0e8f4276f1f7f96d732/docx/oxml/text/__init__.py -------------------------------------------------------------------------------- /docx/parts/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsaint/python-docx-oss/fc5ed80737542afd073dc0e8f4276f1f7f96d732/docx/parts/__init__.py -------------------------------------------------------------------------------- /docx/parts/settings.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | """ 4 | |SettingsPart| and closely related objects 5 | """ 6 | 7 | from __future__ import absolute_import, division, print_function, unicode_literals 8 | 9 | import os 10 | 11 | from ..opc.constants import CONTENT_TYPE as CT 12 | from ..opc.packuri import PackURI 13 | from ..opc.part import XmlPart 14 | from ..oxml import parse_xml 15 | from ..settings import Settings 16 | 17 | 18 | class SettingsPart(XmlPart): 19 | """ 20 | Document-level settings part of a WordprocessingML (WML) package. 21 | """ 22 | 23 | @classmethod 24 | def default(cls, package): 25 | """ 26 | Return a newly created settings part, containing a default 27 | `w:settings` element tree. 28 | """ 29 | partname = PackURI("/word/settings.xml") 30 | content_type = CT.WML_SETTINGS 31 | element = parse_xml(cls._default_settings_xml()) 32 | return cls(partname, content_type, element, package) 33 | 34 | @property 35 | def settings(self): 36 | """ 37 | A |Settings| proxy object for the `w:settings` element in this part, 38 | containing the document-level settings for this document. 39 | """ 40 | return Settings(self.element) 41 | 42 | @classmethod 43 | def _default_settings_xml(cls): 44 | """ 45 | Return a bytestream containing XML for a default settings part. 46 | """ 47 | path = os.path.join( 48 | os.path.split(__file__)[0], "..", "templates", "default-settings.xml" 49 | ) 50 | with open(path, "rb") as f: 51 | xml_bytes = f.read() 52 | return xml_bytes 53 | -------------------------------------------------------------------------------- /docx/parts/styles.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | """ 4 | Provides StylesPart and related objects 5 | """ 6 | 7 | from __future__ import absolute_import, division, print_function, unicode_literals 8 | 9 | import os 10 | 11 | from ..opc.constants import CONTENT_TYPE as CT 12 | from ..opc.packuri import PackURI 13 | from ..opc.part import XmlPart 14 | from ..oxml import parse_xml 15 | from ..styles.styles import Styles 16 | 17 | 18 | class StylesPart(XmlPart): 19 | """ 20 | Proxy for the styles.xml part containing style definitions for a document 21 | or glossary. 22 | """ 23 | 24 | @classmethod 25 | def default(cls, package): 26 | """ 27 | Return a newly created styles part, containing a default set of 28 | elements. 29 | """ 30 | partname = PackURI("/word/styles.xml") 31 | content_type = CT.WML_STYLES 32 | element = parse_xml(cls._default_styles_xml()) 33 | return cls(partname, content_type, element, package) 34 | 35 | @property 36 | def styles(self): 37 | """ 38 | The |_Styles| instance containing the styles ( element 39 | proxies) for this styles part. 40 | """ 41 | return Styles(self.element) 42 | 43 | @classmethod 44 | def _default_styles_xml(cls): 45 | """ 46 | Return a bytestream containing XML for a default styles part. 47 | """ 48 | path = os.path.join( 49 | os.path.split(__file__)[0], "..", "templates", "default-styles.xml" 50 | ) 51 | with open(path, "rb") as f: 52 | xml_bytes = f.read() 53 | return xml_bytes 54 | -------------------------------------------------------------------------------- /docx/settings.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | """Settings object, providing access to document-level settings""" 4 | 5 | from __future__ import absolute_import, division, print_function, unicode_literals 6 | 7 | from docx.shared import ElementProxy 8 | 9 | 10 | class Settings(ElementProxy): 11 | """Provides access to document-level settings for a document. 12 | 13 | Accessed using the :attr:`.Document.settings` property. 14 | """ 15 | 16 | __slots__ = () 17 | 18 | @property 19 | def odd_and_even_pages_header_footer(self): 20 | """True if this document has distinct odd and even page headers and footers. 21 | 22 | Read/write. 23 | """ 24 | return self._element.evenAndOddHeaders_val 25 | 26 | @odd_and_even_pages_header_footer.setter 27 | def odd_and_even_pages_header_footer(self, value): 28 | self._element.evenAndOddHeaders_val = value 29 | -------------------------------------------------------------------------------- /docx/templates/default-docx-template/_rels/.rels: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /docx/templates/default-docx-template/customXml/_rels/item1.xml.rels: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /docx/templates/default-docx-template/customXml/item1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /docx/templates/default-docx-template/customXml/itemProps1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /docx/templates/default-docx-template/docProps/app.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 0 5 | 1 6 | 0 7 | 0 8 | Microsoft Macintosh Word 9 | 0 10 | 0 11 | 0 12 | false 13 | 14 | 15 | 16 | Title 17 | 18 | 19 | 1 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | false 31 | 0 32 | false 33 | 34 | false 35 | 14.0000 36 | 37 | -------------------------------------------------------------------------------- /docx/templates/default-docx-template/docProps/core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | python-docx 6 | 7 | generated by python-docx 8 | 9 | 1 10 | 2013-12-23T23:15:00Z 11 | 2013-12-23T23:15:00Z 12 | 13 | 14 | -------------------------------------------------------------------------------- /docx/templates/default-docx-template/docProps/thumbnail.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsaint/python-docx-oss/fc5ed80737542afd073dc0e8f4276f1f7f96d732/docx/templates/default-docx-template/docProps/thumbnail.jpeg -------------------------------------------------------------------------------- /docx/templates/default-docx-template/word/_rels/document.xml.rels: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /docx/templates/default-docx-template/word/document.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /docx/templates/default-docx-template/word/webSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /docx/templates/default-footer.xml: -------------------------------------------------------------------------------- 1 | 2 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /docx/templates/default-header.xml: -------------------------------------------------------------------------------- 1 | 2 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /docx/templates/default-numbering.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | -------------------------------------------------------------------------------- /docx/templates/default.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsaint/python-docx-oss/fc5ed80737542afd073dc0e8f4276f1f7f96d732/docx/templates/default.docx -------------------------------------------------------------------------------- /docx/text/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsaint/python-docx-oss/fc5ed80737542afd073dc0e8f4276f1f7f96d732/docx/text/__init__.py -------------------------------------------------------------------------------- /features/api-open-document.feature: -------------------------------------------------------------------------------- 1 | Feature: Open a document 2 | In order work on a document 3 | As a developer using python-docx 4 | I need a way to open a document 5 | 6 | 7 | Scenario: Open a specified document 8 | Given I have python-docx installed 9 | When I call docx.Document() with the path of a .docx file 10 | Then document is a Document object 11 | 12 | 13 | Scenario: Open the default document 14 | Given I have python-docx installed 15 | When I call docx.Document() with no arguments 16 | Then document is a Document object 17 | -------------------------------------------------------------------------------- /features/blk-add-paragraph.feature: -------------------------------------------------------------------------------- 1 | Feature: Add a paragraph of text 2 | In order to populate the text of a document 3 | As a developer using python-docx 4 | I need the ability to add a paragraph 5 | 6 | Scenario: Add a paragraph using low-level text API 7 | Given a document 8 | When I add a paragraph 9 | And I add a run to the paragraph 10 | And I add text to the run 11 | And I save the document 12 | Then the document contains the text I added 13 | -------------------------------------------------------------------------------- /features/blk-add-table.feature: -------------------------------------------------------------------------------- 1 | Feature: Add a table 2 | In order to fulfill a requirement for a table in a document 3 | As a developer using python-docx 4 | I need the ability to add a table 5 | 6 | Scenario: Access a table 7 | Given a document containing a table 8 | Then I can access the table 9 | 10 | Scenario: Add a table 11 | Given a document 12 | When I add a table 13 | Then the new table appears in the document 14 | -------------------------------------------------------------------------------- /features/cel-add-table.feature: -------------------------------------------------------------------------------- 1 | Feature: Add a table into a table cell 2 | In order to nest a table within a table cell 3 | As a developer using python-docx 4 | I need a way to add a table to a table cell 5 | 6 | 7 | Scenario: Add a table into a table cell 8 | Given a table cell 9 | When I add a 2 x 2 table into the first cell 10 | Then cell.tables[0] is a 2 x 2 table 11 | And the width of each column is 1.5375 inches 12 | And the width of each cell is 1.5375 inches 13 | -------------------------------------------------------------------------------- /features/cel-text.feature: -------------------------------------------------------------------------------- 1 | Feature: Set table cell text 2 | In order to quickly populate a table cell with regular text 3 | As a developer using python-docx 4 | I need the ability to set the text of a table cell 5 | 6 | Scenario: Set table cell text 7 | Given a table cell 8 | When I assign a string to the cell text attribute 9 | Then the cell contains the string I assigned 10 | -------------------------------------------------------------------------------- /features/doc-access-collections.feature: -------------------------------------------------------------------------------- 1 | Feature: Access document collections 2 | In order to operate on objects related to a document 3 | As a developer using python-docx 4 | I need a way to access each of the document's collections 5 | 6 | 7 | Scenario: Access the inline shapes collection of a document 8 | Given a document having inline shapes 9 | Then document.inline_shapes is an InlineShapes object 10 | 11 | 12 | Scenario: Access the paragraphs in the document body as a list 13 | Given a document containing three paragraphs 14 | Then document.paragraphs is a list containing three paragraphs 15 | 16 | 17 | Scenario: Access the section collection of a document 18 | Given a document having sections 19 | Then document.sections is a Sections object 20 | 21 | 22 | Scenario: Access the styles collection of a document 23 | Given a document having styles 24 | Then document.styles is a Styles object 25 | 26 | 27 | Scenario: Access the tables collection of a document 28 | Given a document having three tables 29 | Then document.tables is a list containing three tables 30 | -------------------------------------------------------------------------------- /features/doc-access-sections.feature: -------------------------------------------------------------------------------- 1 | Feature: Access document sections 2 | In order to operate on an individual section 3 | As a developer using python-docx 4 | I need access to each section in the section collection 5 | 6 | 7 | Scenario: Access section in section collection 8 | Given a section collection containing 3 sections 9 | Then len(sections) is 3 10 | And I can iterate over the sections 11 | And I can access a section by index 12 | -------------------------------------------------------------------------------- /features/doc-add-heading.feature: -------------------------------------------------------------------------------- 1 | Feature: Add a heading paragraph 2 | In order add a heading to a document 3 | As a developer using python-docx 4 | I need a way to add a heading with its text and level in a single step 5 | 6 | 7 | Scenario: Add a heading specifying only its text 8 | Given a document having built-in styles 9 | When I add a heading specifying only its text 10 | Then the style of the last paragraph is 'Heading 1' 11 | And the last paragraph contains the heading text 12 | 13 | 14 | Scenario Outline: Add a heading specifying level 15 | Given a document having built-in styles 16 | When I add a heading specifying level= 17 | Then the style of the last paragraph is '