FIX: Export fronzen rows/columns properly
This commit is contained in:
committed by
Nicolás Hatcher Andrés
parent
42c651da29
commit
cc140b087d
1
webapp/app.ironcalc.com/server/Cargo.lock
generated
1
webapp/app.ironcalc.com/server/Cargo.lock
generated
@@ -947,7 +947,6 @@ dependencies = [
|
|||||||
"chrono-tz",
|
"chrono-tz",
|
||||||
"csv",
|
"csv",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"once_cell",
|
|
||||||
"rand",
|
"rand",
|
||||||
"regex",
|
"regex",
|
||||||
"ryu",
|
"ryu",
|
||||||
|
|||||||
@@ -88,6 +88,44 @@ fn test_values() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn frozen_rows() {
|
||||||
|
let mut model = new_empty_model();
|
||||||
|
model.set_frozen_rows(0, 23).unwrap();
|
||||||
|
model.evaluate();
|
||||||
|
let temp_file_name = "temp_file_test_frozen_rows.xlsx";
|
||||||
|
save_to_xlsx(&model, temp_file_name).unwrap();
|
||||||
|
let model = load_from_xlsx(temp_file_name, "en", "UTC").unwrap();
|
||||||
|
assert_eq!(model.get_frozen_rows_count(0).unwrap(), 23);
|
||||||
|
fs::remove_file(temp_file_name).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn frozen_columns() {
|
||||||
|
let mut model = new_empty_model();
|
||||||
|
model.set_frozen_columns(0, 42).unwrap();
|
||||||
|
model.evaluate();
|
||||||
|
let temp_file_name = "temp_file_test_frozen_columns.xlsx";
|
||||||
|
save_to_xlsx(&model, temp_file_name).unwrap();
|
||||||
|
let model = load_from_xlsx(temp_file_name, "en", "UTC").unwrap();
|
||||||
|
assert_eq!(model.get_frozen_columns_count(0).unwrap(), 42);
|
||||||
|
fs::remove_file(temp_file_name).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn frozen_rows_and_columns() {
|
||||||
|
let mut model = new_empty_model();
|
||||||
|
model.set_frozen_rows(0, 23).unwrap();
|
||||||
|
model.set_frozen_columns(0, 42).unwrap();
|
||||||
|
model.evaluate();
|
||||||
|
let temp_file_name = "temp_file_test_frozen_rows_and_columns.xlsx";
|
||||||
|
save_to_xlsx(&model, temp_file_name).unwrap();
|
||||||
|
let model = load_from_xlsx(temp_file_name, "en", "UTC").unwrap();
|
||||||
|
assert_eq!(model.get_frozen_rows_count(0).unwrap(), 23);
|
||||||
|
assert_eq!(model.get_frozen_columns_count(0).unwrap(), 42);
|
||||||
|
fs::remove_file(temp_file_name).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_formulas() {
|
fn test_formulas() {
|
||||||
let mut model = new_empty_model();
|
let mut model = new_empty_model();
|
||||||
|
|||||||
@@ -301,15 +301,53 @@ pub(crate) fn get_worksheet_xml(
|
|||||||
"".to_string()
|
"".to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let frozen_rows = worksheet.frozen_rows;
|
||||||
|
let frozen_columns = worksheet.frozen_columns;
|
||||||
|
|
||||||
|
let pane = if frozen_rows > 0 && frozen_columns > 0 {
|
||||||
|
// There are both frozen rows and columns. There are four panes.
|
||||||
|
// The first column is the first column after the last frozen column.
|
||||||
|
let first_column = number_to_column(frozen_columns + 1).unwrap_or("A".to_string());
|
||||||
|
// This is the top left cell of the bottom right pane.
|
||||||
|
let top_left_cell = format!("{}{}", first_column, frozen_rows + 1);
|
||||||
|
// The meaning of the next two is irrelevant for IronCalc.
|
||||||
|
let top_right_active_cell = format!("{first_column}1");
|
||||||
|
let bottom_left_active_cell = format!("A{}", frozen_rows + 1);
|
||||||
|
// The bottom right active cell is the "true" selected cell and it does not need to reside on this pane.
|
||||||
|
format!(
|
||||||
|
"<pane xSplit=\"{frozen_columns}\" ySplit=\"{frozen_rows}\" topLeftCell=\"{top_left_cell}\" activePane=\"bottomRight\" state=\"frozen\"/>\
|
||||||
|
<selection pane=\"topRight\" activeCell=\"{top_right_active_cell}\" sqref=\"{top_right_active_cell}\"/>\
|
||||||
|
<selection pane=\"bottomLeft\" activeCell=\"{bottom_left_active_cell}\" sqref=\"{bottom_left_active_cell}\"/>\
|
||||||
|
<selection pane=\"bottomRight\" activeCell=\"{active_cell}\" sqref=\"{sqref}\"/>",
|
||||||
|
)
|
||||||
|
} else if frozen_rows > 0 {
|
||||||
|
// Only frozen rows
|
||||||
|
let top_left_cell = format!("A{}", frozen_rows + 1);
|
||||||
|
format!(
|
||||||
|
"<pane ySplit=\"{frozen_rows}\" topLeftCell=\"{top_left_cell}\" activePane=\"bottomLeft\" state=\"frozen\"/>\
|
||||||
|
<selection pane=\"bottomLeft\" activeCell=\"{active_cell}\" sqref=\"{sqref}\"/>",
|
||||||
|
)
|
||||||
|
} else if frozen_columns > 0 {
|
||||||
|
let top_left_cell = format!(
|
||||||
|
"{}1",
|
||||||
|
number_to_column(frozen_columns + 1).unwrap_or("A".to_string())
|
||||||
|
);
|
||||||
|
format!(
|
||||||
|
"<pane xSplit=\"{frozen_columns}\" topLeftCell=\"{top_left_cell}\" activePane=\"topRight\" state=\"frozen\"/>\
|
||||||
|
<selection pane=\"topRight\" activeCell=\"{active_cell}\" sqref=\"{sqref}\"/>"
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
// No frozen rows or columns
|
||||||
|
format!(r#"<selection activeCell="{active_cell}" sqref="{sqref}"/>"#)
|
||||||
|
};
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
"{XML_DECLARATION}
|
"{XML_DECLARATION}\
|
||||||
<worksheet \
|
<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">\
|
||||||
xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" \
|
|
||||||
xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">\
|
|
||||||
<dimension ref=\"{dimension}\"/>\
|
<dimension ref=\"{dimension}\"/>\
|
||||||
<sheetViews>\
|
<sheetViews>\
|
||||||
<sheetView workbookViewId=\"0\"{show_grid_lines}{tab_selected}>\
|
<sheetView workbookViewId=\"0\"{show_grid_lines}{tab_selected}>\
|
||||||
<selection activeCell=\"{active_cell}\" sqref=\"{sqref}\"/>\
|
{pane}\
|
||||||
</sheetView>\
|
</sheetView>\
|
||||||
</sheetViews>\
|
</sheetViews>\
|
||||||
{cols}\
|
{cols}\
|
||||||
|
|||||||
Reference in New Issue
Block a user