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 as regular text. 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

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.2.0.tar.gz (10.5 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.2.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: docx_renderer-0.2.0.tar.gz
  • Upload date:
  • Size: 10.5 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.2.0.tar.gz
Algorithm Hash digest
SHA256 356e1ca2454f24abad1669d238bba9ba91551ae7a0db43abf34e5b7e8ede6c9b
MD5 e2de295b687cff127a14011852b67742
BLAKE2b-256 f306a712d631054ac8753a3a87317a3e7cc99026457f82c758890615593a895a

See more details on using hashes here.

Provenance

The following attestation bundles were made for docx_renderer-0.2.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: docx_renderer-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0ce4e9b9d71554ea4f19f084173416f7f8dea155297ab23c5112b1d26cc500a6
MD5 a055f21bc6b6b243dcc1a19fcd1554bd
BLAKE2b-256 65ac2a553c5cc841a38747d5d075d7f348de5da57cd77a3d2c6dc268c20271d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for docx_renderer-0.2.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