Python转换Excel到Markdown
原创2024年3月15日大约 3 分钟
背景
互联网搜集到一个Excel描述关于
AI工具合集格式如下(有合并单元格,下面没有合并) , 我想转成Markdown格式发布到本平台机器学习-大模型-AI工具合集文章。
| 序号 | 类型 | AI工具名称 | 入口 | 功能 |
|---|---|---|---|---|
| 1 | 聊天/内容生成 | 文心一言 | https://yiyan.baidu.com | 综合型AI:内容生成、文档分析、图像分 |
| 2 | 通义千问 | https://tongyi.aliyun.com | 综合型AI:内容生成、文档分析、图像分析…… | |
| 3 | Kimi(月之暗面) | https://kimi.moonshot.cn | 综合型AI:内容生成、文档分析、互联网搜索 | |
| 4 | 腾讯混元 | https://hunyuan.tencent.com/bot/chat | 综合型AI:内容生成、文档分析、灵感 | |
| 5 | 讯飞星火 | https://xinghuo.xfyun.cn | 综合型AI:内容生成…… | |
| 6 | 抖音豆包 | https://www.doubao.com | 综合型AI:内容生成,偏互联网运营方向…… | |
| 7 | 智谱AI | https://open.bigmodel.cn | 综合型AI:内容生成、知识问答…… | |
| 8 | 百川智能 | https://www.baichuan-ai.com/chat | 综合型AI:内容生成、文档分析、互联网搜索 | |
| 9 | 360智脑 | https://ai.360.com | 综合型AI:360智脑全家桶…… | |
| 10 | 字节小悟空 | https://wukong.com/tool | 综合型AI:字节跳动内容生成工具集 | |
| 11 | 达观数据曹植 | http://www.datagrand.com/ | 行业垂域大模型 | |
| 12 | AI办公-综合 | 360数字员工 | https://ai.360.com | 团队协作共享,企业知识库、AI文档分析、 |
| 13 | 有道AI | https://ai.youdao.com | 文档、翻译、视觉、语音、教育…… | |
| 14 | AI办公-Office | AiPPT | https://www.aippt.cn | 自动生成PPT大纲、模板、Word-PPT…… |
| 15 | iSlide | https://www.islide.cc | AI 一键设计 PPT | |
| 16 | WPS AI | https://ai.wps.cn | WPS的AI插件(智能PPT、表格、文档整理……) | |
| 17 | ChatPPT | http://www.chat-ppt.com | AI插件,支持Office、WPS,自动文档生成 | |
| 18 | 360苏打办公 | https://bangong.360.cn | AI办公工具集:文档、视频、设计、开发…… | |
| 19 | 酷表ChatExcel | https://chatexcel.com | 智能Excel公式 | |
| 20 | 商汤办公小浣熊 | https://raccoon.sensetime.com | 智能图表 | |
| .. | .. | .... | .... | .... |
下面代码是基于openpyxl的Python转换Excel到Markdown的代码。根据我的格式转换成了markdown格式。
特别说明
当然你可以修改代码,实现你自己的格式。
Python 代码
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2024-03-15 17:35
# @Author : Jack
# @File : 01.excel_convert
"""
01.excel_convert
pip install openpyxl
"""
from openpyxl import load_workbook
def get_table(file_path):
# 读取Excel文件
wb = load_workbook(file_path)
# 选择工作表
sheet = wb.active
table = []
# 打印每个单元格的内容
for row in sheet.iter_rows(values_only=True):
rows = []
for cell in row:
rows.append(cell)
table.append(rows)
# 关闭Excel文件
wb.close()
return table
def main(file_path):
table = get_table(file_path)
idx = 1
i_idx = 1
for row in table[2:-2]:
if row[2] is not None and len(row[2]) > 0:
i_idx = 1
print(f'''### {idx}. {row[2]}
{i_idx}. [{row[3]}]({row[4]})
{row[5]}
''')
idx += 1
else:
i_idx += 1
print(f'''{i_idx}. [{row[3]}]({row[4]})
{row[5]}
''')
if __name__ == '__main__':
main(r'AI工具集.xlsx')