Skip to content

API リファレンス

Office Oxide のサーフェスをバインディング別ではなく概念別にまとめたリファレンス。各バインディングは同じ形をミラーします — 名前は言語の慣習に従います(Rust/Python は snake_case、JS は camelCase、C#/.NET は PascalCase、Go は Pascal)。

Document — 読み取りハンドル

パスから開く; フォーマットは拡張子とマジックバイトから検出。

概念 Rust Python JavaScript Go C# C
ファイルを開く Document::open(path) Document.open(path) Document.open(path) officeoxide.Open(path) Document.Open(path) office_document_open
バイトから開く Document::from_reader(r, fmt) Document.from_bytes(b, fmt) Document.fromBytes(b, fmt) OpenFromBytes(b, fmt) Document.FromBytes(b, fmt) office_document_open_from_bytes
フォーマット .format() .format .format .Format() .Format office_document_format
プレーンテキスト .plain_text() .plain_text() .plainText() .PlainText() .PlainText() office_document_plain_text
Markdown .to_markdown() .to_markdown() .toMarkdown() .ToMarkdown() .ToMarkdown() office_document_to_markdown
HTML .to_html() .to_html() .toHtml() .ToHTML() .ToHtml() office_document_to_html
IR .to_ir()(型付き) .to_ir()(dict) .toIr()(オブジェクト) .ToIRJSON() .ToIrJson() office_document_to_ir_json
保存 / 変換 .save_as(path) .save_as(path) .saveAs(path) .SaveAs(path) .SaveAs(path) office_document_save_as
クローズ drop with ブロック終了 close() / using .Close() Dispose / using office_document_free

DocumentFormat

Docx | Xlsx | Pptx | Doc | Xls | Ppt

FFI 境界(from_bytes など)で使われるフォーマット文字列はこれらの 小文字 版: "docx""xlsx""pptx""doc""xls""ppt"

EditableDocument — read-modify-write

Document と同じオープン API。保存ではすべての変更されていない OPC パーツを温存します。

概念 Rust Python JavaScript Go C# C
開く EditableDocument::open EditableDocument.open EditableDocument.open OpenEditable EditableDocument.Open office_editable_open
テキスト置換 .replace_text(n, r) .replace_text(n, r) .replaceText(n, r) .ReplaceText(n, r) .ReplaceText(n, r) office_editable_replace_text
XLSX セル設定 .set_cell(idx, ref, v) .set_cell(idx, ref, v) .setCell(idx, ref, v) .SetCell(idx, ref, v) .SetCell(idx, ref, v) office_editable_set_cell
保存 .save(path) .save(path) .save(path) .Save(path) .Save(path) office_editable_save
バイト保存 .write_to(w) .save_to_bytes() .saveToBytes() .SaveToBytes() .SaveToBytes() office_editable_save_to_bytes

編集可能ハンドルは DOCX、XLSX、PPTX のみ をサポートします。XLSX で replace_text を呼ぶと 0 を返すので set_cell を使用。DOCX/PPTX で set_cell を呼ぶとエラー。

モジュールレベルヘルパー

ヘルパー 戻り値 利用可能
extract_text(path) UTF-8 文字列 全バインディング
to_markdown(path) GFM Markdown 文字列 全バインディング
to_html(path) HTML フラグメント文字列 全バインディング
detect_format(path) フォーマット名または null 全バインディング
version() "0.1.0" 全バインディング
create_from_ir(ir, fmt, path) unit / void Rust、Python

DocumentIR — スキーマ

DocumentIR {
    sections: [Section]
}

Section {
    title:    Option<string>
    elements: [Element]
}

Element = Heading   { level, text }
        | Paragraph { runs: [Run] }
        | List      { ordered, items: [string] }
        | Table     { rows: [[string]] }
        | Image     { filename, data: bytes }

Run {
    text, bold, italic, underline, hyperlink: Option<string>
}

Python では Elementkind フィールド("Heading""Paragraph""List""Table""Image")でディスパッチされます。

エラー

エラーは型付きコードと失敗オペレーション名を公開します。

Code 意味
0 OK
1 不正な引数(nil ポインタ、不明なフォーマット文字列)
2 I/O エラー
3 パースエラー(壊れたドキュメント)
4 抽出失敗(パースは成功したがレンダリングが失敗)
5 内部エラー(バグ — issue を上げてください)
6 未対応(拡張子または機能)
バインディング
Rust office_oxide::OfficeError(enum)
Python OfficeOxideError(exception、.code.operation
JavaScript OfficeOxideError(Error サブクラス、.code.operation
Go *officeoxide.Error.Code.Op
C# OfficeOxideException.Code.Operation
C int *error_code 出力パラメータ

フィーチャフラグ(Rust クレート)

[dependencies]
office_oxide = { version = "0.1.0", features = ["mmap", "parallel"] }
フィーチャ 効果
mmap ゼロコピーの OOXML オープンに Document::open_mmap
parallel rayon ベースの並列パースヘルパー
serde (デフォルト)IR 型に Serialize / Deserialize
python PyO3 バインディング(office-oxide PyPI wheel ビルドで使用)

フォーマット別サブモジュール(Rust)

office_oxide::docx   — DocxDocument、DocxBuilder、edit::DocxEditor
office_oxide::xlsx   — XlsxDocument、XlsxBuilder、edit::{XlsxEditor, CellValue}
office_oxide::pptx   — PptxDocument、PptxBuilder、edit::PptxEditor
office_oxide::doc    — DocDocument
office_oxide::xls    — XlsDocument
office_oxide::ppt    — PptDocument
office_oxide::ir     — DocumentIR、Section、Element、Run
office_oxide::edit   — EditableDocument
office_oxide::create — create_from_ir

統一 Document で公開される範囲を超えるフォーマット固有アクセス — シート反復、スライド操作、カスタム XML — が必要なときに使用。

関連項目