Generates Office documents (PPTX/XLSX) from template files that are flexibly populated or composed using provided context.
Project description
Office Templates
Office Templates is a Python library turns PowerPoint (PPTX) and Excel (XLSX) files into reusable templates. Placeholders inside those templates are resolved using provided context so that you can generate templated documents without hard‑coding content.
Key Features
- PowerPoint and Excel rendering – supply a PPTX or XLSX file and a context dictionary to produce a finished document.
- Placeholder expressions using
{{ }}to access attributes, call methods, filter lists and perform math. - Formatting helpers for dates, numbers and string casing (
upper,lower,title). - Arithmetic operators in expressions (
+,-,*,/). - Dynamic table and worksheet expansion when a placeholder resolves to a list.
- Chart support where spreadsheet values inside charts contain placeholders.
- Permission enforcement – data is filtered based on
check_permissionsfunction. - Global context injection for values that should always be available.
- Context extraction to inspect templates and determine which context keys are required.
- Image placeholders – shapes or cells starting with
%imagesqueeze%or%image%are replaced by an image downloaded from the provided URL.
Codebase Overview
office_templates/ contains the library:
office_renderer/– logic for rendering PPTX and XLSX files. This handles text boxes, tables, charts, worksheets and the%image%/%imagesqueeze%directives.templating/– the template engine responsible for parsing and evaluating expressions.tests/– the test suite.
Start by looking at the functions in office_renderer to see how a file is rendered. The templating package is standalone and can be read independently if you want to learn how placeholders are parsed.
Writing Templates
Template files are just normal PowerPoint or Excel documents. No coding or macros are required—just type plain text placeholders where you want dynamic information to appear.
- Design your layout. Build the slides or workbook exactly as you would for a static report.
- Insert placeholders. Anywhere you would type text you can instead type a placeholder wrapped in
{{and}}:{{ user.name }}– insert a simple value from the context.{{ user.profile__email }}– read nested attributes using.or__.{{ users[is_active=True].email }}– pick a specific item from a list.{{ amount * 1.15 }}– perform calculations.{{ price | .2f }}or{{ name | upper }}– apply formatting filters.
- Repeat rows or slides for lists. If a placeholder by itself resolves to a list, extra rows (or slides) will be created so that each item appears separately. This is how you build tables from querysets.
- Add images. To include an image from a URL, create a text box or cell that starts with
%image%or%imagesqueeze%followed by the address:%image% https://example.com/logo.png%imagesqueeze% https://example.com/logo.pngThe former keeps the image's aspect ratio while fitting it inside the shape. The latter squeezes the image to exactly fill the shape. - Save the file and register it in the Django admin as a report template.
You can experiment with the example files in office_templates/raw_templates to see common patterns. Remember that all placeholders are plain text—avoid formulas or punctuation that might confuse the parser.
Chart data sheets can also contain placeholders so your graphs update automatically.
Learning More
After trying the example templates in raw_templates/ explore the tests/ directory to see many usage patterns. The test files demonstrate complex placeholders, permission checks and the new image replacement behaviour.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file office_templates-0.5.0.tar.gz.
File metadata
- Download URL: office_templates-0.5.0.tar.gz
- Upload date:
- Size: 61.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8be6144ecfc79e32b3663c4675257fd052ebc33d3608154182ff7d661fc015c7
|
|
| MD5 |
3163933006da35dc7a9f6fb701bd0179
|
|
| BLAKE2b-256 |
3c741a912684551c7da468ebbbf2067dfb897130d6f6015d25b73ba37ff3fc92
|
Provenance
The following attestation bundles were made for office_templates-0.5.0.tar.gz:
Publisher:
build.yml on gaussian/python-office-templates
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
office_templates-0.5.0.tar.gz -
Subject digest:
8be6144ecfc79e32b3663c4675257fd052ebc33d3608154182ff7d661fc015c7 - Sigstore transparency entry: 230053516
- Sigstore integration time:
-
Permalink:
gaussian/python-office-templates@02470626a9167ae913d835834e02b9c63f113be4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/gaussian
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@02470626a9167ae913d835834e02b9c63f113be4 -
Trigger Event:
pull_request_target
-
Statement type:
File details
Details for the file office_templates-0.5.0-py3-none-any.whl.
File metadata
- Download URL: office_templates-0.5.0-py3-none-any.whl
- Upload date:
- Size: 40.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ad0bc0a00d1c3e9a7ceb0940a2587a824f0455547079f7d2ed6ecf2a63f505d
|
|
| MD5 |
f6069790675571825b457213a18d3779
|
|
| BLAKE2b-256 |
ece4c5741c2e9cee1deabcffa01ad5db59b1c08802e78ae1099c848118c33c0d
|
Provenance
The following attestation bundles were made for office_templates-0.5.0-py3-none-any.whl:
Publisher:
build.yml on gaussian/python-office-templates
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
office_templates-0.5.0-py3-none-any.whl -
Subject digest:
7ad0bc0a00d1c3e9a7ceb0940a2587a824f0455547079f7d2ed6ecf2a63f505d - Sigstore transparency entry: 230053518
- Sigstore integration time:
-
Permalink:
gaussian/python-office-templates@02470626a9167ae913d835834e02b9c63f113be4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/gaussian
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@02470626a9167ae913d835834e02b9c63f113be4 -
Trigger Event:
pull_request_target
-
Statement type: