mirror of
https://github.com/storytold/gridcraft.git
synced 2026-12-02 10:37:05 -06:00
Extract file sharing XML writer
This commit is contained in:
+24
-21
@@ -214,6 +214,29 @@ fn check_write_xlsx(wb: &Workbook) -> Result<(), IoError> {
|
||||
check_sheet_names(wb)
|
||||
}
|
||||
|
||||
fn append_file_sharing(w: &mut String, wb: &Workbook) {
|
||||
let Some(r) = &wb.write_reservation else { return };
|
||||
w.push_str("<fileSharing");
|
||||
if r.read_only_recommended {
|
||||
w.push_str(" readOnlyRecommended=\"1\"");
|
||||
}
|
||||
// Office needs a userName beside a legacy reservationPassword, so a nameless one gets a placeholder
|
||||
// rather than losing the password.
|
||||
let legacy = matches!(r.password, Some(gridcraft_model::PasswordHash::Legacy(_)));
|
||||
let name = if r.user_name.is_empty() && legacy { "GridCraft" } else { r.user_name.as_str() };
|
||||
if !name.is_empty() {
|
||||
let _ = write!(w, " userName=\"{}\"", esc_attr(name));
|
||||
}
|
||||
match &r.password {
|
||||
Some(gridcraft_model::PasswordHash::Legacy(h)) => {
|
||||
let _ = write!(w, " reservationPassword=\"{h:04X}\"");
|
||||
}
|
||||
Some(h) => w.push_str(&crate::sheet_write::password_attrs(h, "")),
|
||||
None => {}
|
||||
}
|
||||
w.push_str("/>");
|
||||
}
|
||||
|
||||
pub fn write_xlsx(wb: &Workbook, kind: XlsxKind) -> Result<Vec<u8>, IoError> {
|
||||
write_xlsx_named(wb, kind, None)
|
||||
}
|
||||
@@ -263,27 +286,7 @@ pub fn write_xlsx_named(wb: &Workbook, kind: XlsxKind, book_name: Option<&str>)
|
||||
// only when appName is "xl" (#799). One without names GridCraft (#1699), and Excel recalculates it.
|
||||
let file_version = crate::passthrough::workbook_elements(wb, "fileVersion");
|
||||
w.push_str(if file_version.is_empty() { "<fileVersion appName=\"gridcraft\"/>" } else { &file_version });
|
||||
if let Some(r) = &wb.write_reservation {
|
||||
w.push_str("<fileSharing");
|
||||
if r.read_only_recommended {
|
||||
w.push_str(" readOnlyRecommended=\"1\"");
|
||||
}
|
||||
// Office needs a userName beside a legacy reservationPassword, so a nameless one gets a placeholder
|
||||
// rather than losing the password.
|
||||
let legacy = matches!(r.password, Some(gridcraft_model::PasswordHash::Legacy(_)));
|
||||
let name = if r.user_name.is_empty() && legacy { "GridCraft" } else { r.user_name.as_str() };
|
||||
if !name.is_empty() {
|
||||
let _ = write!(w, " userName=\"{}\"", esc_attr(name));
|
||||
}
|
||||
match &r.password {
|
||||
Some(gridcraft_model::PasswordHash::Legacy(h)) => {
|
||||
let _ = write!(w, " reservationPassword=\"{h:04X}\"");
|
||||
}
|
||||
Some(h) => w.push_str(&crate::sheet_write::password_attrs(h, "")),
|
||||
None => {}
|
||||
}
|
||||
w.push_str("/>");
|
||||
}
|
||||
append_file_sharing(&mut w, wb);
|
||||
w.push_str("<workbookPr");
|
||||
match wb.show_objects {
|
||||
ShowObjects::All => {}
|
||||
|
||||
Reference in New Issue
Block a user