專業的文件批次處理技能,支援舊版 Office 文件(.doc/.xls)高質量轉換為 Markdown,保持格式結構完整。
.doc → .md(LibreOffice 直接轉換).docx → .md(LibreOffice 直接轉換)7w4.net小蔥技能。
.xls → .xlsx → .md(保留表格結構).ppt → .pptx → .md(可選支援).xlsx/.pptx → .md(MarkItDown 直接處理)# 安裝 LibreOffice(系統級)
# 下載: https://zh-cn.libreoffice.org/
# 安裝 Python 依賴
pip install markitdown[docx,xlsx]
# 互動模式(推薦)
npx skills run document-organizer
# 命令列引數
npx skills run document-organizer --source "源目錄" --output "輸出目錄" --type doc,xls
首次執行會檢測 LibreOffice 路徑,預設:
- Windows: D:\Program Files\LibreOffice\program\soffice.exe
- Linux: /usr/bin/soffice
- macOS: /Applications/LibreOffice.app/Contents/MacOS/soffice
| 源格式 | 轉換流程 | 輸出格式 | 質量 |
|---|---|---|---|
.doc |
LibreOffice → Markdown | .md |
✅ 完美 |
.docx |
LibreOffice → Markdown | .md |
✅ 完美 |
.xls |
LibreOffice → .xlsx → MarkItDown → .md | .md |
✅ 完美 |
.xlsx |
MarkItDown → .md | .md |
✅ 完美 |
.ppt |
LibreOffice → .pptx → MarkItDown → .md | .md |
✅ 良好 |
.pptx |
MarkItDown → .md | .md |
✅ 良好 |
.pdf |
MarkItDown → .md | .md |
✅ 優秀(文本+表格) |
方案一:分類批次(推薦)
批次轉換所有 .doc 檔案:
soffice --convert-to md *.doc
批次轉換所有 .docx 檔案:
soffice --convert-to md *.docx
批次轉換所有 .xls 檔案:
soffice --convert-to xlsx *.xls → markitdown *.xlsx
批次轉換所有 .ppt 檔案:
soffice --convert-to pptx *.ppt → markitdown *.pptx
方案二:遞迴處理
掃描目錄樹,按檔案型別分組
分別批次轉換每個子目錄
保持完整目錄結構輸出
# 掃描源目錄
npx skills run document-organizer --source "G:\歷史文件" --output "d:\知識庫"
輸出結構:
知識庫/
├── 專案A/
│ ├── 需求文件.md
│ └── 設計文件.md
└── 專案B/
└── 會議記錄.md
npx skills run document-organizer --source "G:\docs" --output "d:\md" --filter .doc,.docx
npx skills run document-organizer --source "G:\pdfs" --type pdf --output "d:\pdf_md"
npx skills run document-organizer --scan-only "G:\docs"
# 輸出: 檔案統計,不執行轉換
| 引數 | 型別 | 預設值 | 說明 |
|---|---|---|---|
--source |
string | 必需 | 源目錄路徑 |
--output |
string | ./output |
輸出目錄 |
--type |
string | doc,xls,docx,xlsx,ppt,pptx,pdf |
處理的檔案型別(逗號分隔) |
--soffice-path |
string | 自動檢測 | LibreOffice soffice.exe 路徑 |
--log-file |
string | conversion.log |
日誌檔案路徑 |
--dry-run |
bool | false |
僅模擬,不實際轉換 |
測試環境: i5 CPU, 16GB RAM, SSD
| 操作 | 數量 | 耗時 | 吞吐 |
|---|---|---|---|
| .doc → .md (LibreOffice) | 1,000 | ~30 秒 | 33 個/秒 |
| .xls → .xlsx (LibreOffice) | 2,000 | ~1.5 分鐘 | 22 個/秒 |
| .xlsx → .md (MarkItDown) | 2,000 | ~2 分鐘 | 17 個/秒 |
| .ppt → .pptx (LibreOffice) | 500 | ~30 秒 | 17 個/秒 |
| .pptx → .md (MarkItDown) | 500 | ~1 分鐘 | 8 個/秒 |
| .pdf → .md (MarkItDown) | 500 | ~2 分鐘 | 4 個/秒 |
| 總計 (3,000檔案) | 3,000 | ~10-12 分鐘 | - |
A: 確保安裝並新增到 PATH,或通過 --soffice-path 指定:
npx skills run document-organizer --soffice-path "C:\Program Files\LibreOffice\program\soffice.exe"
A: 檢查錯誤日誌,常見原因:
- 原始檔損壞
- 臨時檔案(~$ 開頭)自動跳過
- 許可權不足(以管理員執行)
A: 使用 --dry-run 引數:
npx skills run document-organizer --source "docs" --dry-run
# 輸出: 將轉換 X 個檔案,Y 個目錄,跳過 Z 個
A: 結合 --filter 和路徑模式:
npx skills run document-organizer --source "docs" --filter "00_模板/*.doc"
┌─────────────────┐
│ 使用者命令 │
│ npx skills ... │
└────────┬────────┘
│
▼
┌─────────────────────────────────────────────┐
│ 文件整理技能 (Python) │
│ • 掃描目錄樹 │
│ • 按型別分組 (doc/xls/docx/xlsx) │
│ • 呼叫 LibreOffice 批次轉換 │
│ • 呼叫 MarkItDown 結構化轉換 │
│ • 保持目錄結構 + 重新命名 │
│ • 錯誤處理 + 日誌記錄 │
└─────────────────────────────────────────────┘
│
▼
┌─────────────────┐ ┌──────────────────┐
│ LibreOffice │ │ MarkItDown │
│ (格式轉換) │ │ (結構化輸出) │
└─────────────────┘ └──────────────────┘
│ │
└───────────┬───────────┘
▼
┌─────────────┐
│ .md 檔案 │
│ (可搜尋) │
└─────────────┘
| 工具 | 版本要求 | 用途 |
|---|---|---|
| LibreOffice | 7.0+ | .doc → .docx / .xls → .xlsx |
| Python | 3.10+ | 指令碼執行 |
| markitdown | 0.1.5+ | .docx/.xlsx → .md |
| pywin32 | (可選) | Windows COM 自動化(備用) |
本技能包含以下指令碼:
| 檔案 | 說明 |
|---|---|
scripts/batch_convert.py |
主指令碼 - 批次文件轉換(支援 .doc/.xls/.docx/.xlsx/.ppt/.pptx/.pdf) |
strings 命令即可)最佳化:增加 markitdown 命令的自動檢測邏輯
v1.0.3 (2026-03-12)
--temp-dir 引數最佳化:文件與實際指令碼保持一致
v1.0.2 (2026-03-11)
最佳化:--dry-run 模式跳過 LibreOffice 檢查
v1.0.0 (2026-03-11)
最後更新: 2026-03-12
適用平臺: Windows/Linux/macOS (需 LibreOffice)
許可證: MIT
這個工具質量不錯,能把 Word、Excel、PPT、PDF 文件批次轉成 Markdown 格式,中文支援好,保持原目錄結構,適合整理歷史文件庫。優點是支援的格式多、批次處理快、有預覽功能。主要問題是使用前需要手動安裝 LibreOffice 和 Python 工具,對新手不太友好,偶爾轉換大檔案時可能超時出錯。