Skip to main content

Easy transform json 2 excel

Project description

[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

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

json2excel-1.0.4.tar.gz (3.8 kB view hashes)

Uploaded Source

Built Distribution

json2excel-1.0.4-py3-none-any.whl (7.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page