Working with Formulas

In general any Excel formula can be used directly in rust_xlsxwriter:

// SPDX-License-Identifier: MIT OR Apache-2.0
//
// Copyright 2022-2024, John McNamara, jmcnamara@cpan.org

//! The following example demonstrates writing a simple formula.

use rust_xlsxwriter::{Workbook, XlsxError};

fn main() -> Result<(), XlsxError> {
    let mut workbook = Workbook::new();
    let worksheet = workbook.add_worksheet();

    worksheet.write_formula(0, 0, "=10*B1 + C1")?;

    worksheet.write_number(0, 1, 5)?;
    worksheet.write_number(0, 2, 1)?;

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

    Ok(())
}

The formula will then be displayed as expected in Excel:

Image of output from doc_working_with_formulas_intro.rs

However, there are a few potential issues and differences that the user of rust_xlsxwriter should be aware of. These are explained in the following sections.