From 0b31398c0d359afc539cd28f2a2a2a3bda173ab0 Mon Sep 17 00:00:00 2001 From: Harrison Booth <73434116+Harrison-Booth@users.noreply.github.com> Date: Tue, 27 Oct 2026 16:20:32 -0500 Subject: [PATCH] Filter: a table filter must reach the table's last data row, and the table part keeps only such filters --- crates/engine/src/cmd/data/filter.rs | 3 +++ crates/xlsx/src/sheet_write/parts.rs | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/data/filter.rs b/crates/engine/src/cmd/data/filter.rs index 59643755b5..f56f9252b4 100644 --- a/crates/engine/src/cmd/data/filter.rs +++ b/crates/engine/src/cmd/data/filter.rs @@ -75,6 +75,9 @@ fn install_filter(s: &mut Session, p: &Json) -> Result { } // A narrower range would leave out the table's criteria on the columns it doesn't cover, and saving would drop them. if let Some(t) = host.and_then(|i| sh.tables.get(i)) { + if t.data_range().is_some_and(|data| r.end.row < data.end.row) { + return Err(bad("data.filter", "filter the table's full data range")); + } let shift = r.start.col.saturating_sub(t.range.start.col); if t.filter.iter().any(|(o, _)| o.checked_sub(shift).is_none_or(|c| c >= r.width())) { return Err(bad("data.filter", "the table is filtered on a column this range leaves out; filter the table's full width")); diff --git a/crates/xlsx/src/sheet_write/parts.rs b/crates/xlsx/src/sheet_write/parts.rs index 579733d6c3..87e0184655 100644 --- a/crates/xlsx/src/sheet_write/parts.rs +++ b/crates/xlsx/src/sheet_write/parts.rs @@ -107,8 +107,12 @@ pub(super) fn autofilter_xml(range: RangeRef, criteria: &[(u32, FilterCriterion) /// as rows hidden by hand, which SUBTOTAL 1-11 counts. pub(super) fn table_filter(sheet: &Sheet, t: &Table) -> Vec<(u32, FilterCriterion)> { let mut criteria = t.filter.clone(); - let Some(af) = sheet.autofilter.as_ref().filter(|af| t.header_row && af.range.start.row == t.range.start.row && af.range.intersects(&t.range)) - else { + let Some(af) = sheet.autofilter.as_ref().filter(|af| { + t.header_row + && af.range.start.row == t.range.start.row + && af.range.intersects(&t.range) + && t.data_range().is_some_and(|d| af.range.end.row >= d.end.row) + }) else { return criteria; }; for (off, c) in &af.criteria {