From 17aae2da04d3cf94c113182711753afa5a7581f2 Mon Sep 17 00:00:00 2001 From: DerKarussellbremser <67138735+DerKarussellbremser@users.noreply.github.com> Date: Sat, 24 Oct 2026 11:41:23 +0200 Subject: [PATCH 1/9] Grid: italic and bold in a one-face font are slanted and thickened, as in Excel Arial Black has a single face. A cell in Arial Black, bold italic, drew it upright and at its own weight; Excel slants it and thickens it (observed in its PDF: oblique by 1/3, outlined 0.23 pt at 9 pt). fonts.rs notes, while it binds a family's roles, which italic roles got an upright face and which bold roles got the plain face; the grid then lays such text out with egui's italics and paints it a second time about 1/36 of its size to the right. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KKbbMZpkzQuncTpqAyhkp9 --- crates/ui-egui/src/fonts.rs | 70 ++++++++++++++++++++++++++++++++++++- crates/ui-egui/src/grid.rs | 37 +++++++++++++++----- docs/ui-parity.md | 3 +- 3 files changed, 100 insertions(+), 10 deletions(-) diff --git a/crates/ui-egui/src/fonts.rs b/crates/ui-egui/src/fonts.rs index 1a381b9d46..11125a9b04 100644 --- a/crates/ui-egui/src/fonts.rs +++ b/crates/ui-egui/src/fonts.rs @@ -325,6 +325,13 @@ pub fn bind_faces(fonts: &mut egui::FontDefinitions, family: &str, faces: &[Face let mut bound: Vec = Vec::new(); for (bold, italic) in [(false, false), (true, false), (false, true), (true, true)] { let Some(primary) = pick_face(faces, bold, italic) else { continue }; + let role = role_key(family, bold, italic); + if italic && !primary.italic { + mark_synthetic(&role, SLANT); + } + if bold && pick_face(faces, false, italic).is_some_and(|plain| face_key(plain) == face_key(primary)) { + mark_synthetic(&role, BOLD); + } let mut chain: Vec = Vec::new(); for face in [Some(primary), pick_face(faces, false, false)] { let Some(face) = face else { continue }; @@ -344,7 +351,6 @@ pub fn bind_faces(fonts: &mut egui::FontDefinitions, family: &str, faces: &[Face continue; } chain.extend(base.iter().cloned()); - let role = role_key(family, bold, italic); fonts.families.insert(egui::FontFamily::Name(role.clone().into()), chain); bound.push(role); } @@ -374,6 +380,35 @@ pub fn is_bound(role: &str) -> bool { bound().read().unwrap_or_else(|e| e.into_inner()).contains(role) } +/// Roles drawn with a face that lacks their slant or weight (Arial Black has one face only), as +/// `{role}|slant` and `{role}|bold`. Excel imitates the missing style (observed in its PDF: a cell in +/// Arial Black, bold italic, is slanted by 1/3 and outlined about 1/36 of its size thick). +static SYNTHETIC: OnceLock>> = OnceLock::new(); +const SLANT: &str = "slant"; +const BOLD: &str = "bold"; + +fn synthetic() -> &'static std::sync::RwLock> { + SYNTHETIC.get_or_init(|| std::sync::RwLock::new(HashSet::new())) +} + +fn mark_synthetic(role: &str, style: &str) { + synthetic().write().unwrap_or_else(|e| e.into_inner()).insert(format!("{role}|{style}")); +} + +fn is_synthetic(role: &str, style: &str) -> bool { + is_bound(role) && synthetic().read().unwrap_or_else(|e| e.into_inner()).contains(&format!("{role}|{style}")) +} + +/// Does italic text in this installed family have to be slanted when drawn (no italic face)? +pub fn is_slanted(family: &str, bold: bool) -> bool { + is_synthetic(&role_key(family, bold, true), SLANT) +} + +/// Does bold text in this installed family have to be thickened when drawn (no face of its own)? +pub fn is_emboldened(family: &str, italic: bool) -> bool { + is_synthetic(&role_key(family, true, italic), BOLD) +} + /// Serializes tests that mutate the process-wide bound-family registry. #[cfg(test)] pub(crate) static TEST_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(()); @@ -473,6 +508,39 @@ mod tests { let _ = std::fs::remove_dir_all(&dir); } + #[test] + fn styles_a_family_has_no_face_for_are_imitated() { + let _g = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner()); + let dir = std::env::temp_dir().join(format!("gridcraft-fonts-synthetic-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).expect("temp dir"); + // One font file stands in for every face; each face is its own (path, index) by its name. + let face = |family: &str, file: &str, weight: f32, italic: bool| { + let path = dir.join(file); + std::fs::write(&path, epaint_default_fonts::UBUNTU_LIGHT).expect("write"); + Face { family: family.into(), names: vec![family.into()], path, index: 0, weight, italic } + }; + let mut fonts = egui::FontDefinitions::default(); + // Like Arial Black: one face, whatever its weight. + let mut bound = bind_faces(&mut fonts, "One Face", &[face("One Face", "one.ttf", 900.0, false)]); + let full = [ + face("Full", "full.ttf", 400.0, false), + face("Full", "full-b.ttf", 700.0, false), + face("Full", "full-i.ttf", 400.0, true), + face("Full", "full-bi.ttf", 700.0, true), + ]; + bound.extend(bind_faces(&mut fonts, "Full", &full)); + set_bound(bound); + assert!(is_slanted("One Face", false) && is_slanted("One Face", true)); + assert!(is_emboldened("One Face", false) && is_emboldened("One Face", true)); + assert!(!is_slanted("Full", false) && !is_slanted("Full", true), "its own italic faces are drawn as they are"); + assert!(!is_emboldened("Full", false) && !is_emboldened("Full", true), "its own bold faces are drawn as they are"); + assert!(!is_slanted("Not Bound", false) && !is_emboldened("Not Bound", false)); + set_bound([]); + assert!(!is_slanted("One Face", false) && !is_emboldened("One Face", false), "nothing is imitated once unbound"); + let _ = std::fs::remove_dir_all(&dir); + } + /// A font that is just a table directory and a `name` table holding `records` as /// `(Windows language id, name id, text)`: all [`file_faces`] reads. #[cfg(not(target_arch = "wasm32"))] diff --git a/crates/ui-egui/src/grid.rs b/crates/ui-egui/src/grid.rs index b485104b1d..ce5545b8c6 100644 --- a/crates/ui-egui/src/grid.rs +++ b/crates/ui-egui/src/grid.rs @@ -1242,6 +1242,9 @@ pub(crate) fn paint_quadrant( let size = st.font.size * 96.0 / 72.0 * z; let fam = theme::cell_family(&st.font.name, st.font.bold, st.font.italic); let font = FontId::new(size, fam); + let slant = st.font.italic && crate::fonts::is_slanted(&st.font.name, st.font.bold); + let embolden = st.font.bold && crate::fonts::is_emboldened(&st.font.name, st.font.italic); + let bold_dx = if embolden { (size / 36.0).max(1.0 / p.ctx().pixels_per_point()) } else { 0.0 }; // Digits fit by the cell's own font and size, not the default 11pt (9pt marks in narrow columns). let char_w = p.layout_no_wrap("0".to_string(), font.clone(), Color32::PLACEHOLDER).size().x.max(1.0); let avail_w = rect.right() - text_left; @@ -1268,7 +1271,7 @@ pub(crate) fn paint_quadrant( // Rotated text wraps along its own direction (below), not across the column width. if !rotated && (st.align.wrap || st.align.h == HAlign::Justify) { let wrap_w = (rect.width() - 2.0 * pad - indent).max(4.0); - let mut job = egui::text::LayoutJob::simple(text.clone(), font.clone(), color, wrap_w); + let mut job = cell_job(text.clone(), font.clone(), color, wrap_w, slant); job.halign = match halign { HAlign::Center | HAlign::CenterAcross => egui::Align::Center, HAlign::Right => egui::Align::RIGHT, @@ -1281,7 +1284,7 @@ pub(crate) fn paint_quadrant( _ => text_left + pad + indent, }; let y = wrapped_cell_text_y(st.align.v, *rect, galley.size().y, z); - p.with_clip_rect(rect.intersect(p.clip_rect())).galley(pos2(x, y), galley, color); + paint_cell_galley(&p.with_clip_rect(rect.intersect(p.clip_rect())), pos2(x, y), galley, color, bold_dx); continue; } // Wrap Text off: Excel ignores the line breaks and draws the whole string on one line. @@ -1295,7 +1298,7 @@ pub(crate) fn paint_quadrant( .flatten(); let shrunk = small.is_some(); let font = small.unwrap_or(font); - let mut galley = p.layout_no_wrap(first_line.clone(), font.clone(), color); + let mut galley = p.layout_job(cell_job(first_line.clone(), font.clone(), color, f32::INFINITY, slant)); let mut w = galley.size().x; // Numbers and dates never overflow: they show #### when too narrow. let hashed = !shrunk && (numeric || matches!(v, Value::Number(_))) && w > avail_w - 2.0 * pad && st.align.h != HAlign::Fill; @@ -1303,7 +1306,7 @@ pub(crate) fn paint_quadrant( // Measured on `#` itself: it is wider than `0` in some fonts, and #### must fit its cell. let hash_w = p.layout_no_wrap("#".to_string(), font.clone(), color).size().x.max(1.0); let n = ((avail_w - 2.0 * pad) / hash_w).floor().max(1.0) as usize; - galley = p.layout_no_wrap("#".repeat(n), font.clone(), color); + galley = p.layout_job(cell_job("#".repeat(n), font.clone(), color, f32::INFINITY, slant)); w = galley.size().x; } // Repeat fill (`*` in number formats) / Fill alignment. A number already shown as #### keeps @@ -1319,7 +1322,7 @@ pub(crate) fn paint_quadrant( if first_line.is_char_boundary(pos) { s.insert_str(pos, &ch.to_string().repeat(n)); } - galley = p.layout_no_wrap(s, font.clone(), color); + galley = p.layout_job(cell_job(s, font.clone(), color, f32::INFINITY, slant)); w = galley.size().x; } // Center Across Selection: the text is centred over this cell and the empty cells to its right that also use it. @@ -1381,8 +1384,7 @@ pub(crate) fn paint_quadrant( let angle = -(st.align.rotation as f32).to_radians(); // Upright (±90°) wrapped text wraps to the row height: lines then stack across the column. let galley = if st.align.wrap && st.align.rotation.abs() == 90 { - let job = egui::text::LayoutJob::simple(text.clone(), font.clone(), color, (rect.height() - 2.0 * pad).max(4.0)); - p.layout_job(job) + p.layout_job(cell_job(text.clone(), font.clone(), color, (rect.height() - 2.0 * pad).max(4.0), slant)) } else { galley.clone() }; @@ -1391,7 +1393,7 @@ pub(crate) fn paint_quadrant( shape.angle = angle; cp.add(shape); } else { - cp.galley(pos2(x, y), galley.clone(), color); + paint_cell_galley(&cp, pos2(x, y), galley.clone(), color, bold_dx); } let baseline = y + gh * 0.82; match st.font.underline { @@ -1604,6 +1606,25 @@ fn merged_edges( out } +/// One cell's text as a layout job, wrapped at `wrap` (`f32::INFINITY`: one line). `slant` draws it +/// oblique, for an italic cell whose font has no italic face (see [`crate::fonts::is_slanted`]). +fn cell_job(text: String, font: FontId, color: Color32, wrap: f32, slant: bool) -> egui::text::LayoutJob { + let mut job = egui::text::LayoutJob::simple(text, font, color, wrap); + for section in &mut job.sections { + section.format.italics = slant; + } + job +} + +/// Paints one cell's text; `bold_dx` > 0 paints it again that far right, to thicken a bold cell +/// whose font has no bold face (see [`crate::fonts::is_emboldened`]). +fn paint_cell_galley(p: &Painter, pos: Pos2, galley: std::sync::Arc, color: Color32, bold_dx: f32) { + if bold_dx > 0.0 { + p.galley(pos + egui::vec2(bold_dx, 0.0), galley.clone(), color); + } + p.galley(pos, galley, color); +} + /// The smaller font that makes `text` fit in `room` points of width (Shrink to fit), or `None` /// when it already fits at its own size. fn shrink_font(p: &Painter, text: &str, font: &FontId, room: f32) -> Option { diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 5d5f1efeee..49c18d66bc 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -1,6 +1,6 @@ # UI parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-23 · **Change:** minor (New Formatting Rule's formula box takes references clicked or dragged on the grid, #2348; Page Up and Ctrl+Up into frozen rows, Ctrl+Left and Alt+Page Up into frozen columns bring the scrolled area back; Auto Fill Options button after a left-drag of the fill handle (#1403); Show Outline Symbols, Ctrl+8; a too-wide number in a repeat-fill format such as Accounting shows #### instead of losing its leading digits; Esc and Enter close a data validation alert over the cell editor; Ctrl+Enter fill gives each cell the automatic number format typing gives it; keytip letters typed with Alt held, #1846; Number Stored as Text indicator and Convert to Number) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-24 · **Change:** minor (italic and bold in a font with one face, such as Arial Black, are slanted and thickened as Excel does; New Formatting Rule's formula box takes references clicked or dragged on the grid, #2348; Page Up and Ctrl+Up into frozen rows, Ctrl+Left and Alt+Page Up into frozen columns bring the scrolled area back; Auto Fill Options button after a left-drag of the fill handle (#1403); Show Outline Symbols, Ctrl+8; a too-wide number in a repeat-fill format such as Accounting shows #### instead of losing its leading digits; Esc and Enter close a data validation alert over the cell editor; Ctrl+Enter fill gives each cell the automatic number format typing gives it; keytip letters typed with Alt held, #1846; Number Stored as Text indicator and Convert to Number) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 Interaction, controls and feel, against Excel. Part of [target-app-parity.md](target-app-parity.md). **UI/UX fidelity: ~55% ready, 50–80 h** (estimated). Ribbon command coverage is measured @@ -178,6 +178,7 @@ scrollbar bugs 2–4 · pixel/feel pass against observed Excel 7–12. | Date | Change | Summary | |---|---|---| +| 2026-10-24 | minor | Italic and bold in an installed font that has no face for them (Arial Black has a single face) are imitated on the grid, as Excel does: the text is slanted and drawn a second time a little to the right (about 1/36 of the size, at least one pixel). Observed in Excel's PDF of a cell in Arial Black, bold italic: oblique by 1/3 and outlined 0.23 pt thick at 9 pt. egui's slant is fixed at about 1/4. Print and PDF still use the standard PDF fonts (`fonts.rs` test) | | 2026-10-23 | minor | Conditional Formatting ▸ New Rule, formula: clicking a cell on the grid writes its absolute reference at the formula box's caret (`=$B$2`, an empty box starts with `=`), a drag writes a range (`$B$2:$C$4`) and a second click replaces the reference just written, as in Excel ("Selecting cells on the worksheet inserts absolute cell references"). The selection the rule applies to doesn't move, and the box keeps the keyboard. After an operand (`=A1>5`) the click does nothing (#2348) | | 2026-10-23 | minor | Frozen panes: Page Up, Ctrl+Up and Shift variants that move from the scrolled rows into the frozen ones bring the scrolled rows back to the top, so the rows in between are seen again (Page Up from far down used to end on row 1 with the view still a page down); Ctrl+Left and Alt+Page Up do the same for frozen columns. Other ways of selecting a frozen cell (click, Find, Go To, Undo, formula pointing) leave the view where it is | | 2026-10-23 | minor | After a left-drag of the fill handle an Auto Fill Options button sits below the filled cells; its menu redoes the fill as Copy Cells, Fill Series, Fill Formatting Only or Fill Without Formatting (undoes the drag's fill, then `edit.autoFill` in that mode). It goes away when the workbook changes or the selection moves (#1403) | From c4ef580a22a5c276a76e94401085bef5b7a932db Mon Sep 17 00:00:00 2001 From: DerKarussellbremser <67138735+DerKarussellbremser@users.noreply.github.com> Date: Sat, 24 Oct 2026 14:41:41 +0200 Subject: [PATCH 2/9] Grid: imitate the styles of the face actually drawn; bold for shrunk and rotated text Review fixes. The slant and bold markers are now set from the face the role is drawn in (the first whose file could be read), so a family whose bold or italic file is missing gets them imitated too, and a later binding that no longer needs a marker removes it. The bold offset follows the size that is painted after Shrink to Fit, and rotated text gets its second impression along its own direction. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KKbbMZpkzQuncTpqAyhkp9 --- crates/ui-egui/src/fonts.rs | 33 ++++++++++++++++++++++----------- crates/ui-egui/src/grid.rs | 15 ++++++++++++--- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/crates/ui-egui/src/fonts.rs b/crates/ui-egui/src/fonts.rs index 11125a9b04..a785c65b2e 100644 --- a/crates/ui-egui/src/fonts.rs +++ b/crates/ui-egui/src/fonts.rs @@ -326,13 +326,9 @@ pub fn bind_faces(fonts: &mut egui::FontDefinitions, family: &str, faces: &[Face for (bold, italic) in [(false, false), (true, false), (false, true), (true, true)] { let Some(primary) = pick_face(faces, bold, italic) else { continue }; let role = role_key(family, bold, italic); - if italic && !primary.italic { - mark_synthetic(&role, SLANT); - } - if bold && pick_face(faces, false, italic).is_some_and(|plain| face_key(plain) == face_key(primary)) { - mark_synthetic(&role, BOLD); - } let mut chain: Vec = Vec::new(); + // The face the role's text is actually drawn in: the first one whose file could be read. + let mut drawn: Option<&Face> = None; for face in [Some(primary), pick_face(faces, false, false)] { let Some(face) = face else { continue }; let key = face_key(face); @@ -346,10 +342,14 @@ pub fn bind_faces(fonts: &mut egui::FontDefinitions, family: &str, faces: &[Face fonts.font_data.insert(key.clone(), std::sync::Arc::new(fd)); } chain.push(key); + drawn.get_or_insert(face); } - if chain.is_empty() { - continue; - } + let Some(drawn) = drawn else { continue }; + // Imitate what the drawn face lacks: italic when it is upright; bold when it is the family's + // plain face (the family has no bold of its own, or the bold file couldn't be read). + let own_bold = pick_face(faces, false, italic).is_none_or(|plain| face_key(plain) != face_key(primary)); + set_synthetic(&role, SLANT, italic && !drawn.italic); + set_synthetic(&role, BOLD, bold && (face_key(drawn) != face_key(primary) || !own_bold)); chain.extend(base.iter().cloned()); fonts.families.insert(egui::FontFamily::Name(role.clone().into()), chain); bound.push(role); @@ -391,8 +391,14 @@ fn synthetic() -> &'static std::sync::RwLock> { SYNTHETIC.get_or_init(|| std::sync::RwLock::new(HashSet::new())) } -fn mark_synthetic(role: &str, style: &str) { - synthetic().write().unwrap_or_else(|e| e.into_inner()).insert(format!("{role}|{style}")); +fn set_synthetic(role: &str, style: &str, on: bool) { + let mut set = synthetic().write().unwrap_or_else(|e| e.into_inner()); + let key = format!("{role}|{style}"); + if on { + set.insert(key); + } else { + set.remove(&key); + } } fn is_synthetic(role: &str, style: &str) -> bool { @@ -530,9 +536,14 @@ mod tests { face("Full", "full-bi.ttf", 700.0, true), ]; bound.extend(bind_faces(&mut fonts, "Full", &full)); + // Bold and italic faces whose files can't be read: the regular face draws them, imitated. + let gone = |file: &str, weight: f32, italic: bool| Face { path: dir.join(file), ..face("Gone", "gone.ttf", weight, italic) }; + let broken = [face("Gone", "gone.ttf", 400.0, false), gone("missing-b.ttf", 700.0, false), gone("missing-i.ttf", 400.0, true)]; + bound.extend(bind_faces(&mut fonts, "Gone", &broken)); set_bound(bound); assert!(is_slanted("One Face", false) && is_slanted("One Face", true)); assert!(is_emboldened("One Face", false) && is_emboldened("One Face", true)); + assert!(is_slanted("Gone", false) && is_emboldened("Gone", false), "the regular face stands in, imitated"); assert!(!is_slanted("Full", false) && !is_slanted("Full", true), "its own italic faces are drawn as they are"); assert!(!is_emboldened("Full", false) && !is_emboldened("Full", true), "its own bold faces are drawn as they are"); assert!(!is_slanted("Not Bound", false) && !is_emboldened("Not Bound", false)); diff --git a/crates/ui-egui/src/grid.rs b/crates/ui-egui/src/grid.rs index ce5545b8c6..7bf2b15b4b 100644 --- a/crates/ui-egui/src/grid.rs +++ b/crates/ui-egui/src/grid.rs @@ -1244,7 +1244,9 @@ pub(crate) fn paint_quadrant( let font = FontId::new(size, fam); let slant = st.font.italic && crate::fonts::is_slanted(&st.font.name, st.font.bold); let embolden = st.font.bold && crate::fonts::is_emboldened(&st.font.name, st.font.italic); - let bold_dx = if embolden { (size / 36.0).max(1.0 / p.ctx().pixels_per_point()) } else { 0.0 }; + // How far the second impression of imitated bold sits from the first, by the size painted. + let ppp = p.ctx().pixels_per_point(); + let bold_dx = |size: f32| if embolden { (size / 36.0).max(1.0 / ppp) } else { 0.0 }; // Digits fit by the cell's own font and size, not the default 11pt (9pt marks in narrow columns). let char_w = p.layout_no_wrap("0".to_string(), font.clone(), Color32::PLACEHOLDER).size().x.max(1.0); let avail_w = rect.right() - text_left; @@ -1284,7 +1286,7 @@ pub(crate) fn paint_quadrant( _ => text_left + pad + indent, }; let y = wrapped_cell_text_y(st.align.v, *rect, galley.size().y, z); - paint_cell_galley(&p.with_clip_rect(rect.intersect(p.clip_rect())), pos2(x, y), galley, color, bold_dx); + paint_cell_galley(&p.with_clip_rect(rect.intersect(p.clip_rect())), pos2(x, y), galley, color, bold_dx(size)); continue; } // Wrap Text off: Excel ignores the line breaks and draws the whole string on one line. @@ -1389,11 +1391,18 @@ pub(crate) fn paint_quadrant( galley.clone() }; let pos = rotated_text_pos(*rect, galley.size(), angle, painted_halign(st.align.h, geo.rtl), st.align.v, pad, indent); + // Imitated bold: the second impression along the text's own direction. + let d = bold_dx(font.size); + if d > 0.0 { + let mut thick = egui::epaint::TextShape::new(pos + d * egui::vec2(angle.cos(), angle.sin()), galley.clone(), color); + thick.angle = angle; + cp.add(thick); + } let mut shape = egui::epaint::TextShape::new(pos, galley, color); shape.angle = angle; cp.add(shape); } else { - paint_cell_galley(&cp, pos2(x, y), galley.clone(), color, bold_dx); + paint_cell_galley(&cp, pos2(x, y), galley.clone(), color, bold_dx(font.size)); } let baseline = y + gh * 0.82; match st.font.underline { From 1fe4f79db6cfaf718375fc5c923451f3fb13b45c Mon Sep 17 00:00:00 2001 From: Harrison Booth <73434116+Harrison-Booth@users.noreply.github.com> Date: Mon, 26 Oct 2026 07:22:28 -0500 Subject: [PATCH 3/9] Excel open check: save workbooks with the CLI and open them in real Excel, a repair counts as a failure --- ROADMAP.md | 4 +- docs/gaps.md | 4 +- packaging/windows/excel-open-check/README.md | 13 +++ .../windows/excel-open-check/charts.jsonl | 12 ++ packaging/windows/excel-open-check/check.ps1 | 109 ++++++++++++++++++ .../conditional-formats.jsonl | 8 ++ .../windows/excel-open-check/pivots.jsonl | 4 + .../excel-open-check/protection-sheets.jsonl | 9 ++ .../excel-open-check/shapes-pictures.jsonl | 5 + .../excel-open-check/tables-names.jsonl | 13 +++ .../windows/excel-open-check/validation.jsonl | 8 ++ 11 files changed, 187 insertions(+), 2 deletions(-) create mode 100644 packaging/windows/excel-open-check/README.md create mode 100644 packaging/windows/excel-open-check/charts.jsonl create mode 100644 packaging/windows/excel-open-check/check.ps1 create mode 100644 packaging/windows/excel-open-check/conditional-formats.jsonl create mode 100644 packaging/windows/excel-open-check/pivots.jsonl create mode 100644 packaging/windows/excel-open-check/protection-sheets.jsonl create mode 100644 packaging/windows/excel-open-check/shapes-pictures.jsonl create mode 100644 packaging/windows/excel-open-check/tables-names.jsonl create mode 100644 packaging/windows/excel-open-check/validation.jsonl diff --git a/ROADMAP.md b/ROADMAP.md index 6b9b0fce78..817ef74dfe 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -2,7 +2,7 @@ **Stage: alpha** · next: beta, ~25 points of "ready for real work" and ~160–240 h away -> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-10-25 · **Change:** minor (AutoSum over a selected row puts its total to the right, and fills a selection's empty last row and column) · **Target:** Microsoft Excel (Microsoft 365) +> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-10-26 · **Change:** minor (Excel open check script; AutoSum over a selected row puts its total to the right, and fills a selection's empty last row and column) · **Target:** Microsoft Excel (Microsoft 365) GridCraft aims at full Microsoft Excel parity, and at being better in places: faster, open (XLSX is the native format), fully scriptable by agents (MCP, control channel, CLI), and on the web. @@ -135,6 +135,7 @@ Ranked; estimates in Opus 5.5 agent-hours. Detail and the full beta-gate list in | Date | What landed | |---|---| +| 2026-10-26 | Excel open check (`packaging/windows/excel-open-check`): saves workbooks with `gridcraft-cli`, opens each in real Excel through COM so a repair counts as a failure, and records pass or the failure per file; 0.12.1 over 18 public fixtures and 7 feature scenarios: 24 of 25 open cleanly, the other is the legacy-formula slowness of #410 | | 2026-10-25 | AutoSum over a selection does what Excel does: a selected row gets one total to its right (in its last cell if that is empty), not a one-cell total under each cell; a block whose last column is empty gets each row's total there, one whose last row is empty each column's, and with both the corner gets the total of the block; otherwise totals go under each column as before | | 2026-10-24 | Go To lists the named ranges of every sheet (`Sheet2!Name` for a name scoped to another sheet; hidden names, constants and formulas left out) and the references entered before, a double-click goes to an entry, and the Reference box takes several names or references separated by commas (`Price, Type`, `B14:C22,F19:G30`) | | 2026-10-24 | Status bar: a right-click opens a menu that sets which selection statistics show (Average, Count and Sum by default; Numerical Count, Minimum and Maximum are new), kept with the preferences (`view.statusBar`) | @@ -242,6 +243,7 @@ Ranked; estimates in Opus 5.5 agent-hours. Detail and the full beta-gate list in | Date | Change | Summary | |---|---|---| +| 2026-10-26 | minor | Progress log: Excel open check | | 2026-10-25 | minor | Progress log: AutoSum over a selected row, and a selection's empty last row and column | | 2026-10-23 | minor | Progress log: accounting negatives in number text | | 2026-10-23 | minor | Progress log: INDEX with one index on a 2-D reference is #REF! | diff --git a/docs/gaps.md b/docs/gaps.md index 97299acda0..cd026b845f 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -1,6 +1,6 @@ # Gaps -> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-10-24 · **Change:** minor (§8: PivotTable Enable show details; earlier: PivotTable Show Details) · **Target:** Microsoft Excel (Microsoft 365) +> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-10-26 · **Change:** minor (§1: repeatable Excel open check; §8: PivotTable Enable show details; earlier: PivotTable Show Details) · **Target:** Microsoft Excel (Microsoft 365) Every known shortfall against Excel, one entry each, ranked by user impact (what blocks someone using GridCraft for real work first). This is the work list: pick from the top, check the open @@ -22,6 +22,7 @@ No alpha blockers: every core workflow passes the [alpha gate](roadmap.md#alpha- - **Evidence:** round-trip tests cover our own files only (`crates/xlsx/src/tests/`); PivotTable round-trip noted as "unverified in real Excel" since 10-07; #64 (dynamic-array flag) shows the class of bug. +- **Check:** `packaging/windows/excel-open-check/check.ps1` saves workbooks with `gridcraft-cli` and opens each result in real Excel through COM with `CorruptLoad` = normal load, so a repair is a failure. The 0.12.1 run (18 public synthetic fixtures + 7 feature scenarios: charts, pivots with pivot chart and slicer, CF, validation, tables and names, shapes and pictures, sheets and protection) gave 24 of 25 saved files opening cleanly; the 25th (`gc_legacy_to_array`) is not a repair but Excel taking over 200 s on legacy formulas saved as whole-column array formulas (#410, open PRs #417, #1367, #1660). Still open: a run over a large real-world corpus. - **Impact:** the main format; a repair prompt or silent loss destroys trust. - **Estimate:** 15–25 h, plus owner time in Excel. [file-format-parity.md](file-format-parity.md) @@ -183,6 +184,7 @@ No alpha blockers: every core workflow passes the [alpha gate](roadmap.md#alpha- | Date | Change | Summary | |---|---|---| +| 2026-10-26 | minor | §1: `packaging/windows/excel-open-check` opens saved workbooks in real Excel and records pass or the exact failure; first run: 24 of 25 open cleanly | | 2026-10-24 | minor | §8: PivotTable Enable show details: `pivot.options` `enableShowDetails` turns Show Details off for a PivotTable, read and written in XLSX as `enableDrill` | | 2026-10-23 | minor | §8: PivotTable Show Details: double-clicking a value cell lists its source records on a new sheet (#2364) | | 2026-10-22 | minor | §20: a native window per workbook window, New Window on the same workbook and Arrange All on the desktop; left: Arrange All across monitors, the web's one window, pen pressure (estimate 10–14 h → 5–8 h) | diff --git a/packaging/windows/excel-open-check/README.md b/packaging/windows/excel-open-check/README.md new file mode 100644 index 0000000000..a927997bb1 --- /dev/null +++ b/packaging/windows/excel-open-check/README.md @@ -0,0 +1,13 @@ +# Excel open check + +Saves workbooks with `gridcraft-cli` and opens each result in real Excel (COM), recording per file `PASS` or the +exact failure. Windows with Excel only. See `check.ps1` for the options. + +```powershell +.\check.ps1 -Cli C:\gridcraft\gridcraft-cli.exe -Inputs C:\workbooks -Csv result.csv +``` + +Inputs are any `.xlsx`/`.xlsm` (the synthetic `gridcraft/` fixtures in a public fixtures repo are a good start); each +`*.jsonl` here is a feature scenario run on the Sales sample. Add a scenario by dropping in another `.jsonl` +(`gridcraft-cli run --script` format). Results: `Original` is the input opened in Excel (so a file Excel itself +rejects or loads slowly isn't blamed on GridCraft), `Saved` is the GridCraft-saved copy. diff --git a/packaging/windows/excel-open-check/charts.jsonl b/packaging/windows/excel-open-check/charts.jsonl new file mode 100644 index 0000000000..3746a83e9c --- /dev/null +++ b/packaging/windows/excel-open-check/charts.jsonl @@ -0,0 +1,12 @@ +# One chart of each common kind over the sales table +insert.chart={"range":"B4:F8","type":"bar","at":"K36"} +insert.chart={"range":"B4:F8","type":"line","subtype":"markers","at":"S3"} +insert.chart={"range":"B4:F8","type":"area","subtype":"stacked","at":"S19"} +insert.chart={"range":"C5:D8","type":"scatter","at":"S36"} +insert.chart={"range":"B4:F8","type":"radar","at":"AA3"} +insert.chart={"range":"B4:C8","type":"doughnut","at":"AA19"} +insert.chart={"range":"B4:C8","type":"waterfall","at":"AA36"} +insert.chart={"range":"B4:C8","type":"treemap","at":"AI3"} +insert.chart={"range":"B4:C8","type":"histogram","at":"AI19"} +insert.sparkline={"range":"C5:F5","location":"J5","type":"line"} +insert.sparkline={"range":"C6:F6","location":"J6","type":"column"} diff --git a/packaging/windows/excel-open-check/check.ps1 b/packaging/windows/excel-open-check/check.ps1 new file mode 100644 index 0000000000..08dff4f162 --- /dev/null +++ b/packaging/windows/excel-open-check/check.ps1 @@ -0,0 +1,109 @@ +<# +Excel open check: saves workbooks with GridCraft, opens each result in real Excel (COM) and records per +file whether Excel loads it as it is or has to repair it (docs/file-format-parity.md, "Excel open check"). + + check.ps1 -Cli C:\gridcraft\gridcraft-cli.exe [-Inputs C:\workbooks] [-Out C:\out] [-Csv result.csv] + [-TimeoutSec 120] + +Files saved: + - every .xlsx / .xlsm in -Inputs, opened and saved with `gridcraft-cli run --in --out` (the original + is opened in Excel too, so a file Excel itself dislikes or loads slowly is told apart from a + GridCraft regression); + - every *.jsonl scenario next to this script (one feature each), run on the Sales sample. + +Each file is opened read-only with CorruptLoad = xlNormalLoad (0), so a part Excel would repair is a +failure instead of a silent fix, with DisplayAlerts off and macros disabled so nothing waits on a prompt. +Excel is a fresh instance per file; a file that hangs or kills Excel is recorded as TIMEOUT or CRASH and +Excel started by this script is stopped. Nothing is written next to the inputs; Excel processes that were +already running are never touched. Exit code 1 when any saved file is not PASS. +#> +param( + [Parameter(Mandatory = $true)][string]$Cli, + [string]$Inputs, + [string]$Out = (Join-Path ([IO.Path]::GetTempPath()) 'gridcraft-excel-open-check'), + [string]$Csv, + [int]$TimeoutSec = 120 +) +$ErrorActionPreference = 'Stop' + +# Excel processes already running are the person's own work: only ones started after this point are ever killed. +$before = @(Get-Process EXCEL -ErrorAction SilentlyContinue | ForEach-Object Id) +function Stop-Excel { + Get-Process EXCEL -ErrorAction SilentlyContinue | Where-Object { $before -notcontains $_.Id } | Stop-Process -Force -ErrorAction SilentlyContinue +} + +# Runs in a child PowerShell so a hang can be killed after $TimeoutSec without taking this script with it. +$probe = { + param($path) + $x = $null + try { + $x = New-Object -ComObject Excel.Application + $x.Visible = $false + $x.DisplayAlerts = $false + $x.AutomationSecurity = 3 # msoAutomationSecurityForceDisable: never run macros + # Named arguments: PowerShell can't skip the optional ones in between positionally. + $wb = [System.__ComObject].InvokeMember('Open', [Reflection.BindingFlags]::InvokeMethod, $null, $x.Workbooks, + @($path, 0, $true, 0), $null, $null, @('Filename', 'UpdateLinks', 'ReadOnly', 'CorruptLoad')) + $sheets = $wb.Worksheets.Count + $wb.Chartsheets.Count + $wb.Close($false) + "PASS`t$sheets sheets" + } catch { + "FAIL`t" + ($_.Exception.Message -replace '\s+', ' ') + } finally { + if ($x) { try { $x.Quit() } catch {} } + } +} + +function Test-InExcel([string]$path) { + $clock = [Diagnostics.Stopwatch]::StartNew() + $job = Start-Job -ScriptBlock $probe -ArgumentList $path + if (Wait-Job $job -Timeout $TimeoutSec) { + $out = (Receive-Job $job) -join ' ' + if (-not $out) { $out = "CRASH`tno result (Excel died)" } + } else { + Stop-Job $job + $out = "TIMEOUT`tno answer in $TimeoutSec s" + } + Remove-Job $job -Force + # Next file only once this Excel has exited, else its first call can get RPC_E_SERVERCALL_RETRYLATER. + $deadline = (Get-Date).AddSeconds(15) + while ((Get-Date) -lt $deadline -and @(Get-Process EXCEL -ErrorAction SilentlyContinue | Where-Object { $before -notcontains $_.Id }).Count) { Start-Sleep -Milliseconds 200 } + Stop-Excel + $state, $detail = $out -split "`t", 2 + [pscustomobject]@{ State = $state; Seconds = [math]::Round($clock.Elapsed.TotalSeconds, 1); Detail = $detail } +} + +$saved = Join-Path $Out 'saved' +Remove-Item $saved -Recurse -Force -ErrorAction SilentlyContinue +New-Item -ItemType Directory -Path $saved -Force | Out-Null + +# (name, original or $null, saved) per file +$work = @() +if ($Inputs) { + foreach ($f in Get-ChildItem -Path $Inputs -File | Where-Object { $_.Extension -in '.xlsx', '.xlsm' } | Sort-Object Name) { + $work += , @($f.Name, $f.FullName, (Join-Path $saved $f.Name), @('run', '--in', $f.FullName, '--quiet')) + } +} +foreach ($s in Get-ChildItem -Path $PSScriptRoot -Filter *.jsonl | Sort-Object Name) { + $work += , @("scenario:$($s.BaseName)", $null, (Join-Path $saved "$($s.BaseName).xlsx"), @('run', '--sample', 'sales', '--script', $s.FullName, '--quiet')) +} + +$rows = @() +foreach ($w in $work) { + $name, $orig, $dest, $cliArgs = $w + # The CLI reports on stderr, which Stop would turn into an exception. + $ErrorActionPreference = 'Continue' + & $Cli @cliArgs --out $dest *> $null + $ErrorActionPreference = 'Stop' + $base = if ($orig) { (Test-InExcel $orig) } else { $null } + $r = if (Test-Path $dest) { Test-InExcel $dest } else { [pscustomobject]@{ State = 'SAVE-FAIL'; Seconds = 0; Detail = "gridcraft-cli exit code $LASTEXITCODE" } } + $rows += [pscustomobject]@{ + File = $name; Original = if ($base) { $base.State } else { '-' }; Saved = $r.State + Seconds = $r.Seconds; Detail = $r.Detail + } +} +$rows | Format-Table -AutoSize -Wrap | Out-String -Width 220 | Write-Output +if ($Csv) { $rows | Export-Csv -NoTypeInformation -Path $Csv } +$bad = @($rows | Where-Object Saved -ne 'PASS').Count +"{0} of {1} saved files pass" -f ($rows.Count - $bad), $rows.Count +if ($bad) { exit 1 } diff --git a/packaging/windows/excel-open-check/conditional-formats.jsonl b/packaging/windows/excel-open-check/conditional-formats.jsonl new file mode 100644 index 0000000000..ebfb544fa9 --- /dev/null +++ b/packaging/windows/excel-open-check/conditional-formats.jsonl @@ -0,0 +1,8 @@ +# Colour scale, data bar, icon set, top 10, formula and text rules +home.conditionalFormat={"range":"C5:F8","rule":{"type":"colorScale"}} +home.conditionalFormat={"range":"C5:C8","rule":{"type":"dataBar"}} +home.conditionalFormat={"range":"D5:D8","rule":{"type":"iconSet"}} +home.conditionalFormat={"range":"E5:E8","rule":{"type":"top10","rank":2}} +home.conditionalFormat={"range":"F5:F8","rule":{"type":"cellIs","operator":"greaterThan","value":"60000","preset":"lightRedFill"}} +home.conditionalFormat={"range":"B5:B8","rule":{"type":"containsText","text":"th","preset":"yellowFill"}} +home.conditionalFormat={"range":"C5:F8","rule":{"type":"expression","formula":"=C5>AVERAGE($C$5:$F$8)","preset":"greenFill"}} diff --git a/packaging/windows/excel-open-check/pivots.jsonl b/packaging/windows/excel-open-check/pivots.jsonl new file mode 100644 index 0000000000..23315f9e8b --- /dev/null +++ b/packaging/windows/excel-open-check/pivots.jsonl @@ -0,0 +1,4 @@ +# PivotTable on the sales table, a pivot chart, a table slicer +insert.pivotTable={"source":"Sales","destination":"Sales!K40","rows":["Region"],"values":[{"field":"Q1","func":"sum"}]} +insert.pivotChart={"pivot":"Sales!K42","type":"column","at":"S50"} +insert.slicer={"table":"Sales","column":"Region","at":"AA50"} diff --git a/packaging/windows/excel-open-check/protection-sheets.jsonl b/packaging/windows/excel-open-check/protection-sheets.jsonl new file mode 100644 index 0000000000..f05bd57ce4 --- /dev/null +++ b/packaging/windows/excel-open-check/protection-sheets.jsonl @@ -0,0 +1,9 @@ +# Extra sheets (renamed, coloured, hidden), grouping and a protected sheet +home.insertSheet={} +sheet.rename={"name":"Second"} +sheet.tabColor={"color":"#FF0000"} +cell.set={"cell":"A1","input":"=Sales!B5&\" \"&Sales!C5"} +home.insertSheet={} +sheet.hide={} +sheet.activate={"sheet":"Sales"} +review.protectSheet={"formatCells":true} diff --git a/packaging/windows/excel-open-check/shapes-pictures.jsonl b/packaging/windows/excel-open-check/shapes-pictures.jsonl new file mode 100644 index 0000000000..ecfcfbbaef --- /dev/null +++ b/packaging/windows/excel-open-check/shapes-pictures.jsonl @@ -0,0 +1,5 @@ +# Shapes with text and a picture from base64 (a 1x1 PNG) +insert.shape={"kind":"rectangle","at":"K30","width":120,"height":40,"text":"Box","fill":"#FFC000"} +insert.shape={"kind":"ellipse","at":"O30","width":80,"height":40} +insert.shape={"kind":"arrow","at":"K33","width":80,"height":30} +insert.picture={"base64":"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==","mime":"image/png","at":"B20","width":60,"height":60,"alt":"dot"} diff --git a/packaging/windows/excel-open-check/tables-names.jsonl b/packaging/windows/excel-open-check/tables-names.jsonl new file mode 100644 index 0000000000..98f07d0949 --- /dev/null +++ b/packaging/windows/excel-open-check/tables-names.jsonl @@ -0,0 +1,13 @@ +# Table style and total row, defined names, merged cells, frozen panes, hyperlink-free cell notes +selection.set={"cell":"C5"} +table.totalRow={} +table.style={"style":"TableStyleLight9"} +formulas.defineName={"name":"NorthQ1","refersTo":"=Sales!$C$5"} +formulas.defineName={"name":"AllRegions","refersTo":"=Sales!$B$5:$B$8"} +formulas.defineName={"name":"Rate","refersTo":"=0.2","comment":"tax rate"} +cell.set={"cell":"K14","input":"=SUM(AllRegions)"} +cell.set={"cell":"K15","input":"=NorthQ1*Rate"} +home.mergeCells={"range":"K16:M16"} +view.freezePanes={"cell":"C5"} +review.newNote={"cell":"C5","text":"checked"} +review.newComment={"cell":"D5","text":"threaded"} diff --git a/packaging/windows/excel-open-check/validation.jsonl b/packaging/windows/excel-open-check/validation.jsonl new file mode 100644 index 0000000000..cd7e2efa09 --- /dev/null +++ b/packaging/windows/excel-open-check/validation.jsonl @@ -0,0 +1,8 @@ +# One rule of each kind +data.validation={"range":"K2:K5","type":"list","formula1":"North,South,East,West"} +data.validation={"range":"K6:K8","type":"whole","operator":"between","formula1":"1","formula2":"100","inputTitle":"Count","inputMessage":"1 to 100","errorStyle":"warning"} +data.validation={"range":"L2:L5","type":"decimal","operator":"greaterThan","formula1":"0"} +data.validation={"range":"L6:L8","type":"date","operator":"greaterOrEqual","formula1":"2026-01-01"} +data.validation={"range":"M2:M5","type":"textLength","operator":"lessOrEqual","formula1":"10"} +data.validation={"range":"M6:M8","type":"custom","formula1":"=ISNUMBER(M6)"} +data.validation={"range":"N2:N5","type":"list","formula1":"=$B$5:$B$8"} From cfcde5bfbd665ea22bf36c51e4130ef26a9a7409 Mon Sep 17 00:00:00 2001 From: Harrison Booth <73434116+Harrison-Booth@users.noreply.github.com> Date: Mon, 26 Oct 2026 07:35:56 -0500 Subject: [PATCH 4/9] Excel open check: stop only the Excel instance a probe started, found by its window's process id --- packaging/windows/excel-open-check/check.ps1 | 37 ++++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/packaging/windows/excel-open-check/check.ps1 b/packaging/windows/excel-open-check/check.ps1 index 08dff4f162..68c9b1afcd 100644 --- a/packaging/windows/excel-open-check/check.ps1 +++ b/packaging/windows/excel-open-check/check.ps1 @@ -14,8 +14,8 @@ Files saved: Each file is opened read-only with CorruptLoad = xlNormalLoad (0), so a part Excel would repair is a failure instead of a silent fix, with DisplayAlerts off and macros disabled so nothing waits on a prompt. Excel is a fresh instance per file; a file that hangs or kills Excel is recorded as TIMEOUT or CRASH and -Excel started by this script is stopped. Nothing is written next to the inputs; Excel processes that were -already running are never touched. Exit code 1 when any saved file is not PASS. +that instance (found by its window's process id) is stopped. Nothing is written next to the inputs; any other +Excel, such as one the person starts meanwhile, is never touched. Exit code 1 when any saved file is not PASS. #> param( [Parameter(Mandatory = $true)][string]$Cli, @@ -26,12 +26,6 @@ param( ) $ErrorActionPreference = 'Stop' -# Excel processes already running are the person's own work: only ones started after this point are ever killed. -$before = @(Get-Process EXCEL -ErrorAction SilentlyContinue | ForEach-Object Id) -function Stop-Excel { - Get-Process EXCEL -ErrorAction SilentlyContinue | Where-Object { $before -notcontains $_.Id } | Stop-Process -Force -ErrorAction SilentlyContinue -} - # Runs in a child PowerShell so a hang can be killed after $TimeoutSec without taking this script with it. $probe = { param($path) @@ -39,6 +33,11 @@ $probe = { try { $x = New-Object -ComObject Excel.Application $x.Visible = $false + # Report this instance's process id so the caller can stop exactly it and nothing else. + Add-Type -Namespace Win -Name U -MemberDefinition '[DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr h, out uint pid);' + $xlPid = [uint32]0 + [void][Win.U]::GetWindowThreadProcessId([IntPtr]$x.Hwnd, [ref]$xlPid) + "PID`t$xlPid" $x.DisplayAlerts = $false $x.AutomationSecurity = 3 # msoAutomationSecurityForceDisable: never run macros # Named arguments: PowerShell can't skip the optional ones in between positionally. @@ -57,18 +56,18 @@ $probe = { function Test-InExcel([string]$path) { $clock = [Diagnostics.Stopwatch]::StartNew() $job = Start-Job -ScriptBlock $probe -ArgumentList $path - if (Wait-Job $job -Timeout $TimeoutSec) { - $out = (Receive-Job $job) -join ' ' - if (-not $out) { $out = "CRASH`tno result (Excel died)" } - } else { - Stop-Job $job - $out = "TIMEOUT`tno answer in $TimeoutSec s" - } + $done = Wait-Job $job -Timeout $TimeoutSec + $lines = @(Receive-Job $job -Keep) + if (-not $done) { Stop-Job $job } Remove-Job $job -Force - # Next file only once this Excel has exited, else its first call can get RPC_E_SERVERCALL_RETRYLATER. - $deadline = (Get-Date).AddSeconds(15) - while ((Get-Date) -lt $deadline -and @(Get-Process EXCEL -ErrorAction SilentlyContinue | Where-Object { $before -notcontains $_.Id }).Count) { Start-Sleep -Milliseconds 200 } - Stop-Excel + $xlPid = ($lines | Where-Object { $_ -like "PID`t*" } | Select-Object -First 1) -replace '^PID\t', '' + $out = $lines | Where-Object { $_ -notlike "PID`t*" } | Select-Object -Last 1 + if (-not $done) { $out = "TIMEOUT`tno answer in $TimeoutSec s" } elseif (-not $out) { $out = "CRASH`tno result (Excel died)" } + if ($xlPid) { + # A clean Quit lets Excel exit by itself; give it a moment, then stop only this instance. + Wait-Process -Id ([int]$xlPid) -Timeout 15 -ErrorAction SilentlyContinue + Stop-Process -Id ([int]$xlPid) -Force -ErrorAction SilentlyContinue + } $state, $detail = $out -split "`t", 2 [pscustomobject]@{ State = $state; Seconds = [math]::Round($clock.Elapsed.TotalSeconds, 1); Detail = $detail } } From 260b84d09352287812930ebae6906ebd78c5ee76 Mon Sep 17 00:00:00 2001 From: Harrison Booth <73434116+Harrison-Booth@users.noreply.github.com> Date: Mon, 26 Oct 2026 07:47:06 -0500 Subject: [PATCH 5/9] Excel open check: a failed probe job is a CRASH, not an error that ends the run --- packaging/windows/excel-open-check/check.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packaging/windows/excel-open-check/check.ps1 b/packaging/windows/excel-open-check/check.ps1 index 68c9b1afcd..c58a02fb5f 100644 --- a/packaging/windows/excel-open-check/check.ps1 +++ b/packaging/windows/excel-open-check/check.ps1 @@ -57,12 +57,13 @@ function Test-InExcel([string]$path) { $clock = [Diagnostics.Stopwatch]::StartNew() $job = Start-Job -ScriptBlock $probe -ArgumentList $path $done = Wait-Job $job -Timeout $TimeoutSec - $lines = @(Receive-Job $job -Keep) + $lines = @(Receive-Job $job -Keep -ErrorAction SilentlyContinue) + $failed = $job.State -eq 'Failed' if (-not $done) { Stop-Job $job } Remove-Job $job -Force $xlPid = ($lines | Where-Object { $_ -like "PID`t*" } | Select-Object -First 1) -replace '^PID\t', '' $out = $lines | Where-Object { $_ -notlike "PID`t*" } | Select-Object -Last 1 - if (-not $done) { $out = "TIMEOUT`tno answer in $TimeoutSec s" } elseif (-not $out) { $out = "CRASH`tno result (Excel died)" } + if (-not $done) { $out = "TIMEOUT`tno answer in $TimeoutSec s" } elseif ($failed -or -not $out) { $out = "CRASH`tno result (Excel died)" } if ($xlPid) { # A clean Quit lets Excel exit by itself; give it a moment, then stop only this instance. Wait-Process -Id ([int]$xlPid) -Timeout 15 -ErrorAction SilentlyContinue From b023410ca4435e8a45db638b9a686418829af549 Mon Sep 17 00:00:00 2001 From: Harrison Booth <73434116+Harrison-Booth@users.noreply.github.com> Date: Mon, 26 Oct 2026 10:55:56 -0500 Subject: [PATCH 6/9] Excel open check: skip workbooks with Excel 4.0 macro sheets, require a zero CLI exit before opening the saved file --- packaging/windows/excel-open-check/check.ps1 | 21 ++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/packaging/windows/excel-open-check/check.ps1 b/packaging/windows/excel-open-check/check.ps1 index c58a02fb5f..1faabf5bcb 100644 --- a/packaging/windows/excel-open-check/check.ps1 +++ b/packaging/windows/excel-open-check/check.ps1 @@ -12,7 +12,9 @@ Files saved: - every *.jsonl scenario next to this script (one feature each), run on the Sales sample. Each file is opened read-only with CorruptLoad = xlNormalLoad (0), so a part Excel would repair is a -failure instead of a silent fix, with DisplayAlerts off and macros disabled so nothing waits on a prompt. +failure instead of a silent fix, with DisplayAlerts off and VBA macros disabled so nothing waits on a prompt. +AutomationSecurity does not cover Excel 4.0 (XLM) macros, which would still prompt, so a workbook that +holds XLM macro sheets is never opened: it is reported as SKIP-XLM and the run does not pass. Excel is a fresh instance per file; a file that hangs or kills Excel is recorded as TIMEOUT or CRASH and that instance (found by its window's process id) is stopped. Nothing is written next to the inputs; any other Excel, such as one the person starts meanwhile, is never touched. Exit code 1 when any saved file is not PASS. @@ -39,7 +41,7 @@ $probe = { [void][Win.U]::GetWindowThreadProcessId([IntPtr]$x.Hwnd, [ref]$xlPid) "PID`t$xlPid" $x.DisplayAlerts = $false - $x.AutomationSecurity = 3 # msoAutomationSecurityForceDisable: never run macros + $x.AutomationSecurity = 3 # msoAutomationSecurityForceDisable: no VBA macros (XLM is screened by Test-HasXlm) # Named arguments: PowerShell can't skip the optional ones in between positionally. $wb = [System.__ComObject].InvokeMember('Open', [Reflection.BindingFlags]::InvokeMethod, $null, $x.Workbooks, @($path, 0, $true, 0), $null, $null, @('Filename', 'UpdateLinks', 'ReadOnly', 'CorruptLoad')) @@ -53,7 +55,16 @@ $probe = { } } +# True when the package holds Excel 4.0 macro sheets, which ForceDisable does not stop and Excel would prompt for. +function Test-HasXlm([string]$path) { + Add-Type -AssemblyName System.IO.Compression.FileSystem + # Not a zip at all: nothing to screen, Excel gets to report it. + try { $zip = [IO.Compression.ZipFile]::OpenRead($path) } catch { return $false } + try { return [bool]($zip.Entries | Where-Object { $_.FullName -like 'xl/macrosheets/*' }) } finally { $zip.Dispose() } +} + function Test-InExcel([string]$path) { + if (Test-HasXlm $path) { return [pscustomobject]@{ State = 'SKIP-XLM'; Seconds = 0; Detail = 'Excel 4.0 macro sheets; not opened' } } $clock = [Diagnostics.Stopwatch]::StartNew() $job = Start-Job -ScriptBlock $probe -ArgumentList $path $done = Wait-Job $job -Timeout $TimeoutSec @@ -92,11 +103,13 @@ $rows = @() foreach ($w in $work) { $name, $orig, $dest, $cliArgs = $w # The CLI reports on stderr, which Stop would turn into an exception. + Remove-Item $dest -Force -ErrorAction SilentlyContinue $ErrorActionPreference = 'Continue' & $Cli @cliArgs --out $dest *> $null + $code = $LASTEXITCODE $ErrorActionPreference = 'Stop' $base = if ($orig) { (Test-InExcel $orig) } else { $null } - $r = if (Test-Path $dest) { Test-InExcel $dest } else { [pscustomobject]@{ State = 'SAVE-FAIL'; Seconds = 0; Detail = "gridcraft-cli exit code $LASTEXITCODE" } } + $r = if ($code -eq 0 -and (Test-Path $dest)) { Test-InExcel $dest } else { [pscustomobject]@{ State = 'SAVE-FAIL'; Seconds = 0; Detail = "gridcraft-cli exit code $code" } } $rows += [pscustomobject]@{ File = $name; Original = if ($base) { $base.State } else { '-' }; Saved = $r.State Seconds = $r.Seconds; Detail = $r.Detail @@ -104,6 +117,6 @@ foreach ($w in $work) { } $rows | Format-Table -AutoSize -Wrap | Out-String -Width 220 | Write-Output if ($Csv) { $rows | Export-Csv -NoTypeInformation -Path $Csv } -$bad = @($rows | Where-Object Saved -ne 'PASS').Count +$bad = @($rows | Where-Object { $_.Saved -ne 'PASS' -or $_.Original -eq 'SKIP-XLM' }).Count "{0} of {1} saved files pass" -f ($rows.Count - $bad), $rows.Count if ($bad) { exit 1 } From 1053b66a0e8905b82a7ee04fca73c0358a9d6c5f Mon Sep 17 00:00:00 2001 From: Harrison Booth <73434116+Harrison-Booth@users.noreply.github.com> Date: Mon, 26 Oct 2026 11:12:32 -0500 Subject: [PATCH 7/9] Excel open check: literal paths for saved workbooks and the input folder --- packaging/windows/excel-open-check/check.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packaging/windows/excel-open-check/check.ps1 b/packaging/windows/excel-open-check/check.ps1 index 1faabf5bcb..77cb82ecd1 100644 --- a/packaging/windows/excel-open-check/check.ps1 +++ b/packaging/windows/excel-open-check/check.ps1 @@ -85,13 +85,13 @@ function Test-InExcel([string]$path) { } $saved = Join-Path $Out 'saved' -Remove-Item $saved -Recurse -Force -ErrorAction SilentlyContinue +Remove-Item -LiteralPath $saved -Recurse -Force -ErrorAction SilentlyContinue New-Item -ItemType Directory -Path $saved -Force | Out-Null # (name, original or $null, saved) per file $work = @() if ($Inputs) { - foreach ($f in Get-ChildItem -Path $Inputs -File | Where-Object { $_.Extension -in '.xlsx', '.xlsm' } | Sort-Object Name) { + foreach ($f in Get-ChildItem -LiteralPath $Inputs -File | Where-Object { $_.Extension -in '.xlsx', '.xlsm' } | Sort-Object Name) { $work += , @($f.Name, $f.FullName, (Join-Path $saved $f.Name), @('run', '--in', $f.FullName, '--quiet')) } } @@ -103,13 +103,13 @@ $rows = @() foreach ($w in $work) { $name, $orig, $dest, $cliArgs = $w # The CLI reports on stderr, which Stop would turn into an exception. - Remove-Item $dest -Force -ErrorAction SilentlyContinue + Remove-Item -LiteralPath $dest -Force -ErrorAction SilentlyContinue $ErrorActionPreference = 'Continue' & $Cli @cliArgs --out $dest *> $null $code = $LASTEXITCODE $ErrorActionPreference = 'Stop' $base = if ($orig) { (Test-InExcel $orig) } else { $null } - $r = if ($code -eq 0 -and (Test-Path $dest)) { Test-InExcel $dest } else { [pscustomobject]@{ State = 'SAVE-FAIL'; Seconds = 0; Detail = "gridcraft-cli exit code $code" } } + $r = if ($code -eq 0 -and (Test-Path -LiteralPath $dest)) { Test-InExcel $dest } else { [pscustomobject]@{ State = 'SAVE-FAIL'; Seconds = 0; Detail = "gridcraft-cli exit code $code" } } $rows += [pscustomobject]@{ File = $name; Original = if ($base) { $base.State } else { '-' }; Saved = $r.State Seconds = $r.Seconds; Detail = $r.Detail From c4920c463b33217b01fcce13811d5220d3f4e5df Mon Sep 17 00:00:00 2001 From: Harrison Booth <73434116+Harrison-Booth@users.noreply.github.com> Date: Mon, 26 Oct 2026 11:30:56 -0500 Subject: [PATCH 8/9] Excel open check: count saved passes apart from the XLM gate --- packaging/windows/excel-open-check/check.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packaging/windows/excel-open-check/check.ps1 b/packaging/windows/excel-open-check/check.ps1 index 77cb82ecd1..c5687e778b 100644 --- a/packaging/windows/excel-open-check/check.ps1 +++ b/packaging/windows/excel-open-check/check.ps1 @@ -118,5 +118,6 @@ foreach ($w in $work) { $rows | Format-Table -AutoSize -Wrap | Out-String -Width 220 | Write-Output if ($Csv) { $rows | Export-Csv -NoTypeInformation -Path $Csv } $bad = @($rows | Where-Object { $_.Saved -ne 'PASS' -or $_.Original -eq 'SKIP-XLM' }).Count -"{0} of {1} saved files pass" -f ($rows.Count - $bad), $rows.Count +$savedBad = @($rows | Where-Object Saved -ne 'PASS').Count +"{0} of {1} saved files pass" -f ($rows.Count - $savedBad), $rows.Count if ($bad) { exit 1 } From 9bbcb7ce908b3b734749b3160d3a4037e6d9ea6f Mon Sep 17 00:00:00 2001 From: Harrison Booth <73434116+Harrison-Booth@users.noreply.github.com> Date: Mon, 26 Oct 2026 11:44:00 -0500 Subject: [PATCH 9/9] Excel open check: compile the helper before Excel starts so the PID line is not held up --- packaging/windows/excel-open-check/check.ps1 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packaging/windows/excel-open-check/check.ps1 b/packaging/windows/excel-open-check/check.ps1 index c5687e778b..1e82a48633 100644 --- a/packaging/windows/excel-open-check/check.ps1 +++ b/packaging/windows/excel-open-check/check.ps1 @@ -33,13 +33,14 @@ $probe = { param($path) $x = $null try { - $x = New-Object -ComObject Excel.Application - $x.Visible = $false - # Report this instance's process id so the caller can stop exactly it and nothing else. + # Compiled before Excel starts, so nothing between the start and the PID line can fail or stall on it. Add-Type -Namespace Win -Name U -MemberDefinition '[DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr h, out uint pid);' + $x = New-Object -ComObject Excel.Application + # Report this instance's process id so the caller can stop exactly it and nothing else. $xlPid = [uint32]0 [void][Win.U]::GetWindowThreadProcessId([IntPtr]$x.Hwnd, [ref]$xlPid) "PID`t$xlPid" + $x.Visible = $false $x.DisplayAlerts = $false $x.AutomationSecurity = 3 # msoAutomationSecurityForceDisable: no VBA macros (XLM is screened by Test-HasXlm) # Named arguments: PowerShell can't skip the optional ones in between positionally. @@ -51,6 +52,7 @@ $probe = { } catch { "FAIL`t" + ($_.Exception.Message -replace '\s+', ' ') } finally { + # Also covers a failure before the PID line: this process's own instance is quit, no other is touched. if ($x) { try { $x.Quit() } catch {} } } }