使用 Python 将excel 生成json

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

步骤:
  1. 安装 Pandas 和 OpenPyXL

    使用 pip 安装 pandasopenpyxl 库:

    复制代码
    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
相关推荐
a努力。1 天前
字节Java面试被问:TCP的BBR拥塞控制算法原理
java·开发语言·python·tcp/ip·elasticsearch·面试·职场和发展
费弗里1 天前
一个小技巧轻松提升Dash应用debug效率
python·dash
小小测试开发1 天前
Python浮点型常用方法全解析:从基础到实战
python
ValhallaCoder1 天前
Day53-图论
数据结构·python·算法·图论
lpfasd1231 天前
PyGithub用法详解
git·python·github
给我来一根1 天前
用户认证与授权:使用JWT保护你的API
jvm·数据库·python
白云千载尽1 天前
LQR与MPC.入门知识与实验
python·控制·mpc·lqr
weixin_433179331 天前
Hangman 猜字游戏使用列表List实现
开发语言·python
热爱学习的小翁同学1 天前
SharePoint 列格式化 JSON 配置
json·sharepoint
52Hz1181 天前
二叉树理论、力扣94.二叉树的中序遍历、104.二叉树的最大深度、226.反转二叉树、101.对称二叉树
python·算法·leetcode