You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Pandoc将Docx转换为带管道式Markdown表格?

Pandoc转换DOCX为Markdown:生成标准管道表格的解决方法

问题描述

我用Pandoc把DOCX文件转成Markdown,执行命令:

pandoc -f docx -t gfm /Users/andrewshostak/Downloads/MV-family-datasheet-240207-r4-1.docx -o res.md

输出里的表格是HTML格式。试了不同的-t参数:markdown_mmd、commonmark结果一致;用markdown或不指定-t会生成格式错乱的窄表格;gfm-raw_html直接显示[TABLE]文本而非表格。需要生成带管道的标准Markdown表格,且表格不含图片,期望输出示例如下:

|                       | MV52-HW           | MV63-HW MV63X-HW          | MV72-HW MV72X-HW                  | MV93-HW MV93X-HW                  |
|-----------------------|-------------------|---------------------------|----------------------------------|----------------------------------|
| **Camera type**       | Telephoto bullet  | Fixed-lens mini dome      | Varifocal dome                   | Fisheye                          |
| **Sensor and resolution** | 8.4MP (3840x2160) | 8.4MP (3854x2176) MV63HW/4K (3840x2160) HW63X-HW | MV72-HW (1920x1080)/4MP (2688x1520) | MV93-HW (2112x2112)/12.4MP (4072x3046) MV93X-HW |
| **Field of View**     | 12-37°            | 102°                      | Horizontal 36-112°, vertical 20-57°, diagonal 42-138° | 360°                            |
| **Storage**           | 1TB               | 256GB (MV63-HW)/1TB       | 256GB (MV72-HW)/512GB             | 256GB (MV93-HW)/1TB              |
| **Ratings**           | IK10+/IP67        | IK10+/IP67                | IK10+/IP67                        | IK10+/IP67                      |
| **IR illumination**   | 50m               | 20m                       | 30m                               | 20m                             |
| **Best for**          | Ideal for parking lots or perimeter monitoring including license plate capture | Ideal for entrances and exits, Filter-based attributes (top/ bottom clothing color and make and color of vehicle) | A variety of outdoor and demanding environments | Ideal for situational awareness and wide coverage of an area |

解决方案

使用以下命令,强制生成管道表格并移除表格内的图片:

pandoc -f docx --extract-media=./media -t markdown+pipe_tables-raw_html --wrap=none --columns=1000 /Users/andrewshostak/Downloads/MV-family-datasheet-240207-r4-1.docx -o res.md

参数说明:

  • --extract-media=./media:将DOCX中的图片提取到当前目录的media文件夹,彻底移除表格内的图片元素
  • -t markdown+pipe_tables-raw_html:指定输出为Markdown格式,启用pipe_tables扩展生成管道表格,禁用raw_html避免输出HTML表格
  • --wrap=none:禁止内容自动换行,保证表格内容完整显示在对应列中
  • --columns=1000:设置足够大的列宽阈值,避免Pandoc将表格拆分成窄表格导致格式错乱

补充说明

如果DOCX表格存在合并单元格,由于Markdown管道表格本身不支持该格式,转换后需要手动调整单元格内容对齐。如果仍有格式问题,可以先在Word中简化表格结构(比如拆分合并单元格)后再执行转换。

内容的提问来源于stack exchange,提问作者Neilord

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 04:36:31