iOfficeAI/OfficeCLI · error · ArgumentException
invalid {key}: '{value}'. Valid: true, false
Error message
invalid {key}: '{value}'. Valid: true, false What it means
ArgumentException thrown by ParsePivotStyleBool when a pivot-table style boolean key (showRowStripes, showColumnStripes, showRowHeaders, showColumnHeaders, showLastColumn) receives a value that is not one of the accepted spellings. Accepted (case-insensitive): true/1/yes/on and false/0/no/off. Anything else is rejected to avoid silent fallbacks masking typos (CONSISTENCY strict-enums).
Source
Thrown at src/officecli/Core/PivotTableHelper.Definition.cs:87
}
return pivotDef.PivotTableStyle;
}
/// <summary>
/// Strict bool parser for pivot style toggles. Accepts true/false/1/0/
/// yes/no/on/off (case-insensitive) and throws ArgumentException on
/// anything else. CONSISTENCY(strict-enums): matches the sort-mode and
/// showdataas reject-unknown behavior introduced in the recent pivot
/// validation sweep — silent fallbacks mask typos.
/// </summary>
private static bool ParsePivotStyleBool(string key, string value)
{
switch ((value ?? "").Trim().ToLowerInvariant())
{
case "true": case "1": case "yes": case "on": return true;
case "false": case "0": case "no": case "off": return false;
default:
throw new ArgumentException(
$"invalid {key}: '{value}'. Valid: true, false");
}
}
/// <summary>
/// Apply the five <pivotTableStyleInfo> bool attributes from the
/// caller's properties dict onto an existing PivotTableStyle element.
/// Only keys actually present in the dict are applied, so Set
/// operations can change one toggle without clobbering the others.
/// Accepts both canonical (showColStripes) and OOXML-verbatim
/// (showColumnStripes) spellings for the "col/column" siblings,
/// matching the existing alias policy.
/// </summary>
private static void ApplyPivotStyleInfoProps(
PivotTableStyle styleInfo,
Dictionary<string, string> properties)
{
foreach (var (rawKey, value) in properties)View on GitHub (pinned to 1ced45e900)
Solutions
- Use one of the accepted spellings: true/false, 1/0, yes/no, or on/off.
- For the column variants both spellings are accepted as keys (showColStripes or showColumnStripes), but the VALUE must still be one of the accepted bool spellings.
- Normalize upstream boolean input to true/false before setting the pivot style property.
Example fix
// before showRowStripes="yep" // after showRowStripes="true"
Defensive patterns
Strategy: validation
Validate before calling
static readonly System.Collections.Generic.HashSet<string> PivotBoolWords =
new(System.StringComparer.OrdinalIgnoreCase) { "true","1","yes","on","false","0","no","off" };
static bool IsPivotStyleBool(string value) => PivotBoolWords.Contains((value ?? "").Trim()); Prevention
- Use only true/false, 1/0, yes/no, or on/off for pivot style toggles.
- Normalize upstream booleans to true/false before setting.
- Reject abbreviations like 't'/'y' before they reach the parser.
When it happens
Trigger: Setting a pivot table styleInfo toggle with an unrecognized value, e.g. showRowStripes="yep", showColStripes="enable", showLastColumn="t", or showColumnStripes="".
Common situations: Using abbreviations ('t'/'f', 'y'/'n'); passing 'enable'/'disable' or 'checked'/'unchecked'; empty value from an unset JSON key; locale-specific words.
Related errors
- Invalid source range: {sourceRef}
- Column {startCol} out of range (max: XFD)
- Column {endCol} out of range (max: XFD)
- Invalid color value: '{value}'. Expected 6-digit hex RGB (e.
- Worksheet missing
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/f45caf3fb77f46d1.
Report an issue: GitHub.