Quickstart
Quickstart
This page walks through the core Aspose.Cells FOSS for Rust workflow: create a workbook, write typed cell values and a formula, save the file, and load it back.
Prerequisites
| Requirement | Detail |
|---|---|
| Crate installed | See Installation |
| Rust toolchain | Edition 2021 |
1. Create a Workbook and Write Values
A new Workbook starts with one worksheet named Sheet1. Mutable access
flows through get_worksheets_mut and get_cells_mut; each cell has typed
setters:
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("Hello")?;
cells.get("B1")?.put_value_i32(123)?;
cells.get("C1")?.put_value_bool(true)?;
cells.get("D1")?.put_value_decimal(12.5)?;
cells.get("F1")?.put_value_i32(10)?;
cells.get("G1")?
.put_formula_with_cached_value("=F1*2", CellValue::Number(20.0))?;
}
workbook.save("hello.xlsx")?;
let loaded = Workbook::load_xlsx("hello.xlsx")?;
let sheet = loaded.worksheet("Sheet1")?;
let cells = sheet.get_cells();
println!("A1 = {}", cells.get("A1")?.display_string_value());
Ok(())
}2. Understand the Key Calls
Workbook::new— creates an empty workbook with one sheet.put_value_string/put_value_i32/put_value_bool/put_value_decimal— typed cell setters.put_formula_with_cached_value— stores the formula and the value Excel shows before recalculation.Workbook::save— writes the XLSX package to disk.Workbook::load_xlsx— loads an existing XLSX file.display_string_value— the cell’s display text when reading values back.
3. Run It
cargo runThe program writes hello.xlsx and prints A1 = Hello after reloading it.