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

相关推荐
wtsolutions1 小时前
Understanding JSON Formats - What JSON to Excel Supports
json·excel
wtsolutions2 小时前
Advanced Features - Unlocking the Power of JSON to Excel Pro
linux·json·excel
fs哆哆3 小时前
VB.NET和VBA教程-如何查找Excel数据区域边界
excel
小矮强3 小时前
Excel中根据年月日提取月日,并按月日进行排序
excel
开开心心_Every4 小时前
图片批量压缩工具:支持有损无损两种模式
python·游戏·微信·django·pdf·excel·语音识别
wtsolutions5 小时前
Real-World Use Cases - How Organizations Use JSON to Excel
json·excel
wtsolutions5 小时前
Introduction to JSON to Excel - The Ultimate Conversion Tool
json·excel
骆驼爱记录5 小时前
Python打包命令全攻略
自动化·word·excel·新人首发
San30.6 小时前
LangChain 第二课:拒绝“废话”,用 Zod 强制 AI 输出标准 JSON
人工智能·langchain·json
wtsolutions6 小时前
JSON to Excel WPS Add-in - Perfect for WPS Office Users
json·excel·wps