Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPDATE: Exposes the model in UserModel #263

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}