From ed04ac6dfc07ed6f236a37a38830ea36938d14f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Hatcher?= Date: Sun, 18 Feb 2024 20:37:39 +0100 Subject: [PATCH] FIX: Adds documentation --- assets/favicon.ico | Bin 3966 -> 9854 bytes xlsx/examples/hello_calc.rs | 28 ++++++++++++++++ xlsx/examples/hello_styles.rs | 22 +++++++++++++ xlsx/examples/widths_and_heights.rs | 23 +++++++++++++ xlsx/src/lib.rs | 48 +++++++++------------------- 5 files changed, 88 insertions(+), 33 deletions(-) create mode 100644 xlsx/examples/hello_calc.rs create mode 100644 xlsx/examples/hello_styles.rs create mode 100644 xlsx/examples/widths_and_heights.rs diff --git a/assets/favicon.ico b/assets/favicon.ico index be340ff7ae781ed05ec30d7d180421f486de88c4..66068597ccd3446a522e3ce205baf87e1f65fdca 100644 GIT binary patch literal 9854 zcmc&)S&S7$6n!Hqi9h`Lt6#NRQF{-G4J|XHZ-s6rk*8=N;z0z^CAyI=Kk7L{jR_b4=t<={g&8w#QoI?%aGgTvn+4oEL@jaCLKeU)021E%;nfN1O&7(=Brh zqT61nuKVb6T%WFUe@o-WSp(KV>xj~j6r1hDxbb06<3m5~+uz&BnitAZ+-M`h&wVyw>uowEt#cj;pZo0a zpv-582=2NJ4X{z4*H$epAB+;535cJR$d9P~X(OUdm+7lDkc;L;8@ZD=kT&hlHN=_5 zF)CpcC)Yp8r?=^(w7&On*?e}GwQxD2uK7o4)0%KMcB=gjUQt}4Y;nHS=JtVx7GDE7 z>Uq_?T;6eQo?o>zuYOfMarO2BdArEIM6~1FD*mzgrZu>n z-8wapFFBwN9%0@4hVY*E@VTOv(64--G%uMTxHma&)I73nu*m&D4VpXo0ljkgEdiMr8pF8fefrY4Uk<{ezgn{(~m z)uG1n`;am4t<-zrL~0!_XMIP0yFV|JK53MRYl=Zeed^)^^3tOHL7uj7uY6zoqIl<% z$34)1`@`fj*^#nj&OCW*{x;b&d%V@hb)zp4_Yc1JxC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_ zH`Ro3 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",