Skip to main content

Crate ferroxl

Crate ferroxl 

Source
Expand description

ferroxl — a Rust port of the openpyxl library for reading and writing Excel 2007 .xlsx/.xlsm files.

The crate mirrors the Python package’s module layout and semantics: cells (cell), styles (styles), worksheets (worksheet), the workbook (workbook), the reader (reader), the writer (writer) and the supporting utilities (units, date_time, xml).

§Reading

use ferroxl::{load_workbook, LoadOptions};

let workbook = load_workbook("report.xlsx", LoadOptions::default())?;

for name in workbook.get_sheet_names() {
    println!("{name}");
}

let sheet = workbook.active_sheet()?;
for row in sheet.range_values("A1:D10")? {
    for value in row {
        println!("{value:?}");
    }
}

// One cell at a time, when a coordinate is all you have.
println!("{:?}", sheet.cell_value("B2"));

§Writing

use ferroxl::{CellValue, Style, Workbook};

let mut workbook = Workbook::new();

// `Workbook::new()` already made `Sheet1`, and `create_sheet` appends without
// making the new sheet active, so take the index it returns.
let summary = workbook.create_sheet(Some("Summary"))?;

let sheet = &mut workbook.worksheets[summary];
sheet.set("A1", CellValue::text("Item"))?;
sheet.set("B1", CellValue::text("Revenue"))?;
sheet.set("A2", CellValue::text("Widget"))?;
sheet.set("B2", CellValue::Number(1200.0))?;
sheet.set("C2", CellValue::Formula("=B2*1.2".to_string()))?;

let mut header = Style::new();
header.font.bold = true;
header.fill.fill_type = Some("solid".to_string());
header.fill.start_color = ferroxl::Color::new("FFDDDDDD".to_string());
for cell in ["A1", "B1", "C1"] {
    sheet.set_style(cell, header.clone())?;
}
sheet.set_freeze_panes("A2");

workbook.save("summary.xlsx")?;

§Feature parity

Every public Python class and function has a Rust counterpart with the same behaviour. Where Python’s semantics are impossible or undesirable to reproduce exactly, the deviation is documented at the call site and the closest faithful behaviour is implemented instead — the places where this happens are the HashableObject equality rules, tri-state booleans, floating-point formatting and PIL-dependent image handling.

Re-exports§

pub use cell::absolute_coordinate;
pub use cell::column_index_from_string;
pub use cell::coordinate_from_string;
pub use cell::get_column_letter;
pub use cell::Cell;
pub use cell::CellValue;
pub use cell::DataType;
pub use comments::Comment;
pub use date_time::BaseDate;
pub use exceptions::Error;
pub use exceptions::Result;
pub use namedrange::DefinedName;
pub use namedrange::NamedRange;
pub use namedrange::NamedRangeContainingValue;
pub use reader::load_workbook;
pub use reader::load_workbook_from_bytes;
pub use reader::LoadOptions;
pub use styles::Alignment;
pub use styles::Border;
pub use styles::Borders;
pub use styles::Color;
pub use styles::Fill;
pub use styles::Font;
pub use styles::NumberFormat;
pub use styles::Protection;
pub use styles::Style;
pub use workbook::DocumentProperties;
pub use workbook::DocumentSecurity;
pub use workbook::Workbook;
pub use worksheet::AutoFilter;
pub use worksheet::HeaderFooter;
pub use worksheet::PageMargins;
pub use worksheet::PageSetup;
pub use worksheet::SheetProtection;
pub use worksheet::Worksheet;
pub use writer::save_dump;
pub use writer::save_workbook;
pub use writer::save_workbook_to;
pub use writer::DumpWorksheet;
pub use writer::ExcelWriter;

Modules§

cell
Cell handling: values, types, coordinates, formulas and read-only cells.
charts
Charts (openpyxl/charts/).
comments
Cell comments (openpyxl/comments/).
datavalidation
Data validation (openpyxl/datavalidation.py).
date_time
Excel date weirdness (openpyxl/date_time.py).
drawing
Drawing objects (openpyxl/drawing/drawing.py).
exceptions
Error types mirroring openpyxl.exceptions.
formatting
Conditional formatting (openpyxl/formatting/).
formula
Formula text handling.
namedrange
Named groups of cells (openpyxl/namedrange.py).
reader
Reading xlsx files (openpyxl/reader/).
styles
Style objects (openpyxl/styles/).
units
Unit conversion helpers (openpyxl/units.py).
workbook
The workbook (openpyxl/workbook/workbook.py).
worksheet
Worksheet parts: dimensions, filters, headers/footers, page setup and protection.
writer
Writing xlsx files (openpyxl/writer/).
xml
XML helpers: namespace constants, DOM building/parsing and streaming writers.

Constants§

MCP_SERVER
The MCP server crate name, for agents that discover tools by package.
UPSTREAM_PROJECT
The upstream Python project this crate ports.
VERSION
The ferroxl version, matching the openpyxl release it ports.