Skip to content

API-довідник

Зведений довідник поверхні Office Oxide, організований за концептами, а не за прив’язками. Кожна прив’язка повторює ту саму форму — імена слідують конвенціям мови (snake_case у Rust/Python, camelCase у JS, PascalCase у C#/.NET, Pascal у Go).

Document — read-handle

Відкрити з шляху; формат визначається за розширенням і magic-байтами.

Концепт 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() .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() (object) .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 тощо) — це lowercase-версії: "docx", "xlsx", "pptx", "doc", "xls", "ppt".

EditableDocument — read-modify-write

Та сама open-API, що в Document. Збереження зберігає всі незмінені 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

Editable-handle підтримує лише DOCX, XLSX, PPTX. Виклик replace_text на XLSX повертає 0 — використовуйте set_cell. Виклик set_cell на DOCX/PPTX викине помилку.

Хелпери модульного рівня

Хелпер Повертає Доступний у
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 Element диспатчиться за полем kind ("Heading", "Paragraph", "List", "Table", "Image").

Помилки

Помилки виставляють типізований код і ім’я операції, яка зірвалася.

Код Значення
0 OK
1 Невалідний аргумент (nil-вказівник, невідомий рядок формату)
2 I/O-помилка
3 Помилка парсингу (пошкоджений документ)
4 Збій видобування (парсинг ОК, але рендер не вдався)
5 Внутрішня помилка (баг — заведіть issue)
6 Не підтримується (розширення або фіча)
Прив’язка Тип
Rust office_oxide::OfficeError (enum)
Python OfficeOxideError (виняток, .code, .operation)
JavaScript OfficeOxideError (підклас Error, .code, .operation)
Go *officeoxide.Error (.Code, .Op)
C# OfficeOxideException (.Code, .Operation)
C int *error_code out-параметр

Feature-флаги (Rust-крейт)

[dependencies]
office_oxide = { version = "0.1.0", features = ["mmap", "parallel"] }
Feature Ефект
mmap Document::open_mmap для zero-copy відкриття OOXML
parallel rayon-based хелпери паралельного парсингу
serde (за замовчуванням) Serialize / Deserialize на типах IR
python PyO3-прив’язки (використовуються при збірці office-oxide-wheel для PyPI)

Підмодулі за форматами (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

Використовуйте підмодулі, коли потрібен форматно-специфічний доступ — ітерація листів, маніпуляції слайдами, custom XML — поза тим, що виставляє уніфікований Document.

Дивіться також