Skip to content

Office ドキュメントを Markdown に変換

Office Oxide のすべてのハンドルには to_markdown() メソッドがあり、6 形式のいずれからも GitHub-flavored Markdown — 見出し、テーブル、リスト、コードライクなブロック — を生成します。LLM や RAG パイプラインの入力として最も適したエントリポイントです。

ワンショット

Rust

use office_oxide::to_markdown;

let md = to_markdown("report.docx")?;
std::fs::write("report.md", md)?;

Python

import office_oxide

md = office_oxide.to_markdown("report.docx")
open("report.md", "w").write(md)

JavaScript

import { toMarkdown } from 'office-oxide';
import { writeFileSync } from 'node:fs';

writeFileSync('report.md', toMarkdown('report.docx'));

Go

md, err := officeoxide.ToMarkdown("report.docx")
os.WriteFile("report.md", []byte(md), 0o644)

C#

File.WriteAllText("report.md", OfficeOxide.ToMarkdown("report.docx"));

再利用可能なハンドル

Python

from office_oxide import Document

with Document.open("deck.pptx") as doc:
    md = doc.to_markdown()

Rust

let doc = office_oxide::Document::open("deck.pptx")?;
let md = doc.to_markdown();

JavaScript

using doc = Document.open('deck.pptx');
const md = doc.toMarkdown();

出力される内容

ソース要素 Markdown
DOCX 見出し(<w:pStyle w:val="Heading1"/> …) # Heading(レベルはスタイルに対応)
DOCX 段落 1 段落、ソフトハイフン除去
DOCX リスト項目 - 項目 または 1. 項目(番号付け維持)
DOCX テーブル GFM パイプテーブル
XLSX シート ## シート名 の後に範囲ごとのパイプテーブル
XLSX 結合セル 最初のセルの内容、span 削除
PPTX スライド ## スライド N + 本文、ノートは引用ブロックとして付加
PPTX テーブル スライド内インラインの GFM パイプテーブル
ハイパーリンク [テキスト](url)
画像 ![alt](filename) プレースホルダ — 下記「画像」を参照

画像

to_markdown() は画像をプレースホルダ(例: ![](image1.png))として出力しますが、画像バイトは抽出しません — Markdown はテキスト形式です。画像を取り出すには IR またはフォーマット固有のアクセスを使用:

from office_oxide import Document

with Document.open("report.docx") as doc:
    ir = doc.to_ir()
    for section in ir["sections"]:
        for el in section["elements"]:
            if el["kind"] == "Image":
                print(el["filename"], len(el["data"]))

完全なスキーマは IR 抽出 を参照。

ユースケース

  • RAG 取り込み — Markdown は最も LLM フレンドリーな入力形式。1 ドキュメント 1 パス、決定論的な構造、HTML ノイズなし。
  • ドキュメントインデックス化 — 見出しが自然なチャンク境界を提供、テーブルもクエリ可能なまま。
  • マイグレーション — 静的サイトジェネレータ(Hugo、Astro、MkDocs)への DOCX → Markdown。
  • コンテンツの差分 — Markdown 差分は .docx バイナリ差分よりはるかにレビューしやすい。

パフォーマンス

to_markdown()plain_text() と同じオーダーで動作 — 中央値ドキュメントで通常 1〜2 倍のコスト。完全な数値は パフォーマンス

関連項目

  • HTML 抽出 — スタイル付き出力が必要な場合
  • IR 抽出 — リッチなパイプライン用の構造化 JSON
  • PDF for RAG — PDF 用のコンパニオンライブラリ pdf_oxide