你可以使用Python中的pandas库来实现这个功能。以下是一个示例代码:

import pandas as pd
import json

# 读取返回的json格式文件
with open('output.json', 'r') as f:
    data = json.load(f)

# 创建一个空的DataFrame
df = pd.DataFrame()

# 遍历每个字典
for item in data:
    # 将字典的key作为列名,value作为对应的值
    row = pd.DataFrame([item.values()], columns=item.keys())
    # 将该行添加到DataFrame中
    df = df.append(row, ignore_index=True)

# 将DataFrame保存为Excel文件
df.to_excel('output.xlsx', index=False)

这个代码假设返回的json格式文件名为output.json,生成的Excel文件名为output.xlsx。你可以根据实际情况修改这些文件名。

使用 Python Pandas 将 JSON 数据转换为 Excel 文件

原文地址: https://www.cveoy.top/t/topic/pVT4 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录