iOfficeAI/OfficeCLI · error · ArgumentException
Invalid color value: '{value}'. Expected 6-digit hex RGB (e.
Error message
Invalid color value: '{value}'. Expected 6-digit hex RGB (e.g. FF0000), 8-digit AARRGGBB (e.g. 80FF0000), 3-digit shorthand (e.g. F00) or 4-digit #RGBA shorthand (e.g. F00A), named color (e.g. red), rgb()/rgba()/hsl()/hsla() notation, or 'transparent'.{schemeHint} What it means
Thrown by ParseHelpers.SanitizeColorForOoxml when, after trying named/rgb/hsl/transparent, #RRGGBBAA, AARRGGBB, 3- and 4- shorthand and 'auto', the remaining hex is not exactly 6 hex digits. The function returns (rgb6, alphaPercent) for srgbClr val. If the input is a recognized scheme color name, the message is extended with a schemeHint telling you to set it on a theme-color-aware property instead.
Source
Thrown at src/officecli/Core/ParseHelpers.cs:772
hex[0], hex[0], hex[1], hex[1], hex[2], hex[2], hex[3], hex[3],
});
var rgb = expanded[..6];
var alphaByte = Convert.ToByte(expanded.Substring(6, 2), 16);
if (alphaByte == 0xFF)
return (rgb, null);
return (rgb, (int)(alphaByte / 255.0 * 100000));
}
if (hex.Length != 6 || !hex.All(char.IsAsciiHexDigit))
{
// Scheme colors (accent1, dark2, hyperlink, …) are not handled
// here — callers that support theme colors must check
// IsSchemeColorName first and route to ThemeColor. Surface a
// hint instead of advertising support we don't provide.
var schemeHint = IsSchemeColorName(trimmedInput)
? " (scheme color names like 'accent1' must be set on properties that accept theme colors)"
: "";
throw new ArgumentException(
$"Invalid color value: '{value}'. Expected 6-digit hex RGB (e.g. FF0000), " +
$"8-digit AARRGGBB (e.g. 80FF0000), 3-digit shorthand (e.g. F00) or 4-digit #RGBA shorthand (e.g. F00A), " +
$"named color (e.g. red), rgb()/rgba()/hsl()/hsla() notation, or 'transparent'." + schemeHint);
}
return (hex, null);
}
// ==================== CJK Text Width Estimation ====================
/// <summary>
/// Returns true if the character is CJK ideograph, fullwidth, or CJK punctuation.
/// These characters occupy approximately 1em width (≈ fontSize) vs ~0.55em for Latin.
/// </summary>
public static bool IsCjkOrFullWidth(char ch)
{
// CJK Unified Ideographs
if (ch >= 0x4E00 && ch <= 0x9FFF) return true;View on GitHub (pinned to 1ced45e900)
Solutions
- For a literal color use one of: 'FF0000', '#FF0000', '#FF0000AA' (CSS alpha-last with #), '80FF0000' (AARRGGBB without #), 'F00', 'red', 'rgb(255,0,0)', 'transparent', 'auto'.
- If the message carries the schemeHint, move that value to a property that accepts theme/scheme colors (the srgbClr path cannot store it).
- Mind the # convention: with '#' an 8-hex value is RRGGBBAA (alpha last); without '#' it is AARRGGBB (alpha first).
Example fix
// before color="accent1" // on a non-theme-aware property // after color="4472C4" // literal hex, or route accent1 to a theme-color property
Defensive patterns
Strategy: validation
Validate before calling
static bool IsAcceptableOoxmlColor(string value)
{
try { var _ = OfficeCli.Core.ParseHelpers.SanitizeColorForOoxml(value); return true; }
catch { return false; }
} Try / catch
try { var (rgb, alpha) = ParseHelpers.SanitizeColorForOoxml(value); }
catch (ArgumentException ex) { /* surface error, especially the schemeHint if present */ } Prevention
- Remember the # convention: with '#', 8-hex is RRGGBBAA; without '#', it is AARRGGBB.
- Use 6-hex RGB or named colors for opaque srgbClr values.
- If the schemeHint appears, move the value to a theme-color-aware property.
When it happens
Trigger: Calling any srgbClr-based color setter routed through SanitizeColorForOoxml (Word/PPT fill, line, theme, gradient stops, drawing effects, chart series colors, axis) with a value that isn't 6-hex RGB, 8-hex, 3-/4-shorthand, named, rgb()/hsl(), 'transparent', or 'auto'. A scheme name like 'accent1' triggers the appended schemeHint.
Common situations: Passing a scheme color ('accent1','dk1','hyperlink') to a property that emits srgbClr (no themeColor handling); passing a 5- or 7-digit hex; passing 'rgb(300,0,0)'; misspelled color name; passing an RGBA 8-hex WITHOUT the '#' when you meant CSS RRGGBBAA (bare 8-hex is treated as AARRGGBB).
Related errors
- Invalid color value: '{value}'. Expected 6-digit hex RGB (e.
- Invalid '{propertyName}' value '{value}': degrees must be in
- Invalid '{propertyName}' value '{value}'. Expected an intege
- Unknown chart preset '{value}'. Available: {string.Join(", "
- Invalid labelPos '{value}' for pie chart: ST_DLblPosPie allo
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/0a2b81e85e23c556.
Report an issue: GitHub.