#markdown-tables #markdown #yaml #csv #command-line-tool #excel #json

bin+lib madato

用于读取和写入表格数据(XLS、ODS、CSV、YAML)和Markdown的库和命令行工具

3个不稳定版本

0.7.0 2024年5月26日
0.5.3 2018年9月9日
0.5.1 2018年8月12日

232解析器实现

Download history 2025/week @ 2024-04-30 2223/week @ 2024-05-07 1350/week @ 2024-05-14 2017/week @ 2024-05-21 2367/week @ 2024-05-28 1571/week @ 2024-06-04 1497/week @ 2024-06-11 1780/week @ 2024-06-18 1375/week @ 2024-06-25 949/week @ 2024-07-02 1157/week @ 2024-07-09 1316/week @ 2024-07-16 1818/week @ 2024-07-23 840/week @ 2024-07-30 665/week @ 2024-08-06 1536/week @ 2024-08-13

5,217 每月下载量
用于 dtool

MIT/Apache

77KB
1K SLoC

madato   构建状态 最新版本

madato 是一个用于处理表格数据和Markdown的库和命令行工具


该工具主要专注于将表格数据(工作表、CSV)转换为Markdown。

它是一个库和CLI。库是Rust和Python库。如果您需要工作表支持,请添加 spreadsheets 功能。

madato = { version = "0", features = ["spreadsheets"] }

  1. madato (library) - 此库支持YAML
  2. feature = "spreadsheets" - 提供读取和写入XLS和ODS工作表的支持
  3. madato (cli) - 提供上述有用的命令行工具
  4. 完整的库可以作为Python模块使用

详细信息

在生成输出时

  • 使用基本正则表达式按键/值对过滤行
  • 限制列到命名标题
  • 重新排序列或使用相同的列功能重复它们
  • 只为命名“工作表”生成表格(适用于XLS/ODS格式)

Madato是

  • 命令行工具(Windows、Mac、Linux) - 适用于CI/CD预处理
  • Rust库 - 适用于集成到Rust Markdown工具
  • Node JS WASM API - 将用于Atom和VSCode扩展

Madato期望每个列都有标题行。也就是说,第一行是标题/列名。如果第一行中的单元格为空,它将创建所需的 NULL0..NULLn 条目。

示例

  • 从MS Excel文档中提取 第3个工作表 工作表
08:39 $ target/debug/madato table --type xlsx test/sample_multi_sheet.xlsx --sheetname "3rd Sheet"
|col1|col2| col3 |col4 |                         col5                          |NULL5|
|----|----|------|-----|-------------------------------------------------------|-----|
| 1  |that| are  |wider|  value ‘aaa’ is in the next cell, but has no heading  | aaa |
|than|the |header| row |       (open the spreadsheet to see what I mean)       |     |
  • 仅提取和重新排序3列
08:42 $ target/debug/madato table --type xlsx test/sample_multi_sheet.xlsx --sheetname "3rd Sheet" -c col2 -c col3 -c NULL5
|col2| col3 |NULL5|
|----|------|-----|
|that| are  | aaa |
|the |header|     |
  • second_sheet 表格中提取
  • 仅提取 标题 4
  • 使用过滤器,其中 标题 4 的值只能包含字母或数字。
08:48 $ target/debug/madato table --type xlsx test/sample_multi_sheet.xlsx --sheetname second_sheet -c "Heading 4" -f 'Heading 4=[a-zA-Z0-9]'
|        Heading 4         |
|--------------------------|
|         << empty         |
|*Some Bolding in Markdown*|
|   `escaped value` foo    |
|           0.22           |
|         #DIV/0!          |
|  “This cell has quotes”  |
|       😕 ← Emoticon       |
  • 在列上过滤,确保在 趋势 列中存在 "+"。
09:00 $ target/debug/madato table --type xlsx test/sample_multi_sheet.xlsx --sheetname Sheet1 -c Rank -c Language -c Trend -f "Trend=\+"
|                         Rank                         |  Language  |Trend |
|------------------------------------------------------|------------|------|
|                          1                           |   Python   |+5.5 %|
|                          3                           | Javascript |+0.2 %|
|                          7                           |     R      |+0.0 %|
|                          12                          | TypeScript |+0.3 %|
|                          16                          |   Kotlin   |+0.5 %|
|                          17                          |     Go     |+0.3 %|
|                          20                          |    Rust    |+0.0 %|

内部结构

madato 使用

提示

  • 我发现将网站上的 "表格"(HTML)复制到电子表格中,然后通过 madato 转换,可以得到原始表格的优秀 Markdown 表格。

Python

pip install madato

# py
from IPython.display import display, Markdown
import madato
display(Markdown(madato.spreadsheet_to_md("../test/Financial Sample.xlsx")
print(madato.spreadsheet_to_md(str(my_sample_spreadsheet)))

更多命令行

表格列表

您可以使用以下命令列出 XLS*、ODS 文件的 "表格":

$ madato sheetlist test/sample_multi_sheet.xlsx 
Sheet1
second_sheet
3rd Sheet

YAML 转换 Markdown

Madato 以与读取电子表格相同的方式读取 "YAML" 文件。这对于在源代码库中 "保留" 表格数据非常有用,也许不是 XLS。

madato 表格-t yaml 测试/www-样本/测试.yml

|col3| col4  |  data1  |       data2        |
|----|-------|---------|--------------------|
|100 |gar gar|somevalue|someother value here|
|190x|       |  that   |        nice        |
|100 | ta da |  this   |someother value here|

请参阅 test/www-sample/test.yml 文件以了解此文件的预期布局

Excel/ODS 转换 YAML

将输出从默认的 "Markdown (MD)" 更改为 "YAML",您将得到一个电子表格的 Markdown 文件。

madato table -t xlsx test/sample_multi_sheet.xslx.xlsx -s Sheet1 -o yaml
---
- Rank: "1"
  Change: ""
  Language: Python
  Share: "23.59 %"
  Trend: "+5.5 %"
- Rank: "2"
  Change: ""
  Language: Java
  Share: "22.4 %"
  Trend: "-0.5 %"
- Rank: "3"
  Change: ""
  Language: Javascript
  Share: "8.49 %"
...

如果您省略表名,它将把所有表格都放入一个数组映射的顺序映射中。

功能

  • [x] 读取格式化的 YAML 字符串并渲染 Markdown 表格
  • [x] 可以接受一个可选的列标题列表,并且只显示表格中的那些(过滤掉其他列)
  • [X] 原生二进制命令行(windows、linux、osx)
  • [X] 读取 XLSX 文件并生成 Markdown 表格
  • [X] 读取 ODS 文件并生成 Markdown 表格
  • [X] 读取 CSV
  • [X] 发布为 Python 模块
  • [ ] TSV、PSV(等)文件并生成 Markdown 表格
  • [ ] 支持在 YAML 输入中嵌套结构
  • [ ] 读取 Markdown 文件,并选择 "表格",然后将其转换回 YAML

未来目标

已知问题

许可

Serde采用以下任一许可:

任选其一。

贡献

除非你明确声明,否则根据Apache-2.0许可证定义的,你提交给Serde的任何有意包含的贡献,将按照上述双重许可,不附加任何额外条款或条件。

依赖

~5–14MB
~168K SLoC