EXCEL 转 Markdown

2022年7月26日

EXCEL 文件转 Markdown表格python脚本

因为Markdown不支持合并单元格,目前合并单元格处理的不好。

需要用HTML重写处理合并单元格的问题

# -*- coding: utf-8 -*-
import pandas as pd # conda install openpyxl pandas

def excelToMd(path, sheetName="Sheet1"):
    df = pd.read_excel(path, sheetName)
    title = "|"
    splitLine = "|"
    for i in df.columns.values:
        title = title + i + "|"
        splitLine = splitLine + "--" + "|"
    print(title)
    print(splitLine)
    for i in df.iterrows():
        row = "|"
        for j in df.columns.values:
            row = row + str(i[1][j]) + "|"
        print(row.replace("nan", "-"))

if __name__=="__main__":
    path = "temp.xlsx"
    sheetName="Sheet1"
    excelToMd(path, sheetName="Sheet1")

网络工具 Table to Markdown

https://tabletomarkdown.com/convert-spreadsheet-to-markdown/

rankment

这个人很懒,什么都没留下

文章评论