Office ドキュメントからテキストを抽出
Office Oxide は唯一のエントリポイント extract_text()(または Document.open(...).plain_text())を、DOCX、XLSX、PPTX、DOC、XLS、PPT すべてで同じように動作させます。フォーマット固有のコードパスは不要。
ワンショットヘルパー
最速の方法: 1 つの関数呼び出しでファイルを開き、フォーマットに応じた抽出を実行し、文字列を返します。
Rust
use office_oxide::extract_text;
let text = extract_text("report.docx")?;
println!("{text}");
Python
import office_oxide
text = office_oxide.extract_text("report.docx")
print(text)
JavaScript
import { extractText } from 'office-oxide';
console.log(extractText('report.docx'));
Go
import officeoxide "github.com/yfedoseev/office_oxide/go"
text, err := officeoxide.ExtractText("report.docx")
C#
using OfficeOxide;
string text = OfficeOxide.ExtractText("report.docx");
再利用可能なハンドル
テキスト + 他の出力(Markdown、HTML、IR)が必要なら、ドキュメントを一度だけ開いてハンドルを再利用:
Rust
use office_oxide::Document;
let doc = Document::open("report.docx")?;
let text = doc.plain_text();
let md = doc.to_markdown();
Python
from office_oxide import Document
with Document.open("report.docx") as doc:
text = doc.plain_text()
md = doc.to_markdown()
JavaScript
import { Document } from 'office-oxide';
using doc = Document.open('report.docx');
const text = doc.plainText();
const md = doc.toMarkdown();
フォーマット別の出力内容
| フォーマット | 出力 |
|---|---|
| DOCX | ドキュメント順の本文、ヘッダ、フッタ。ソフトハイフン除去 |
| XLSX | 各シートのセル値、行内はタブ区切り、シート間は空行 |
| PPTX | スライドタイトル、本文プレースホルダ、テーブルセル、ノート — スライドごとに段落ブロック |
| DOC | DOCX と同じ形 — CFB ピーステーブルから直接パース |
| XLS | XLSX と同じ形 — BIFF8 レコードから直接パース |
| PPT | PPTX と同じ形 — PowerPoint Document ストリームからパース |
バイトから(一時ファイル不要)
サーバーレス・ストリーミングのパイプラインに有効。
Python
import requests
from office_oxide import Document
data = requests.get("https://example.com/report.docx").content
with Document.from_bytes(data, "docx") as doc:
print(doc.plain_text())
JavaScript
import { Document } from 'office-oxide';
const res = await fetch('https://example.com/report.docx');
const data = new Uint8Array(await res.arrayBuffer());
using doc = Document.fromBytes(data, 'docx');
console.log(doc.plainText());
Rust
use std::io::Cursor;
use office_oxide::{Document, DocumentFormat};
let data = std::fs::read("report.docx")?;
let doc = Document::from_reader(Cursor::new(data), DocumentFormat::Docx)?;
let text = doc.plain_text();
パフォーマンス
| フォーマット | 平均 | p99 | 通過率 |
|---|---|---|---|
| DOCX (2,538 ファイル) | 0.8ms | 3.9ms | 98.9% |
| XLSX (1,802 ファイル) | 5.0ms | 40ms | 97.8% |
| PPTX (806 ファイル) | 0.7ms | 3.9ms | 98.4% |
| DOC (246 ファイル) | 0.3ms | 3.4ms | 94.7% |
| XLS (494 ファイル) | 2.8ms | 75ms | 99.2% |
| PPT (176 ファイル) | 0.7ms | 6.6ms | 100% |
詳細な計測手順は パフォーマンス を参照。
関連項目
- Markdown 抽出 — 同じ API、GitHub-flavored 出力
- HTML 抽出 — プレビューや埋め込み用のセマンティック HTML
- フォーマット非依存の IR — パイプラインや LLM 用の構造化 JSON
- テーブル — XLSX、DOCX、PPTX から構造化された行を取り出す