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

相关推荐
葬歌倾城5 小时前
JSON的缩进格式方式和紧凑格式方式
c#·json
爱代码的小黄人6 小时前
Excel VLOOKUP函数使用详解:原理、格式、常见错误与解决方案
excel
YouYOUyouFairy8 小时前
EXCEL动态表格
excel
Maruko3109 小时前
Java 实现excel大批量导出
excel·poi
忧郁的蛋~9 小时前
HTML表格导出为Excel文件的实现方案
前端·html·excel
不坑老师16 小时前
利用不坑盒子的Copilot,快速排值班表
microsoft·word·powerpoint·excel·copilot·wps
火车叨位去194918 小时前
Java中的JSON序列化和反序列化
json
开开心心就好20 小时前
批量PDF转换工具,一键转换Word Excel
开发语言·前端·学习·pdf·电脑·word·excel
Fireworkitte1 天前
Apache POI 详解 - Java 操作 Excel/Word/PPT
java·apache·excel
测试杂货铺1 天前
Jmeter(六):json断言元件,jmeter参数化实现
jmeter·json