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

相关推荐
XYX的Blog10 小时前
Pandas基础07(Csv/Excel/Mysql数据的存储与读取)
mysql·excel·pandas
东京老树根14 小时前
Excel 技巧23 - 在Excel中用切片器做出查询效果(★★★)
笔记·学习·excel
nbsaas-boot1 天前
存储过程优化实践:统一返回结构、参数 JSON 化与事务原子化
数据库·json
东京老树根2 天前
Excel 技巧22 - Ctrl+D 向下复制(★★),复制同间距图形
笔记·学习·excel
如意机反光镜裸2 天前
如何批量导入竖版Excel表到数据库
数据库·excel
NiNg_1_2342 天前
FastExcel使用详解
开发语言·excel·fastexcel
思逻辑维3 天前
强大到工业层面的软件
数据结构·sql·sqlite·json
旺代3 天前
Qt中json的使用
qt·json
VB.Net3 天前
10.6.4 Json文件操作
c#·json
小奥超人4 天前
EXCEL教程:如何打开Excel隐藏部分?
windows·经验分享·microsoft·excel·办公技巧