From 264fcac63cc93b08a4b4a6764815e0c0adf6a53c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Hatcher?= Date: Thu, 30 Jan 2025 07:42:16 +0100 Subject: [PATCH] UPDATE: Exposes the model in UserModel Fixes #262 --- base/src/user_model/common.rs | 5 +++++ xlsx/tests/test.rs | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/base/src/user_model/common.rs b/base/src/user_model/common.rs index 7c5fc76..385ef99 100644 --- a/base/src/user_model/common.rs +++ b/base/src/user_model/common.rs @@ -195,6 +195,11 @@ impl UserModel { self.model.to_bytes() } + /// Returns the internal model + pub fn get_model(&self) -> &Model { + &self.model + } + /// Returns the workbook name pub fn get_name(&self) -> String { self.model.workbook.name.clone() diff --git a/xlsx/tests/test.rs b/xlsx/tests/test.rs index df4bf4a..34cb487 100644 --- a/xlsx/tests/test.rs +++ b/xlsx/tests/test.rs @@ -9,7 +9,7 @@ use ironcalc::compare::{test_file, test_load_and_saving}; use ironcalc::export::save_to_xlsx; use ironcalc::import::{load_from_icalc, load_from_xlsx, load_from_xlsx_bytes}; use ironcalc_base::types::{HorizontalAlignment, VerticalAlignment}; -use ironcalc_base::Model; +use ironcalc_base::{Model, UserModel}; // This is a functional test. // We check that the output of example.xlsx is what we expect. @@ -496,3 +496,17 @@ fn test_documentation_xlsx() { } fs::remove_dir_all(&dir).unwrap(); } + +#[test] +fn test_user_model() { + let temp_file_name = "temp_file_test_user_model.xlsx"; + let mut model = UserModel::new_empty("my_model", "en", "UTC").unwrap(); + model.set_user_input(0, 1, 1, "=1+1").unwrap(); + + // test we can use `get_model` to save the model + save_to_xlsx(model.get_model(), temp_file_name).unwrap(); + fs::remove_file(temp_file_name).unwrap(); + + // we can still use the model afterwards + model.set_row_height(0, 1, 100.0).unwrap(); +}