qax-os/excelize · error
fill pattern value must be between 0 and 18
Error message
fill pattern value must be between 0 and 18
What it means
ErrFillPattern is returned by parseFormatStyleSet when Fill.Type is "pattern" and Fill.Pattern is outside the inclusive range 0-18. The pattern value selects which OOXML pattern style (solid, dots, stripes, etc.) to apply.
Source
Thrown at errors.go:77
// ErrExistsSheet defined the error message on given sheet already exists.
ErrExistsSheet = errors.New("the same name sheet already exists")
// ErrExistsTableName defined the error message on given table already
// exists.
ErrExistsTableName = errors.New("the same name table already exists")
// ErrFillType defined the error message on receive an invalid fill type.
ErrFillType = errors.New("fill type value must be one of 'gradient' or 'pattern'")
// ErrFillGradientColor defined the error message on receive an invalid fill
// color for 'gradient' type.
ErrFillGradientColor = errors.New("fill color value must be an array of two colors for 'gradient' type")
// ErrFillGradientShading defined the error message on receive an invalid
// fill shading for 'gradient' type.
ErrFillGradientShading = errors.New("fill shading value must be between 0 and 16 for 'gradient' type")
// ErrFillPatternColor defined the error message on receive an invalid fill
// color for 'pattern' type.
ErrFillPatternColor = errors.New("fill color value must be empty or an array of one color for 'pattern' type")
// ErrFillPattern defined the error message on receive an invalid fill
// pattern.
ErrFillPattern = errors.New("fill pattern value must be between 0 and 18")
// ErrFontLength defined the error message on the length of the font
// family name overflow.
ErrFontLength = fmt.Errorf("the length of the font family name must be less than or equal to %d", MaxFontFamilyLength)
// ErrFontSize defined the error message on the size of the font is invalid.
ErrFontSize = fmt.Errorf("font size must be an integer from %d to %d points", MinFontSize, MaxFontSize)
// ErrFormControlValue defined the error message for receiving a scroll
// value exceeds limit.
ErrFormControlValue = fmt.Errorf("scroll value must be an integer from 0 to %d", MaxFormControlValue)
// ErrGroupSheets defined the error message on group sheets.
ErrGroupSheets = errors.New("group worksheet must contain an active worksheet")
// ErrImgExt defined the error message on receive an unsupported image
// extension.
ErrImgExt = errors.New("unsupported image extension")
// ErrInvalidFormula defined the error message on receive an invalid
// formula.
ErrInvalidFormula = errors.New("formula not valid")
// ErrMaxFilePathLength defined the error message on receive the file path
// length overflow.View on GitHub (pinned to f2483381fb)
Solutions
- Set Fill.Pattern to an integer between 0 and 18 inclusive (1 is the solid pattern).
- Clamp the value to [0, 18] before calling NewStyle.
- Map your pattern names to this library's 0-18 numbering explicitly.
Example fix
// before
f.NewStyle(&Style{Fill: Fill{Type: "pattern", Pattern: 19}})
// after
f.NewStyle(&Style{Fill: Fill{Type: "pattern", Pattern: 1}}) // 1 = solid Defensive patterns
Strategy: validation
Validate before calling
if fill.Type == "pattern" && (fill.Pattern < 0 || fill.Pattern > 18) {
return fmt.Errorf("pattern %d out of range 0-18", fill.Pattern)
} Type guard
func validPattern(p int) bool { return p >= 0 && p <= 18 } Try / catch
_, err := f.NewStyle(&Style{Fill: fill})
if errors.Is(err, excelize.ErrFillPattern) {
fill.Pattern = 1 // default to solid
_, err = f.NewStyle(&Style{Fill: fill})
} Prevention
- Define named Go constants for pattern values 0-18.
- Clamp pattern values derived from user input.
- Test boundary values 0, 18, and 19 in unit tests.
When it happens
Trigger: Calling f.NewStyle(&Style{Fill: Fill{Type: "pattern", Pattern: 19}}) or passing a negative Pattern value.
Common situations: Using pattern constants from another library or a newer OOXML spec revision, computing pattern from user input, or off-by-one errors against the 0-18 valid range.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- fill color value must be empty or an array of one color for
- fill type value must be one of 'gradient' or 'pattern'
- fill color value must be an array of two colors for 'gradien
- fill shading value must be between 0 and 16 for 'gradient' t
- group worksheet must contain an active worksheet
AI-assisted analysis of qax-os/excelize@f2483381fb (2026-09-02).
Data as JSON: /api/errors/434da3b10e1baa48.
Report an issue: GitHub.