office_toolkit/lib.rs
1//! `office-toolkit` — facade crate for the toolkit.
2//!
3//! Single entry point re-exporting the public API of the format-specific crates, each behind its
4//! own same-named Cargo feature — but all three enabled by `full`, which is also this crate's own
5//! default. A plain `cargo add office-toolkit` compiles and works with zero configuration; the
6//! features exist for anyone who wants to opt out of formats they don't use (smaller binary, faster
7//! build), never as a requirement to get started. Simplicity for the common case was chosen
8//! deliberately over "pay only for what you use by default".
9//!
10//! # Module layout
11//!
12//! - [`word`] — everything from `word_ooxml`, when the `word` feature is enabled (on by default).
13//! - [`excel`] — everything from `excel_ooxml`, when the `excel` feature is enabled (on by
14//! default).
15//! - [`powerpoint`] — everything from `powerpoint_ooxml`, when the `powerpoint` feature is enabled
16//! (on by default).
17//! - [`drawing`]/[`chart`] — the two crates shared across all three formats (shape/text
18//! formatting, embedded charts respectively) — always available, unconditionally, since every
19//! format needs them to add an image, a shape, or a chart.
20//! - [`prelude`] — the handful of types used constantly regardless of format
21//! (`Document`/`Workbook`/`Presentation`, each format's most basic content-building type —
22//! `Paragraph`/`Row`/`Slide` — plus the most common `drawing` types), re-exported unprefixed, so
23//! `use office_toolkit::prelude::*;` alone is enough to start writing code.
24//!
25//! Everything deeper stays in its own namespaced module above — that namespacing isn't optional
26//! there: several types (`DocumentProperties`, `Theme`, `ColorScheme`, `CustomPropertyValue`)
27//! intentionally share the same name across two or three formats (kept consistent between them on
28//! purpose), so re-exporting all of them flat at this crate's root would collide.
29//!
30//! [`open`] auto-detects a `.docx`/`.xlsx`/`.pptx` file's format from the package's own content
31//! (not the file's name or extension) and returns a single [`OfficeDocument`];
32//! [`OpenFile`]/[`SaveToFile`] add `open_file`/`save_to_file` methods directly on
33//! `Document`/`Workbook`/`Presentation` for the more common case where the caller already knows
34//! which format they're working with.
35//!
36//! # Example
37//!
38//! ```no_run
39//! use office_toolkit::prelude::*;
40//! use office_toolkit::SaveToFile;
41//!
42//! # fn main() -> office_toolkit::Result<()> {
43//! // Build a minimal Word document and save it — `Document` and `Paragraph` both come straight
44//! // from the prelude. `save_to_file` comes from the `SaveToFile` trait (see [`SaveToFile`]) —
45//! // it has to be imported explicitly like any trait method, the prelude only covers types, not
46//! // traits.
47//! let document = Document::new().with_paragraph(Paragraph::with_text("Hello, world!"));
48//! document.save_to_file("hello.docx")?;
49//!
50//! // Open any .docx/.xlsx/.pptx without knowing its format ahead of time.
51//! let opened = office_toolkit::open("hello.docx")?;
52//! opened.save_to_file("hello-resaved.docx")?;
53//! # Ok(())
54//! # }
55//! ```
56
57#[cfg(feature = "word")]
58pub mod word {
59 //! Everything from `word_ooxml` — reading and writing `.docx`.
60 pub use word_ooxml::*;
61}
62
63#[cfg(feature = "excel")]
64pub mod excel {
65 //! Everything from `excel_ooxml` — reading and writing `.xlsx`.
66 pub use excel_ooxml::*;
67}
68
69#[cfg(feature = "powerpoint")]
70pub mod powerpoint {
71 //! Everything from `powerpoint_ooxml` — reading and writing `.pptx`.
72 pub use powerpoint_ooxml::*;
73}
74
75pub mod drawing {
76 //! Everything from the `drawing` crate — shape/text formatting shared by every format (fill,
77 //! line, geometry, text body...). Always available: unlike `word`/`excel`/`powerpoint`, not
78 //! gated by a feature, since it has no meaningful "opt out" — any format that has images or
79 //! shapes at all needs it.
80 pub use ::drawing::*;
81}
82
83pub mod chart {
84 //! Everything from the `chart` crate — embedded charts, shared by every format. Always
85 //! available, same reasoning as [`crate::drawing`].
86 pub use ::chart::*;
87}
88
89pub mod prelude {
90 //! The handful of types needed to get started with any format, re-exported unprefixed. See the
91 //! crate-level doc comment for why only these (and not the rest of the API) live here.
92 //!
93 //! Alongside each format's entry point, its single most basic content-building type is included
94 //! too (`Paragraph` for Word, `Row` for Excel, `Slide` for PowerPoint) — without at least one
95 //! of these, `prelude::*` alone can't build so much as a "Hello, world!" file, which defeats
96 //! the point of a prelude. `Cell` (Excel) is included too: `Sheet::write_cell` accepts a raw
97 //! `&str`/`f64`/`bool` directly for the common cases, but reading a workbook back, or writing a
98 //! formula/date/rich-text cell, still means naming `Cell`/`CellValue` explicitly. None of these
99 //! collide with anything else re-exported here or in another format's own module.
100
101 #[cfg(feature = "excel")]
102 pub use excel_ooxml::{Cell, Row, Workbook};
103 #[cfg(feature = "powerpoint")]
104 pub use powerpoint_ooxml::{Presentation, Slide};
105 #[cfg(feature = "word")]
106 pub use word_ooxml::{Document, Paragraph};
107
108 pub use ::drawing::{Color, Fill, ShapeProperties, Transform2D};
109}
110
111mod document;
112mod error;
113
114pub use document::{OfficeDocument, OpenFile, SaveToFile, open};
115pub use error::{Error, Result};