Skip to main content

Letterpress

Letterpress取意于活字印刷,是帮需要批量生成Word的朋友写的一个小工具。

每一套信息需要生成大量文件,Word自带的邮件生成也帮不了他。

Installation

python -m pip install letterpress

Usage

假设你有一个Word文件,起名为template.docx,其中的内容是这样的:

标题:{{ topic }}
正文: {{ content }}

这些内容可以在正文,可以在表格,甚至可以在页眉页脚或者嵌套的表格中。

当然,也可以在页眉页脚嵌套的表格中。

这些内容也可以是任何格式,任何大小,甚至大括号与变量名都不需要统一格式。

唯一需要注意的是,需要用两个大括号和一个空格包围你的变量名。

然后运行下面的Python代码:

from letterpress import TemplateDocument

vm = {
    'topic': 'my-topic',
    'content': 'my-content',
}
template = TemplateDocument('template.docx', vm.keys())
template.parse_document()
template.replace_and_save(vm, 'outcome.docx')

vm = {
    'topic': 'my-another-topic',
    'content': 'my-another-content',
}
template.replace_and_save(vm, 'another-outcome.docx')

就根据给定的内容生成了两个Word文件。

FAQ

Q: Word文件无法读取,显示检测到不是Word文件。 A: python-docx读取的方式不适用于老版本Word,升级到docx就好了。

Metadata

Release files for letterpress 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for letterpress 0.0.1
File Size Uploaded Provenance Actions
letterpress-0.0.1.tar.gz 3.6 kB Without provenance Details for letterpress-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for letterpress 0.0.1
File Interpreter ABI Platform Actions
letterpress-0.0.1-py3-none-any.whl Python 3 none any Details for letterpress-0.0.1-py3-none-any.whl

Total release size: 7.3 kB

Release files / letterpress-0.0.1.tar.gz

Download URL letterpress-0.0.1.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
99ce6741103a1ddeabeaa9083f95abc1ba9a3d98bfccbab5abf94c445958bf61
BLAKE2b-256 checksum
How to use checksums
8c37406f4c7c105d0d67ce9cf3d2b5515ad01b9ca87d1435253710461953eddd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.4

Release files / letterpress-0.0.1-py3-none-any.whl

Download URL letterpress-0.0.1-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fecd71ab26b972d39028b53c7253ca66395269e04cce40c74dacf47b9da9170a
BLAKE2b-256 checksum
How to use checksums
99312ba88dc4073e0b09729ade645fb47b3b3639ca2b3a54dac166a9d2debcb0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.4

Security for letterpress 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page