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

相关推荐
Jp7gnUWcI15 小时前
基于.NET操作Excel COM组件生成数据透视报表
.net·excel
pl4H522a616 小时前
Python 高效实现 Excel 转 TXT 文本
java·python·excel
数据知道17 小时前
claw-code 源码详细分析:`reference_data` JSON 快照——大型移植里「对照底稿」该怎么治理与演进?
linux·python·ubuntu·json·claude code
不会写DN18 小时前
让 gRPC 服务同时支持 HTTP/JSON 的gRPC-Gateway
http·json·gateway
开开心心_Every1 天前
实用PDF擦除隐藏信息工具,空白处理需留意
运维·服务器·网络·pdf·电脑·excel·依赖倒置原则
codeJinger1 天前
【Python】操作Excel文件
python·excel
bloglin999992 天前
掌握解析JSON输出的技巧:使用LLM生成结构化数据
json
城数派2 天前
谷歌18亿建筑足迹数据集 Google Open Buildings V3
数据库·arcgis·信息可视化·数据分析·excel
whatzhang0072 天前
在 macOS 上从零配置 Vim:开启语法高亮 + 安装 vim-polyglot + 设置 gruvbox 主题
macos·vim·excel
fengyehongWorld2 天前
Excel 杂项知识
excel