mirror of
https://github.com/storytold/gridcraft.git
synced 2026-10-27 20:26:48 -06:00
Integration: #1225 write a dxf's border before its protection
Schema order is font, numFmt, fill, alignment, border, protection.
This commit is contained in:
@@ -716,12 +716,12 @@ pub fn write_styles(wb: &Workbook, dxfs: &[Style], extra_fmts: &[String]) -> (St
|
||||
if let Some(a) = alignment_xml(&d.align) {
|
||||
dx.push_str(&a);
|
||||
}
|
||||
if st.protection || d.protection != def.protection {
|
||||
let _ = write!(dx, "<protection locked=\"{}\" hidden=\"{}\"/>", d.protection.locked as u8, d.protection.hidden as u8);
|
||||
}
|
||||
if d.borders != def.borders {
|
||||
dx.push_str(&border_xml(&d.borders));
|
||||
}
|
||||
if st.protection || d.protection != def.protection {
|
||||
let _ = write!(dx, "<protection locked=\"{}\" hidden=\"{}\"/>", d.protection.locked as u8, d.protection.hidden as u8);
|
||||
}
|
||||
dx.push_str("</dxf>");
|
||||
}
|
||||
for f in extra_fmts {
|
||||
|
||||
@@ -224,6 +224,32 @@ fn dxf_font_and_parts_stated_at_their_defaults_survive_save() {
|
||||
assert_eq!(written, Some(format!(r#" count="4">{dxfs}"#).as_str()));
|
||||
}
|
||||
|
||||
/// A dxf writes its parts in schema order: the border comes before the protection.
|
||||
#[test]
|
||||
fn dxf_border_is_written_before_protection() {
|
||||
let dxfs = r#"<dxf><border><left style="thin"><color rgb="FF000000"/></left></border><protection locked="0" hidden="1"/></dxf>"#;
|
||||
let styles = format!(
|
||||
r#"<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
||||
<fonts count="1"><font><sz val="11"/><name val="Calibri"/></font></fonts>
|
||||
<fills count="2"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill></fills>
|
||||
<borders count="1"><border/></borders>
|
||||
<cellXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"/></cellXfs>
|
||||
<dxfs count="1">{dxfs}</dxfs>
|
||||
</styleSheet>"#
|
||||
);
|
||||
let rels = r#"<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>"#;
|
||||
let body = r#"<sheetData><row r="1"><c r="A1"><v>1</v></c></row></sheetData>
|
||||
<conditionalFormatting sqref="A1"><cfRule type="cellIs" dxfId="0" priority="1" operator="greaterThan"><formula>0</formula></cfRule></conditionalFormatting>"#;
|
||||
let bytes = minimal(body, &[("xl/styles.xml", &styles)], rels, "");
|
||||
let (wb, _) = read_xlsx(&bytes).unwrap();
|
||||
let out = crate::write_xlsx(&wb).unwrap();
|
||||
let st = crate::package::Package::open(&out).unwrap().read("xl/styles.xml").unwrap().unwrap();
|
||||
let st = String::from_utf8(st).unwrap();
|
||||
let dx = st.split_once("<dxfs").and_then(|(_, r)| r.split_once("</dxfs>")).map(|(d, _)| d).unwrap_or_default();
|
||||
let (b, p) = (dx.find("<border"), dx.find("<protection"));
|
||||
assert!(b.is_some() && p.is_some() && b < p, "{dx}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strict_namespace_and_shared_strings() {
|
||||
let ct = super::CT;
|
||||
|
||||
Reference in New Issue
Block a user