From 59a8b14d4dac6f005acfe722d5c4632986b9342d Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Fri, 30 Oct 2026 22:26:49 +0000 Subject: [PATCH] Print structured refs to columns starting with @ in double brackets Found while testing crates/formula/src/printer.rs:164 (write_struct_ref, single column without specifiers) Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/formula/src/printer.rs | 4 ++-- crates/formula/src/tests.rs | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/formula/src/printer.rs b/crates/formula/src/printer.rs index 3b5989372..bddbfebf2 100644 --- a/crates/formula/src/printer.rs +++ b/crates/formula/src/printer.rs @@ -175,8 +175,8 @@ fn write_struct_ref(s: &StructRef, at_shorthand: bool) -> String { let _ = write!(out, "[{}]", s.specifiers.first().map(item).unwrap_or("")); } (Some(c), None) if s.specifiers.is_empty() => { - // Excel writes a name with spaces at its edges in the double-bracket form. - if c.trim() == c { + // Names with spaces at their edges, or starting with `@` (this-row shorthand), use the double-bracket form. + if c.trim() == c && !c.starts_with('@') { let _ = write!(out, "[{}]", esc(c)); } else { let _ = write!(out, "[[{}]]", esc(c)); diff --git a/crates/formula/src/tests.rs b/crates/formula/src/tests.rs index 0fdc9ca38..8b8215455 100644 --- a/crates/formula/src/tests.rs +++ b/crates/formula/src/tests.rs @@ -558,3 +558,12 @@ fn reference_shapes_print_unchanged() -> Result<(), Box> } Ok(()) } + +#[test] +fn column_starting_with_at_round_trips() { + for name in ["@a", "a@b"] { + let s = StructRef { table: "T".into(), specifiers: vec![], col_start: Some(name.into()), col_end: None }; + let text = format!("={}", printer::struct_ref(&s)); + assert_eq!(parse(&text).ok(), Some(Expr::Struct(s)), "printed as {text}"); + } +}