read_word_charts

read_word_charts(path)

Read every chart in a Word document.

Parameters

Name Type Description Default
path str, os.PathLike or binary file object A .docx or .docm document, or a .dotx template, or an open binary stream of one, such as an uploaded file. required

Returns

Name Type Description
list of WordChart One per chart maidr can read in the document’s body, in reading order: inline and floating charts, and charts in tables and text boxes. Pass one to :func:maidr.show, :func:maidr.render or :func:maidr.save_html.

Raises

Name Type Description
NotADocumentError If the file is not a .docx document: an older .doc file, an Excel workbook or a PowerPoint presentation, or a Strict Open XML document. A ValueError.

Notes

Every chart type :func:maidr.read_excel_charts reads is read, and read the same way: a chart in a document is the same chart part, with the copy of its values Word drew and its data in a workbook embedded in the document. That workbook is read only for what the copy leaves out, such as the header cell that names a category axis with no title. Each chart is drawn in the colors of the document’s theme. Charts in headers, footers, footnotes and comments are not read.

Examples

>>> import maidr
>>> for chart in maidr.read_word_charts("report.docx"):
...     maidr.save_html(chart, f"chart-{chart.number}.html")