Skip to main content

ooxml_sml/
lib.rs

1//! SpreadsheetML (XLSX) support for the ooxml library.
2//!
3//! This crate provides reading and writing of Excel spreadsheets (.xlsx files).
4//!
5//! # Reading Workbooks
6//!
7//! ```no_run
8//! use ooxml_sml::{CellResolveExt, RowExt, Workbook};
9//!
10//! let mut workbook = Workbook::open("spreadsheet.xlsx")?;
11//! for sheet in workbook.resolved_sheets()? {
12//!     println!("Sheet: {}", sheet.name());
13//!     for row in sheet.rows() {
14//!         for cell in row.cells_iter() {
15//!             print!("{}\t", cell.value_as_string(sheet.context()));
16//!         }
17//!         println!();
18//!     }
19//! }
20//! # Ok::<(), ooxml_sml::Error>(())
21//! ```
22//!
23//! # Writing Workbooks
24//!
25//! ```no_run
26//! use ooxml_sml::WorkbookBuilder;
27//!
28//! let mut wb = WorkbookBuilder::new();
29//! let sheet = wb.add_sheet("Sheet1");
30//! sheet.set_cell("A1", "Hello");
31//! sheet.set_cell("B1", 42.0);
32//! sheet.set_cell("C1", true);
33//! wb.save("output.xlsx")?;
34//! # Ok::<(), ooxml_sml::Error>(())
35//! ```
36
37pub mod error;
38pub mod workbook;
39pub mod writer;
40
41/// Generated types from the ECMA-376 SpreadsheetML schema.
42///
43/// These types map 1:1 to XML elements and attributes defined in ECMA-376 Part 1 ยง18.
44/// They are produced by `ooxml-codegen` from the RELAX NG schemas and committed to avoid
45/// requiring the schema files at build time. Use the extension traits in [`ext`] for
46/// ergonomic access rather than working with these types directly.
47///
48/// Re-exported as [`types`].
49pub mod generated;
50/// Type aliases for the generated ECMA-376 types. See [`generated`] for details.
51pub use generated as types;
52
53/// Generated [`FromXml`](ooxml_xml::FromXml) parsers for all generated types.
54///
55/// Re-exported as [`parsers`].
56pub mod generated_parsers;
57/// Parsers for the generated ECMA-376 types. See [`generated_parsers`] for details.
58pub use generated_parsers as parsers;
59
60/// Generated [`ToXml`](ooxml_xml::ToXml) serializers for all generated types.
61///
62/// Re-exported as [`serializers`].
63pub mod generated_serializers;
64/// Serializers for the generated ECMA-376 types. See [`generated_serializers`] for details.
65pub use generated_serializers as serializers;
66
67// Lazy/streaming API for memory-efficient parsing
68pub mod lazy;
69pub use lazy::{LazyCell, LazyRow, LazyWorksheet};
70
71// Extension traits for generated types (see ADR-003)
72pub mod ext;
73#[cfg(feature = "sml-pivot")]
74pub use ext::PivotTableExt;
75pub use ext::{
76    CellExt, CellResolveExt, CellValue, Chart, ChartType, Comment, ResolveContext, ResolvedSheet,
77    RowExt, SheetDataExt, WorksheetExt, parse_worksheet,
78};
79#[cfg(feature = "sml-styling")]
80pub use ext::{ConditionalFormattingExt, ConditionalRuleExt, WorksheetConditionalFormattingExt};
81
82pub use error::{Error, Result};
83// Writer-required types from workbook module
84pub use workbook::{
85    ConditionalRuleType, DataValidationErrorStyle, DataValidationOperator, DataValidationType,
86    DefinedNameExt, DefinedNameScope, StylesheetExt, Workbook, builtin_format_code,
87    excel_date_to_ymd, excel_datetime_to_ymdhms, format_excel_date, format_excel_datetime,
88};
89pub use writer::{
90    BorderLineStyle, BorderSideStyle, BorderStyle, CellStyle, CommentBuilder, ConditionalFormat,
91    ConditionalFormatRule, DataValidationBuilder, DefinedNameBuilder, FillPattern, FillStyle,
92    FontStyle, HorizontalAlignment, IgnoredErrorType, PageOrientation, PageSetupOptions,
93    SheetBuilder, UnderlineStyle, VerticalAlignment, WorkbookBuilder, WriteCellValue,
94};