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

相关推荐
用户298698530141 小时前
Python 实现 Excel 与 Markdown 互转的实用指南
后端·python·excel
2501_930707783 小时前
如何使用C#代码在 Excel 中编辑或删除批注
excel
SunnyDays101121 小时前
Python Excel 切片器操作详解:自动创建智能交互式报表
python·excel·数据筛选·切片器
观远数据21 小时前
Excel到数据资产池:文件数据入湖的治理规范怎么建
前端·javascript·excel
CedarQR1 天前
万字长文:从零在 RK3588 上部署 PaddleSpeech 中文 TTS 全流程(FastSpeech2 + HiFiGAN)
开发语言·c++·嵌入式硬件·ubuntu·json
蓝创工坊Blue Foundry1 天前
PDF 批量提取指定内容到 Excel:按字段整理多个 PDF 的方法
pdf·ocr·excel·文心一言·paddlepaddle·paddle
用户298698530141 天前
React 项目中灵活管理 Excel 工作表:增删与移动
javascript·react.js·excel
程序猿乐锅2 天前
【苍穹外卖 Day12| Excel 入门】
excel
Geoking.2 天前
JSON vs JSONL:从数据格式到 AI Agent 的工程实践
人工智能·深度学习·json
ID_180079054732 天前
京东商品详情API能力解析与标准化应用方案(含JSON返回示例)
json