Merge pull request #2303 from MarekSpodBiedry/issue-2285

XLSX: write spilled text as cached strings, not shared strings (#2285)
This commit is contained in:
FredApps authored and GitHub committed 2026-11-18 16:23:35 +07:00
commit 21def4fa1a
2 files changed
+26

No files matched your search

+5
View File
@@ -854,6 +854,11 @@ fn write_cell(s: &mut String, input: CellWriteInput<'_>, sid: &dyn Fn(gridcraft_
Value::Number(n) => {
let _ = write!(s, "><v>{}</v></c>", num(*n));
}
// Text inside a spill or array range is a cached formula result: Excel writes it as `t="str"`
// and shows #VALUE! for a shared string there when it trusts the saved values.
Value::Text(t) if extra.is_some() => {
let _ = write!(s, " t=\"str\"><v>{}</v></c>", esc(&encode_xstring(t)));
}
Value::Text(t) => {
let i = out.sst.index(t);
let _ = write!(s, " t=\"s\"><v>{i}</v></c>");
+21
View File
@@ -623,3 +623,24 @@ fn long_flat_chains_are_scalar_formulas() {
assert_dynamic(&sheet, "B4", "B4");
assert_eq!(cell(&sheet, "B1").child("f").unwrap().text, refs);
}
#[test]
fn spilled_text_is_written_as_a_cached_string_not_a_shared_string() {
let mut wb = Workbook::new();
let sh = wb.sheet_mut(0).unwrap();
let mut anchor = Cell::formula(Formula::new("SORT({\"b\";\"a\";\"c\"})"));
anchor.value = Value::text("a");
sh.cells.set(at("K4"), anchor);
sh.spill_ranges.insert(at("K4"), range("K4:K6"));
sh.spill.insert(at("K5"), Value::text("b"));
sh.spill.insert(at("K6"), Value::text("c"));
let bytes = write_xlsx(&wb).unwrap();
let mut pkg = Package::open(&bytes).unwrap();
let sheet = pkg.read_xml("xl/worksheets/sheet1.xml").unwrap().unwrap();
for (address, text) in [("K4", "a"), ("K5", "b"), ("K6", "c")] {
let c = cell(&sheet, address);
assert_eq!(c.attr("t"), Some("str"), "{address}");
assert_eq!(c.child("v").unwrap().text, text, "{address}");
}
}