Skip to content

Commit

Permalink
UPDATE: Exposes the model in UserModel
Browse files Browse the repository at this point in the history
Fixes #262
  • Loading branch information
nhatcher committed Jan 30, 2025
1 parent 7777f8e commit 264fcac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions base/src/user_model/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 15 additions & 1 deletion xlsx/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
}

0 comments on commit 264fcac

Please sign in to comment.