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

相关推荐
likerhood1 天前
Fastjson中的JSON.parseObject()详细讲解
java·json
开开心心就好1 天前
一键扫描电脑重复文件的实用工具
linux·运维·服务器·随机森林·智能手机·excel·启发式算法
ModestCoder_1 天前
Git 忽略所有 `.xlsx`,但保留指定 Excel 文件的方法
git·excel
老神在在0011 天前
JSON Schema
测试工具·json
xiaodaoluanzha1 天前
golang中MetaMessage(mm)的使用
json·protobuf
z19408920661 天前
在线题库整理:把重复劳动从 Excel 手工里解放出来
excel
开开心心_Every1 天前
免费简洁的安卓黄历日历,软件推荐
运维·服务器·随机森林·pdf·电脑·excel·最小二乘法
VBAMatrix2 天前
deepseek-v4正式接入Excel,一键生成财务分析报告
word·excel·审计·财务分析·deepseek·会计师事务所·tb工具箱
星空椰3 天前
从零到实战:一套完整的 Python 爬虫技术体系(requests + BeautifulSoup + 正则 + JSON)
爬虫·python·json·beautifulsoup
A__tao3 天前
JSON 转 Proto 工具(支持嵌套与注释解析)
json