batch docx generation
Project description
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就好了。
Project details
Release history Release notifications | RSS feed
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 letterpress-0.0.1.tar.gz.
File metadata
- Download URL: letterpress-0.0.1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99ce6741103a1ddeabeaa9083f95abc1ba9a3d98bfccbab5abf94c445958bf61
|
|
| MD5 |
2449bc5431ada575e66c8fffc345f9b1
|
|
| BLAKE2b-256 |
8c37406f4c7c105d0d67ce9cf3d2b5515ad01b9ca87d1435253710461953eddd
|
File details
Details for the file letterpress-0.0.1-py3-none-any.whl.
File metadata
- Download URL: letterpress-0.0.1-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fecd71ab26b972d39028b53c7253ca66395269e04cce40c74dacf47b9da9170a
|
|
| MD5 |
c7084fe883ec7ae2b7cd3925a4aa2c01
|
|
| BLAKE2b-256 |
99312ba88dc4073e0b09729ade645fb47b3b3639ca2b3a54dac166a9d2debcb0
|