把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提问吧 ,它会告诉你的

相关推荐
AI导出鸭5 小时前
怎么让豆包做表格?AI导出鸭苹果版将豆包输出的管道表格智能解析为二维结构,一键导出为Excel或Word标准表格。
人工智能·chatgpt·word·excel·ai导出鸭
zhanghaha131416 小时前
Python进阶教程:6_JSON 数据解析 —— 新手完全指南
开发语言·python·json
云水一下19 小时前
零基础玩转bWAPP靶场(四十六):XSS - Reflected (AJAX/JSON)
web安全·ajax·json·xss·bwapp·reflected
小小龙学IT1 天前
simdjson:利用 SIMD 指令实现 GB/s 级 JSON 解析的 C++ 开源库
开发语言·c++·json
天吾cc1 天前
JSON 与 cJSON 学习笔记
笔记·学习·json
大家的林语冰1 天前
👍 JS 还在进化,ES2026 正式推出,最新七大特性补全!
前端·javascript·json
秋田君1 天前
QT_JSON文件操作
开发语言·qt·json
k4m7v2pz1 天前
Rust 规则热重载实战:用 serde_json + notify 告别重启
开发语言·rust·json·规则引擎·notify·热重载
Am-Chestnuts2 天前
AI表格复制到Excel后日期金额和编号被改写:导入与格式检查方法
excel
方渐鸿2 天前
【无标题】使用Agent总结网页信息写入Excel
ai·excel