diff --git a/assets/favicon.ico b/assets/favicon.ico index be340ff..6606859 100644 Binary files a/assets/favicon.ico and b/assets/favicon.ico differ diff --git a/xlsx/examples/hello_calc.rs b/xlsx/examples/hello_calc.rs new file mode 100644 index 0000000..9269e5c --- /dev/null +++ b/xlsx/examples/hello_calc.rs @@ -0,0 +1,28 @@ +use ironcalc::{ + base::{expressions::utils::number_to_column, model::Model}, + export::save_to_xlsx, +}; + +fn main() -> Result<(), Box> { + let mut model = Model::new_empty("hello-calc.xlsx", "en", "UTC")?; + // Adds a square of numbers in the first sheet + for row in 1..100 { + for column in 1..100 { + let value = row * column; + model.set_user_input(0, row, column, format!("{}", value)); + } + } + // Adds a new sheet + model.add_sheet("Calculation")?; + // column 100 is CV + let last_column = number_to_column(100).unwrap(); + let formula = format!("=SUM(Sheet1!A1:{}100)", last_column); + model.set_user_input(1, 1, 1, formula); + + // evaluates + model.evaluate(); + + // saves to disk + save_to_xlsx(&model, "hello-calc.xlsx")?; + Ok(()) +} diff --git a/xlsx/examples/hello_styles.rs b/xlsx/examples/hello_styles.rs new file mode 100644 index 0000000..9157437 --- /dev/null +++ b/xlsx/examples/hello_styles.rs @@ -0,0 +1,22 @@ +use ironcalc::{base::model::Model, export::save_to_xlsx}; + +fn main() -> Result<(), Box> { + let mut model = Model::new_empty("hello_styles", "en", "UTC")?; + + // We are going to change styles in cell A1 + let sheet = 0; + let row = 1; + let column = 1; + let mut style = model.get_style_for_cell(sheet, row, column); + style.fill.fg_color = Some("#FFEE11".to_string()); + style.font.b = true; + style.font.color = Some("#EEFF22".to_string()); + model.set_cell_style(sheet, row, column, &style)?; + + // evaluates (unnecessary in this case) + model.evaluate(); + + // saves to disk + save_to_xlsx(&model, "hello-styles.xlsx")?; + Ok(()) +} diff --git a/xlsx/examples/widths_and_heights.rs b/xlsx/examples/widths_and_heights.rs new file mode 100644 index 0000000..24eabb6 --- /dev/null +++ b/xlsx/examples/widths_and_heights.rs @@ -0,0 +1,23 @@ +use ironcalc::{base::model::Model, export::save_to_xlsx}; + +fn main() -> Result<(), Box> { + let mut model = Model::new_empty("widths-and-heights", "en", "UTC")?; + // Cell C5 + let column = 3; + let row = 5; + // Make the first column 4 times as width + let worksheet = model.workbook.worksheet_mut(0)?; + let column_width = worksheet.column_width(column)? * 4.0; + worksheet.set_column_width(column, column_width)?; + + // and the first row twice as high. + let row_height = worksheet.row_height(row)? * 2.0; + worksheet.set_row_height(row, row_height)?; + + // evaluates + model.evaluate(); + + // saves to disk + save_to_xlsx(&model, "widths-and-heights.xlsx")?; + Ok(()) +} diff --git a/xlsx/src/lib.rs b/xlsx/src/lib.rs index f45cc9a..13b4db5 100644 --- a/xlsx/src/lib.rs +++ b/xlsx/src/lib.rs @@ -3,7 +3,7 @@ //! This technical API documentation in aimed at developers who want to develop bindings for a different language, //! build a UI based on the engine or just use the library in a Rust program //! -//! ## Usage +//! ## Basic usage //! //! Add the dependency in `Cargo.toml`: //! @@ -14,45 +14,27 @@ //! //! until version 0.5.0 you should use the git dependencies as stated //! -//! A simple example: +//! A simple example with some numbers, a new sheet and a formula: //! //! //! ```rust -//! use ironcalc::{ -//! base::{expressions::utils::number_to_column, model::Model}, -//! export::save_to_xlsx, -//! }; -//! -//! fn main() -> Result<(), Box> { -//! let mut model = Model::new_empty("hello-calc.xlsx", "en", "UTC")?; -//! // Adds a square of numbers in the first sheet -//! for row in 1..100 { -//! for column in 1..100 { -//! let value = row * column; -//! model.set_user_input(0, row, column, format!("{}", value)); -//! } -//! } -//! // Adds a new sheet -//! model.add_sheet("Calculation")?; -//! // column 100 is CV -//! let last_column = number_to_column(100).unwrap(); -//! let formula = format!("=SUM(Sheet1!A1:{}100)", last_column); -//! model.set_user_input(1, 1, 1, formula); -//! -//! // evaluates -//! model.evaluate(); -//! -//! // saves to disk -//! save_to_xlsx(&model, "hello-calc.xlsx")?; -//! Ok(()) -//! } +#![doc = include_str!("../examples/hello_calc.rs")] //! ``` //! -//! You can then just: +//! ## Styling the workbook //! -//! ```bash -//! cargo run +//! Adding colors, to cells, full columns or full rows is easy +//! +//! ```rust +#![doc = include_str!("../examples/hello_styles.rs")] //! ``` +//! +//! Changing column width and row heigh +//! +//! ```rust +#![doc = include_str!("../examples/widths_and_heights.rs")] +//! ``` +//! #![doc( html_logo_url = "https://raw.githubusercontent.com/ironcalc/ironcalc/main/assets/logo.png",