Expand description
office-toolkit — facade crate for the toolkit.
Single entry point re-exporting the public API of the format-specific crates, each behind its
own same-named Cargo feature — but all three enabled by full, which is also this crate’s own
default. A plain cargo add office-toolkit compiles and works with zero configuration; the
features exist for anyone who wants to opt out of formats they don’t use (smaller binary, faster
build), never as a requirement to get started. Simplicity for the common case was chosen
deliberately over “pay only for what you use by default”.
§Module layout
word— everything fromword_ooxml, when thewordfeature is enabled (on by default).excel— everything fromexcel_ooxml, when theexcelfeature is enabled (on by default).powerpoint— everything frompowerpoint_ooxml, when thepowerpointfeature is enabled (on by default).drawing/chart— the two crates shared across all three formats (shape/text formatting, embedded charts respectively) — always available, unconditionally, since every format needs them to add an image, a shape, or a chart.prelude— the handful of types used constantly regardless of format (Document/Workbook/Presentation, each format’s most basic content-building type —Paragraph/Row/Slide— plus the most commondrawingtypes), re-exported unprefixed, souse office_toolkit::prelude::*;alone is enough to start writing code.
Everything deeper stays in its own namespaced module above — that namespacing isn’t optional
there: several types (DocumentProperties, Theme, ColorScheme, CustomPropertyValue)
intentionally share the same name across two or three formats (kept consistent between them on
purpose), so re-exporting all of them flat at this crate’s root would collide.
open auto-detects a .docx/.xlsx/.pptx file’s format from the package’s own content
(not the file’s name or extension) and returns a single OfficeDocument;
OpenFile/SaveToFile add open_file/save_to_file methods directly on
Document/Workbook/Presentation for the more common case where the caller already knows
which format they’re working with.
§Example
use office_toolkit::prelude::*;
use office_toolkit::SaveToFile;
// Build a minimal Word document and save it — `Document` and `Paragraph` both come straight
// from the prelude. `save_to_file` comes from the `SaveToFile` trait (see [`SaveToFile`]) —
// it has to be imported explicitly like any trait method, the prelude only covers types, not
// traits.
let document = Document::new().with_paragraph(Paragraph::with_text("Hello, world!"));
document.save_to_file("hello.docx")?;
// Open any .docx/.xlsx/.pptx without knowing its format ahead of time.
let opened = office_toolkit::open("hello.docx")?;
opened.save_to_file("hello-resaved.docx")?;Modules§
- chart
- Everything from the
chartcrate — embedded charts, shared by every format. Always available, same reasoning ascrate::drawing. - drawing
- Everything from the
drawingcrate — shape/text formatting shared by every format (fill, line, geometry, text body…). Always available: unlikeword/excel/powerpoint, not gated by a feature, since it has no meaningful “opt out” — any format that has images or shapes at all needs it. - excel
- Everything from
excel_ooxml— reading and writing.xlsx. - powerpoint
- Everything from
powerpoint_ooxml— reading and writing.pptx. - prelude
- The handful of types needed to get started with any format, re-exported unprefixed. See the crate-level doc comment for why only these (and not the rest of the API) live here.
- word
- Everything from
word_ooxml— reading and writing.docx.
Enums§
- Error
- Errors from
office-toolkit’s own file-level convenience layer. - Office
Document - A document opened by
open, with its format determined at runtime from the file’s own content rather than assumed up front. Match on this when the caller genuinely doesn’t know the format ahead of time; when it does,OpenFile::open_fileon the concrete type (word::Document::open_file(...), etc.) skips the enum entirely.
Traits§
- Open
File - Reads a
Document/Workbook/Presentationdirectly from a path on disk —word::Document::open_file("report.docx")?instead of manually opening aFileand calling the type’s ownread_from. For the common case where the caller already knows which format they’re working with; seeopenfor auto-detection. - Save
ToFile - Writes a
Document/Workbook/Presentationdirectly to a path on disk —doc.save_to_file("report.docx")?instead of manually creating aFileand calling the type’s ownwrite_to.
Functions§
- open
- Opens a
.docx/.xlsx/.pptxfile, detecting its format from the OPC package’s own parts (word/document.xml/xl/workbook.xml/ppt/presentation.xml) rather than from the file’s extension or name — a renamed or extension-less file still opens correctly, and a file carrying none of the three is reported asError::UnrecognizedFormatrather than silently misidentified as one of them. A file whose format is recognized, but whose matching Cargo feature isn’t enabled in this build, is reported asError::FormatNotEnabledinstead — a more useful answer than pretending the file doesn’t exist.