| import pandas as pd | |
| from io import StringIO | |
| import re | |
| def md_table_to_excel(md_file, excel_file, sheet_name="Sheet1"): | |
| # 读取 Markdown 文件内容 | |
| with open(md_file, "r", encoding="utf-8") as f: | |
| lines = f.readlines() | |
| # 提取表格行(包含 '|' 的行) | |
| table_lines = [line.strip() for line in lines if "|" in line and "---" not in line] | |
| # 拼接成 CSV 风格的字符串 | |
| csv_string = "\n".join([re.sub(r'^\||\|$', '', line).strip() for line in table_lines]) | |
| csv_string = csv_string.replace("|", ",") | |
| # 用 pandas 解析 | |
| df = pd.read_csv(StringIO(csv_string)) | |
| # 输出到 Excel | |
| df.to_excel(excel_file, sheet_name=sheet_name, index=False) | |
| print(f"✅ 转换完成,已保存到 {excel_file}") | |
| # 示例调用 | |
| md_table_to_excel("/home/luoxianzhen/yang/eval_wrong_code/rank_md/new_algo/ALL_RESULT.md", "ALL_RESULT-part-922.xlsx") | |
Xet Storage Details
- Size:
- 913 Bytes
- Xet hash:
- 25fac7a0f3ff12d01760ecd6b41d7666f0e11180dfa33e765839b3b57682c2ea
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.