python-pptx からの移行
Office Oxide は PPTX を python-pptx より 46 倍高速 に読み取ります(806 ファイルで平均 0.7 ms 対 32.5 ms)、パス率は 11.7 ポイント高い。レガシー .ppt も直接読めます — python-pptx にはできません。
いつ移行するか
以下のいずれかをやっているなら切り替えを:
- 取り込み / RAG のために
.pptxからスライドテキスト、ノート、テーブルを抽出 - プレビュー用にデッキを Markdown や HTML に変換
- 検索置換のテンプレート化(“Q3 → Q4”、“{{quarter}}”、“{{growth}}”)を実行
- LibreOffice にシェルアウトせずに
.pptサポートが必要 .docx、.xlsx、レガシーフォーマットもカバーする 1 つのライブラリが欲しい
python-pptx に留まる方がよい場合:
- カスタムレイアウト、アニメーション、トランジション、図形ジオメトリで複雑な PPTX をゼロから構築
- スライドレイアウト XML のきめ細かな制御が必要
インストール
pip uninstall python-pptx
pip install office-oxide
並べて比較するチートシート
すべてのスライドテキストを読む
python-pptx
from pptx import Presentation
prs = Presentation("deck.pptx")
for slide in prs.slides:
for shape in slide.shapes:
if shape.has_text_frame:
for para in shape.text_frame.paragraphs:
for run in para.runs:
print(run.text)
office_oxide
from office_oxide import Document
with Document.open("deck.pptx") as doc:
text = doc.plain_text()
print(text)
スライドごとのイテレーション
python-pptx
prs = Presentation("deck.pptx")
for i, slide in enumerate(prs.slides, 1):
title = slide.shapes.title.text if slide.shapes.title else "(no title)"
print(f"slide {i}: {title}")
office_oxide
with Document.open("deck.pptx") as doc:
ir = doc.to_ir()
for i, section in enumerate(ir["sections"], 1):
print(f"slide {i}: {section.get('title') or '(no title)'}")
各 IR セクションは 1 つのスライドに対応します。section["title"] はタイトルプレースホルダから来ます。
スライド上のテーブルを読む
python-pptx
for slide in prs.slides:
for shape in slide.shapes:
if shape.has_table:
for row in shape.table.rows:
cells = [c.text for c in row.cells]
print(cells)
office_oxide
with Document.open("deck.pptx") as doc:
ir = doc.to_ir()
for section in ir["sections"]:
for el in section["elements"]:
if el["kind"] == "Table":
for row in el["rows"]:
print(row)
スピーカーノートを読む
python-pptx
for slide in prs.slides:
if slide.has_notes_slide:
print(slide.notes_slide.notes_text_frame.text)
office_oxide
plain_text() と to_markdown() はデフォルトでノートを含みます — 各スライドセクションの末尾に追加されます。ノートを個別に取得したいなら、フォーマット固有のアクセサを使います:
with Document.open("deck.pptx") as doc:
pptx = doc.as_pptx()
for i, slide in enumerate(pptx.slides(), 1):
notes = slide.notes()
if notes:
print(f"slide {i} notes: {notes}")
テンプレート化(検索と置換)
python-pptx — ファーストクラス API なし; 一般的なパターンはすべての shape のテキストフレームを歩いて書き換えることです。クロス run マッチで壊れやすい。
office_oxide
from office_oxide import EditableDocument
with EditableDocument.open("deck_template.pptx") as ed:
ed.replace_text("{{quarter}}", "Q4 2026")
ed.replace_text("{{growth}}", "+18.4%")
ed.save("q4_deck.pptx")
replace_text はすべてのスライドとノートスライドの <a:t> をすべて歩き、変更されていないすべての OPC パーツ(画像、グラフ、レイアウト、テーマ)を温存します。
Markdown / HTML に変換
python-pptx — 組み込みなし。
office_oxide
with Document.open("deck.pptx") as doc:
md = doc.to_markdown()
html = doc.to_html()
Markdown 出力はスライドごとに ## Slide N セクション 1 つで、本文とノートがブロッククォートとして付加されます。
レガシー .ppt の読み取り
python-pptx は .ppt を開けません。Office Oxide は直接読めます:
from office_oxide import Document
with Document.open("legacy.ppt") as doc:
print(doc.plain_text())
doc.save_as("modern.pptx") # 1 行で移行
パフォーマンス
| ライブラリ | 平均 | p99 | 通過率 |
|---|---|---|---|
| office_oxide | 0.7 ms | 3.9 ms | 98.4% |
| python-pptx | 32.5 ms | 174 ms | 86.7% |
10 万デッキの取り込みが python-pptx で 54 分 かかるところ、office_oxide なら 70 秒 で完了します。
失われるもの
EditableDocument がテンプレート用途をカバーします。よりリッチな PPTX 構築 — スライド追加、カスタムレイアウト、チャート、アニメーション — には office_oxide.pptx::create::PptxBuilder に降りるか、作成ステップでは python-pptx に留まって取り込みに office_oxide を使ってください。
関連項目
- テキストを置換 —
replace_textのセマンティクスと run 境界の扱い - RAG のための Office — スライド認識チャンキング
- パフォーマンスベンチマーク