Skip to main content

Render ppt like a jupyter notebook

Project description

DOCX Renderer

This package lets you run your Microsoft Word documents like a script. You can insert placeholders in the document and use either a Python function or an equivalent command-line tool to convert it into an output rendered document.

Documentation

Installation

pip install docx-renderer

Usage

Below is a simple example.

from docx_renderer import DOCXRenderer
p = DOCXRenderer("template.docx")

someval = "world!"
def mymethod(abc):
    return f"{abc} " * 5

p.render(
    "output.docx", 
    {
        "variable": someval, "mymethod": mymethod, "myimage": "is_it_worth.png"
    }
)

This will replace placeholders in the template document with the provided values.

Before

Before

After

After

You can define some functions within the document itself by writing Python code in the comments section. The variables and functions in this code can be used in the main document.

For example: write the following in one of the comments in the document.

```python
def myfunc(input):
    return input * 42
```

Now you can, for example, add the placeholder {{{myfunc(42)}}} in your document.

If the template document is a self-contained Python script (i.e., it does not require variable values and function definitions to be passed from outside), you can generate the output document directly from the command line using the following command.

docx-renderer input_template.docx output_file.docx

Placeholders

You can have placeholders for text, images, or tables. Placeholders can be added inside paragraphs or tables. All placeholders should be enclosed within a pair of triple braces ({{{ and }}}).

Text

Any placeholder which can be evaluated into a string can act as a text placeholder.

For example: {{{"hello " * 10/2}}} or {{{abs(-2)}}}

Image

If you have added :image() as a suffix to the Python statement, the renderer will try to convert the value of the Python statement to a file location and insert an image from that file location.

For example: {{{"c:\\temp\\myimage.png":image()}}}

Table

Tables are similar to images, but instead of a string, the Python statement should evaluate to a list of lists. Then you can add :table() as a suffix, and it will be converted to a table inside the document.

For example: {{{[["col1", "col2", "col3"],[1, 2, 3]]:table()}}} will render to

col1 col2 col3
1 2 3

Code in comments

You can write regular Python code in the comments section of the document but enclosed between ```python and ```.

For example: Add the following in a comment in the document.

```python
import numpy as np
myarr = np.array([[1, 2], [3, 4]])
```

And in the document, add the text {{{myarr:table()}}} and a paragraph with the text The determinant of the array is {{{np.linalg.det(myarr)}}}.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docx_renderer-0.1.0.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docx_renderer-0.1.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file docx_renderer-0.1.0.tar.gz.

File metadata

  • Download URL: docx_renderer-0.1.0.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for docx_renderer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 50437b601d69e6d1e02f1b856842fbc8fdfbbf04cf80c651f9940a1f212195c4
MD5 dd7299a026dfa29d0c97d9876179c368
BLAKE2b-256 b1350d0dd87758e24e57069f5d5e18091477cc151504192dd92d172b2a617f89

See more details on using hashes here.

Provenance

The following attestation bundles were made for docx_renderer-0.1.0.tar.gz:

Publisher: python-publish.yml on idling-mind/docx_renderer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file docx_renderer-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: docx_renderer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for docx_renderer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cf2ea3e781f5d940bb99d654ac57375b2719c64325c419d463481bb8cf2f10d2
MD5 95d4d5b17cfea115ccefb2d832939583
BLAKE2b-256 622f415d8baf5d46bba26475ca6fde9212d6cde155169c17bd7114a44906a0f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for docx_renderer-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on idling-mind/docx_renderer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page