使用 Python 将excel 生成json

Python 的 pandas 库是一个强大的数据处理工具,可以轻松地将 Excel 文件转换为 JSON 格式。

步骤:
  1. 安装 Pandas 和 OpenPyXL :

    使用 pip 安装 pandas 和 openpyxl 库:

    复制代码
    pip install pandas openpyxl
  2. 编写 Python 脚本 :

    创建一个 Python 脚本,例如 excel_to_json.py,内容如下:

    复制代码
    import pandas as pd
    
    def excel_to_json(excel_file, sheet_name, json_file):
        # 读取 Excel 文件
        df = pd.read_excel(excel_file, sheet_name=sheet_name)
        
        # 将 DataFrame 转换为 JSON
        df.to_json(json_file, orient='records', force_ascii=False)
    
    # 示例用法
    excel_to_json('input.xlsx', 'Sheet1', 'output.json')
  3. 运行脚本 :

    在终端中运行脚本:

    复制代码
    python excel_to_json.py
相关推荐
ebiobiz1 小时前
基于 GD32 Embedded Builder (GEB) 与 Nimmake 的 MCU 工程搭建指南
c++·python·单片机·嵌入式硬件·mcu
老歌老听老掉牙2 小时前
穿越时空的物流密码:VRP与VRPTW的深度剖析及实战求解
python·物流·vrp
FYKJ_20102 小时前
django电影推荐系统55066-计算机课程设计、毕业设计
vue.js·spring boot·python·mysql·typescript·spark·django
ShyanZh2 小时前
【Python3基础】13-Python 常用设计模式
开发语言·python·设计模式
小静AI工程实验室3 小时前
RSA 算法详解:从模幂原理到 OAEP 加密、PSS 签名与 Python 实验
python·算法
xzal123 小时前
GESP Python笔记
笔记·python·算法
半日闲dusknook3 小时前
我给 AI 写了个「音频编译器」:把「听起来还行」变成 PASS/FAIL
python
在世修行3 小时前
干货:信号槽
python·信号槽
Wx-bishekaifayuan3 小时前
springboot生活易购超市管理系统54086-计算机课程设计、毕业设计
spring boot·后端·python·django·课程设计·express·旅游
数字融合4 小时前
透明化数字孪生智慧养老平台运维服务项目
人工智能·python·virtualenv