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

相关推荐
偷心伊普西隆2 小时前
Python EXCEL 理论探究:格式转换时处理缺失值方法
python·excel
luckys.one11 小时前
第9篇:Freqtrade量化交易之config.json 基础入门与初始化
javascript·数据库·python·mysql·算法·json·区块链
小菜全15 小时前
基于若依框架Vue+TS导出PDF文件的方法
javascript·vue.js·前端框架·json
CodeCraft Studio1 天前
Excel处理控件Aspose.Cells教程:使用 Python 将 Pandas DataFrame 转换为 Excel
python·json·excel·pandas·csv·aspose·dataframe
星空的资源小屋1 天前
PPTist,一个完全免费的 AI 生成 PPT 在线网站
人工智能·python·电脑·excel
开开心心_Every1 天前
免费语音合成工具:66种音色随心选
人工智能·面试·java-ee·计算机外设·电脑·maven·excel
敬业小码哥2 天前
记一次:mysql的json及json数组使用组合使用
数据库·mysql·json
一键三联啊2 天前
BSON 和 JSON 的区别
json
偷心伊普西隆2 天前
EXCEL VBA 清空Excel工作表(Sheet)的方法
microsoft·excel
Coding_Doggy2 天前
苍穹外卖Day12 | Apache POI、导出Excel报表、HttpServletResponse、工作台
excel