diff --git a/crates/xlsx/src/styles.rs b/crates/xlsx/src/styles.rs index 89575ea795..6e29148a15 100644 --- a/crates/xlsx/src/styles.rs +++ b/crates/xlsx/src/styles.rs @@ -593,7 +593,8 @@ impl Dxf { } } - /// ``. + /// ``, its children in the `CT_Dxf` sequence: `font`, `numFmt`, `fill`, `alignment`, + /// `border`, `protection`. pub fn to_el(&self) -> El { let mut e = El::new("dxf"); if let Some(f) = &self.font { @@ -611,12 +612,12 @@ impl Dxf { if let Some(a) = &self.alignment { e.push(a.to_el()); } - if let Some(p) = self.protection { - e.push(p.to_el()); - } if let Some(b) = &self.border { e.push(b.to_el()); } + if let Some(p) = self.protection { + e.push(p.to_el()); + } e } } @@ -798,6 +799,23 @@ mod tests { assert_eq!(styles("").palette(), DEFAULT_PALETTE); } + #[test] + fn dxf_children_are_written_in_schema_order() { + // Every child CT_Dxf allows (but extLst), in its sequence; the issue's case is border then protection. + let s = styles( + r#""#, + ); + let written = styles(std::str::from_utf8(&s.to_xml()).unwrap()); + assert_eq!(written.dxfs, s.dxfs); + let root = craft_xml::Options::local().parse(&s.to_xml()).unwrap_or_default(); + let dxf = root.child("dxfs").and_then(|d| d.child("dxf")).expect("dxf written"); + let names: Vec<&str> = dxf.elements().map(|c| c.name.as_str()).collect(); + assert_eq!(names, ["font", "numFmt", "fill", "alignment", "border", "protection"]); + // border and protection alone keep that order too. + let pair = Dxf { border: s.dxfs[0].border.clone(), protection: s.dxfs[0].protection, ..Dxf::default() }.to_el(); + assert_eq!(pair.elements().map(|c| c.name.as_str()).collect::>(), ["border", "protection"]); + } + #[test] fn long_font_names_are_cut() { let s = styles(&format!(r#""#, "é".repeat(300)));