UPDATE: Implement the implicit Intersection Operator
The II operator takes a range and returns a single cell that is in the same column or the same row as the present cell. This is needed for backwards compatibility with old Excel models and as a first step towards dynamic arrays. In the past Excel would evaluate `=A1:A10` in cell `C3` as `A3`, but today in results in an array containing all values in the range. To be compatible with old workbooks Excel inserts the II operator on those cases. So this PR performs an static analysis on all formulas inserting on import automatically the II operator where necessary. This we call the _automatic implicit operator_. When exporting to Excel the operator is striped away. You can also manually use the II. For instance `=SUM(@A1:A10)` in cell `C3`. This was not possible before and such a formula would break backwards compatibility with Excel. To Excel that "non automatic" form of the II is exported as `_xlfn.SINGLE()`. Th static analysis has to be done for all arithmetic operations and all functions. This is a bit of a daunting task and it is not done fully in this PR. We also need to implement arrays and dynamic arrays. My believe is that once the core operations have been implemented we can go formula by formula writing proper tests and documentation. After this PR formulas like `=A1:A10` for instance will return `#N/IMPL!` instead of performing the implicit intersection
This commit is contained in:
committed by
Nicolás Hatcher Andrés
parent
90763048bc
commit
da017b6113
@@ -48,8 +48,8 @@ fn test_example() {
|
||||
assert_eq!(ws[0].views[&0].range, [13, 5, 20, 14]);
|
||||
|
||||
let model2 = load_from_icalc("tests/example.ic").unwrap();
|
||||
let s = bitcode::encode(&model2.workbook);
|
||||
assert_eq!(workbook, model2.workbook, "{:?}", s);
|
||||
let _ = bitcode::encode(&model2.workbook);
|
||||
assert_eq!(workbook, model2.workbook);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -346,21 +346,31 @@ fn test_xlsx() {
|
||||
let path = format!("{}", Uuid::new_v4());
|
||||
let dir = temp_folder.join(path);
|
||||
fs::create_dir(&dir).unwrap();
|
||||
let mut is_error = false;
|
||||
for file_path in entries {
|
||||
let file_name_str = file_path.file_name().unwrap().to_str().unwrap();
|
||||
let file_path_str = file_path.to_str().unwrap();
|
||||
println!("Testing file: {}", file_path_str);
|
||||
if file_name_str.ends_with(".xlsx") && !file_name_str.starts_with('~') {
|
||||
if let Err(message) = test_file(file_path_str) {
|
||||
println!("Error with file: '{file_path_str}'");
|
||||
println!("{}", message);
|
||||
panic!("Model was evaluated inconsistently with XLSX data.")
|
||||
is_error = true;
|
||||
}
|
||||
let t = test_load_and_saving(file_path_str, &dir);
|
||||
if t.is_err() {
|
||||
println!("Error while load and saving file: {file_path_str}");
|
||||
is_error = true;
|
||||
}
|
||||
assert!(test_load_and_saving(file_path_str, &dir).is_ok());
|
||||
} else {
|
||||
println!("skipping");
|
||||
}
|
||||
}
|
||||
fs::remove_dir_all(&dir).unwrap();
|
||||
assert!(
|
||||
!is_error,
|
||||
"Models were evaluated inconsistently with XLSX data."
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -375,20 +385,26 @@ fn no_export() {
|
||||
let path = format!("{}", Uuid::new_v4());
|
||||
let dir = temp_folder.join(path);
|
||||
fs::create_dir(&dir).unwrap();
|
||||
let mut is_error = false;
|
||||
for file_path in entries {
|
||||
let file_name_str = file_path.file_name().unwrap().to_str().unwrap();
|
||||
let file_path_str = file_path.to_str().unwrap();
|
||||
println!("Testing file: {}", file_path_str);
|
||||
if file_name_str.ends_with(".xlsx") && !file_name_str.starts_with('~') {
|
||||
if let Err(message) = test_file(file_path_str) {
|
||||
println!("Error with file: '{file_path_str}'");
|
||||
println!("{}", message);
|
||||
panic!("Model was evaluated inconsistently with XLSX data.")
|
||||
is_error = true;
|
||||
}
|
||||
} else {
|
||||
println!("skipping");
|
||||
}
|
||||
}
|
||||
fs::remove_dir_all(&dir).unwrap();
|
||||
assert!(
|
||||
!is_error,
|
||||
"Models were evaluated inconsistently with XLSX data."
|
||||
);
|
||||
}
|
||||
|
||||
// This test verifies whether exporting the merged cells functionality is happening properly or not.
|
||||
@@ -476,6 +492,7 @@ fn test_documentation_xlsx() {
|
||||
let path = format!("{}", Uuid::new_v4());
|
||||
let dir = temp_folder.join(path);
|
||||
fs::create_dir(&dir).unwrap();
|
||||
let mut is_error = false;
|
||||
for file_path in entries {
|
||||
let file_name_str = file_path.file_name().unwrap().to_str().unwrap();
|
||||
let file_path_str = file_path.to_str().unwrap();
|
||||
@@ -487,7 +504,7 @@ fn test_documentation_xlsx() {
|
||||
if file_name_str.ends_with(".xlsx") && !file_name_str.starts_with('~') {
|
||||
if let Err(message) = test_file(file_path_str) {
|
||||
println!("{}", message);
|
||||
panic!("Model was evaluated inconsistently with XLSX data.")
|
||||
is_error = true;
|
||||
}
|
||||
assert!(test_load_and_saving(file_path_str, &dir).is_ok());
|
||||
} else {
|
||||
@@ -495,6 +512,10 @@ fn test_documentation_xlsx() {
|
||||
}
|
||||
}
|
||||
fs::remove_dir_all(&dir).unwrap();
|
||||
assert!(
|
||||
!is_error,
|
||||
"Models were evaluated inconsistently with XLSX data."
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user