Fix hidden Values row with page filters

This commit is contained in:
Neil Cawse
2026-10-22 05:19:41 +00:00
parent 32b2bbe471
commit 12c08d7e9d
2 changed files with 12 additions and 2 deletions
+3 -2
View File
@@ -909,8 +909,9 @@ fn table_xml(pt: &PivotTable, idx: usize, cache_id: u32, c: &Cache, fmt_id: &dyn
row_levels.max(1)
};
// Two or more value fields in Columns alone: Excel 365 adds a `Values` caption row
// when field headers are shown. Page-filter layouts retain their classic header row.
let hide_values_row = col_values.is_some() && col_idx.is_empty() && pages.is_empty() && pt.show_headers;
// when field headers are shown. Page-filter layouts retain their classic header row
// unless the table explicitly hides the Values row.
let hide_values_row = col_values.is_some() && col_idx.is_empty() && (pages.is_empty() || !pt.show_values_row) && pt.show_headers;
let first_header_row = usize::from(!hide_values_row);
let _ = write!(
s,
+9
View File
@@ -743,6 +743,15 @@ fn location_without_field_headers_has_no_values_row() {
let parts = unzip(&write_xlsx(&wb).unwrap());
let t3 = String::from_utf8(parts.get("xl/pivotTables/pivotTable3.xml").unwrap().clone()).unwrap();
assert!(t3.contains("firstHeaderRow=\"1\" firstDataRow=\"2\""), "{t3}");
{
let p = &mut wb.sheet_mut(1).unwrap().pivots[2];
p.values.push(PivotValue { source_col: "Sales".into(), name: "Sum of Sales".into(), ..PivotValue::default() });
p.show_values_row = false;
}
let parts = unzip(&write_xlsx(&wb).unwrap());
let t3 = String::from_utf8(parts.get("xl/pivotTables/pivotTable3.xml").unwrap().clone()).unwrap();
assert!(t3.contains("firstHeaderRow=\"0\""), "{t3}");
assert!(t3.contains("<x14:pivotTableDefinition hideValuesRow=\"1\"/>"), "{t3}");
}
/// A one-sheet-of-data workbook with a pivot on "Report": `columns` are the source columns