使用 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
相关推荐
happylifetree20 分钟前
Python14:核心语法-数据存储与运算-字符串定义
python
hhb_61822 分钟前
AIRAGDebug:一键定位RAG链路异常
人工智能·python·算法
小静AI工程实验室44 分钟前
asyncio.Queue 有界队列实战:背压、task_done、join 与异常收尾
python
小凡geo1 小时前
本地商家 GEO:用脚本一键生成 FAQPage 结构化数据,让 AI 切片更稳
开发语言·人工智能·python·microsoft·搜索引擎·ai
Zhou1411361 小时前
SpringBoot_03_Web开发
前端·spring boot·python
weixin199701080161 小时前
《1688物流API接口边界:logistics.trace.get 与 freight.template.list 的隐藏约束》(附Python源码)
windows·python·list
mhmh1232 小时前
Python 对象模型与数据模型:魔术方法、描述符与元类深度解析
开发语言·python
估值探索者2 小时前
【Python量化策略实战 #02】多因子合成mom和vol两因子打分合成
开发语言·c++·python·数据挖掘·c#
FYKJ_20103 小时前
SSM校园失物招领系统41452-计算机课程设计、毕业设计
java·vue.js·spring boot·python·mysql·typescript·spark
头发够用的程序员3 小时前
TensorRT 自定义算子插件实战(一):从零手写 customScaledTanh
c++·人工智能·pytorch·python·深度学习·边缘计算·jetson