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

相关推荐
Cloud_Shy6184 小时前
Python 数据分析基础入门:《Excel Python:飞速搞定数据分析与处理》学习笔记系列(第十章 Python 驱动的 Excel 工具 上篇)
vscode·python·数据分析·excel·pandas
Cloud_Shy6184 小时前
Python 数据分析基础入门:《Excel Python:飞速搞定数据分析与处理》学习笔记系列(第十章 Python 驱动的 Excel 工具 下篇)
笔记·python·学习·数据分析·excel·pandas
会编程的土豆5 小时前
Gin 中 `c.BindJSON` 与 `c.JSON` 详细讲解
c语言·json·gin
关中老四5 小时前
不用登录!3 步把 Excel 进度表变成甘特图
excel·项目管理·甘特图·一键生成·进度管理·pjman
Ada大侦探16 小时前
新手小白学习数据分析03----Excel 报表之大厂周报(2026最新版实操,包教包会!)
学习·数据分析·excel
ID_1800790547320 小时前
企业级实战:淘宝商品详情 API简要说明,json数据返回参考
json
软件富二代1 天前
— 批量转换Word题库到Excel的小工具
电脑·word·excel·排版·软件
学习3人组1 天前
业务主表+JSON自定义字段
java·spring boot·json
曦夜日长1 天前
Linux系统篇,开发工具(二):vim的使用与配置
linux·服务器·vim·excel
金玉满堂@bj1 天前
pytest+uiautomation+allure+Excel 数据驱动桌面自动化
自动化·excel·pytest