把json文件转换成excel格式文件

自己没写一行代码,用通义千问生成的python程序搞定的,python我也不熟悉,只是helloworld水平。

import pandas as pd
import json
import argparse

def json_to_excel(input_json, output_excel):
    # 读取json文件
    with open(input_json, 'r') as f:
        data = json.load(f)

    # 将json数据转换为DataFrame
    df = pd.DataFrame(data)

    # 将DataFrame写入Excel文件
    df.to_excel(output_excel, index=False)

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Convert JSON file to Excel (xlsx) file.")
    parser.add_argument("--input", "-i", required=True, help="Input JSON file name.")
    parser.add_argument("--output", "-o", required=True, help="Output Excel (xlsx) file name.")

    args = parser.parse_args()

    json_to_excel(args.input, args.output)

1、新建一个py文件,复制粘贴过去。(电脑上要先安装python才能运行)

2、控制台给出输入和输出文件名(同目录)

python your_script_name.py -i input.json -o output.xlsx

3、如果提示缺失某个依赖,直接pip安装。

比如: import pandas as pd ModuleNotFoundError: No module named 'pandas'。没关系,在控制台终端,输入命令:pip install pandas

4、如果还有问题,跟GPT提问吧 ,它会告诉你的

最近更新

  1. TCP协议是安全的吗?

    2024-03-23 05:24:05       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-23 05:24:05       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-23 05:24:05       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-23 05:24:05       20 阅读

热门阅读

  1. python与excel第五节 打印excel

    2024-03-23 05:24:05       20 阅读
  2. 在realsense D455相机上运行orb_slam3

    2024-03-23 05:24:05       17 阅读
  3. OpenCV自带颜色表

    2024-03-23 05:24:05       19 阅读
  4. cordova cordova-hot-code-push-plugin 插件热更新

    2024-03-23 05:24:05       18 阅读
  5. 图书管理借阅系统(SpringBoot项目)

    2024-03-23 05:24:05       20 阅读