[TOC]
介绍
json 转换成 excel 满足 报表业务需求
为什么需要这个模块:
1. 标准 2. 可能,真的很优雅。
好的功能
1. 标准化
安装方法
pip install json2excel
调用案例
from json2excel import Json2Excel
if __name__ == '__main__':
json2excel = Json2Excel(head_name_cols=["rank", "name"])
# print(json2excel.run('./test.json'))
jsons = [
{
"student_no": 1001,
"name": "James",
"score": 10,
"class": "A-1",
"rank": 1
},
{
"student_no": 1002,
"name": "Tome",
"score": 91,
"class": "A-1",
"rank": 2
},
]
print(json2excel.run(jsons))
参数介绍
json2excel 控制参数
format_handler 非必须 function/class 自定义json格式化函数,强烈推荐自定义 export_handler 非必须 class 自定义json输出成excel函数,一般不需要修改 export_dir 非必须 str 文件输出 **绝对** 路径,推荐自定义 head_name_cols 非必须 list 自定义excel表头排序,推荐自定义 kwargs 非必须 空 其他参数
自定义json转换函数说明
FormatHandler 可以是 类,或者函数。最重要的是把数据转换成如下格式。
"""
输出目标格式:
注意,一定需要转换成这种格式,才能正常保存。
[
{
"student_no": 1001,
"name": "James",
"score": 10,
"class": "A-1",
"rank": 1
},
{
"student_no": 1002,
"name": "Tome",
"score": 91,
"class": "A-1",
"rank": 2
},
]
"""
class FormatHandler:
def __init__(self, **kwargs):
""""""
def __call__(self, data_list: (list, dict)):
""""""
todo
Metadata
Release files for json2excel 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| json2excel-1.0.4.tar.gz | 3.8 kB | Without provenance | Details for json2excel-1.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| json2excel-1.0.4-py3-none-any.whl | Python 3 | none | any | Details for json2excel-1.0.4-py3-none-any.whl |
Total release size: 11.2 kB
Release files / json2excel-1.0.4.tar.gz
| Download URL | json2excel-1.0.4.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4318148a591493bd2d65054cebcf6f20f29d77cb3f2a0875d720ee642852fefe
|
|
BLAKE2b-256 checksum How to use checksums |
9e66fddb0d03c807bf356d90c0c02684db658b46d1fb9bacfeab1d20f93bb73f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.7
|
Release files / json2excel-1.0.4-py3-none-any.whl
| Download URL | json2excel-1.0.4-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
67cc6602078b2290fe4675e69c11d5d2d2f1cf0241f18f08e6754a4bbff12fda
|
|
BLAKE2b-256 checksum How to use checksums |
9e47fa776375cc347b5d6c1bbb7f729af7da19fac8d9b5c6ff67e0dfbdc0a648
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.7
|
Security for json2excel 1.0.4
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.