Introduction

Spreadsheet management is the core of the aspose-cells-foss-rust crate: the objects that model a workbook, its sheets, and their cells, and the operations that turn Rust data into presentable XLSX files. This post walks through that surface — from creating sheets and writing typed values to styling, page layout, and the structural features that make workbooks usable: comments, hyperlinks, tables, and defined names.

Everything shown here is part of the open-source, MIT-licensed crate. No Microsoft Office installation is involved at any point; the library reads and writes the XLSX package format directly.


Key Features

Worksheets and Cell Collections

Worksheets are managed through the workbook’s worksheet collections. Sheets are addressed by index or name, renamed with set_name, and their cells are reached through get_cells (read) or get_cells_mut (write):

let mut workbook = Workbook::new();
{
    let mut worksheets = workbook.get_worksheets_mut();
    let sheet = worksheets.get(0)?;
    sheet.set_name("Charts")?;
    {
        let mut cells = sheet.get_cells_mut();
        cells.get("A1")?.put_value_string("Month")?;
        cells.get("B1")?.put_value_string("Sales")?;
    }
}

Typed Values by Name or Index

Cells accept strings, integers, booleans, decimals, and date-times through typed setters. Cells can be addressed A1-style (get("B3")) or numerically (get_by_index(row, column)), which suits generated layouts:

for month in 1..=12_u32 {
    cells
        .get_by_index(month, 0)
        .put_value_string(format!("Month {month}"))?;
    cells
        .get_by_index(month, 1)
        .put_value_i32((month as i32 * 1000) + (month as i32 * 50))?;
}

Formulas with Cached Values

put_formula_with_cached_value stores the formula text together with the value Excel should display before its first recalculation — important when the file is consumed by other tools that read cached results:

cells.get("F1")?.put_value_i32(10)?;
cells.get("G1")?
    .put_formula_with_cached_value("=F1*2", CellValue::Number(20.0))?;

Styling and Page Layout

CellStyle carries Font, Fill, and Borders; StyleFlag selects which style aspects an update applies. NumberFormat controls value rendering, and PageSetup manages PaperSizeType and PageOrientationType for printing. FreezePane and row/column VisibilityType keep large sheets navigable.

Reviewer workflows and navigation are covered by Comment and CommentCollection, Hyperlink with HyperlinkCollection, and DefinedName with DefinedNameCollection for named ranges.

Structured Tables and Filters

ListObject turns a range into a structured table with TableStyleType styling and TotalsCalculation rows; AutoFilter adds filtering with FilterColumn and FilterOperatorType conditions.


Quick Start

Add the crate to your Cargo.toml as a git dependency (the crate is not yet published on crates.io):

# Cargo.toml
[dependencies]
aspose-cells-foss-rust = { git = "https://github.com/aspose-cells-foss/Aspose.Cells-FOSS-for-Rust" }

A minimal spreadsheet-management session — create, write, save, reload:

use aspose_cells_foss_rust::{CellValue, Workbook};
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    let mut workbook = Workbook::new();
    {
        let mut worksheets = workbook.get_worksheets_mut();
        let sheet = worksheets.get(0)?;
        let mut cells = sheet.get_cells_mut();

        cells.get("A1")?.put_value_string("Item")?;
        cells.get("B1")?.put_value_string("Quantity")?;
        cells.get("A2")?.put_value_string("Apples")?;
        cells.get("B2")?.put_value_i32(12)?;
    }
    workbook.save("inventory.xlsx")?;

    let loaded = Workbook::load_xlsx("inventory.xlsx")?;
    let sheet = loaded.worksheet("Sheet1")?;
    let cells = sheet.get_cells();
    println!("A2 = {}", cells.get("A2")?.display_string_value());

    Ok(())
}

Supported Formats

FormatExtensionReadWrite
XLSX.xlsx

Loading accepts LoadOptions repair flags (try_repair_package, try_repair_xml) with structured LoadDiagnostics; saving goes through save, save_xlsx, or save_with_format with the SaveFormat enum.


Open Source & Licensing

Aspose.Cells FOSS for Rust is MIT licensed. Source code lives on GitHub; commercial use, modification, and redistribution are permitted.


Getting Started