qax-os/excelize · error

fill type value must be one of 'gradient' or 'pattern'

Error message

fill type value must be one of 'gradient' or 'pattern'

What it means

ErrFillType is returned by parseFormatStyleSet when Style.Fill.Type is not an accepted value. The library only supports the fill types 'gradient' and 'pattern'; any other non-empty string is rejected when creating a style via NewStyle. An empty type is allowed and defaults to no fill.

Source

Thrown at errors.go:65

	// ErrDataValidationFormulaLength defined the error message for receiving a
	// data validation formula length that exceeds the limit.
	ErrDataValidationFormulaLength = fmt.Errorf("data validation must be 0-%d characters", MaxFieldLength)
	// ErrDataValidationRange defined the error message on set decimal range
	// exceeds limit.
	ErrDataValidationRange = errors.New("data validation range exceeds limit")
	// ErrDefinedNameDuplicate defined the error message on the same name
	// already exists on the scope.
	ErrDefinedNameDuplicate = errors.New("the same name already exists on the scope")
	// ErrDefinedNameScope defined the error message on not found defined name
	// in the given scope.
	ErrDefinedNameScope = errors.New("no defined name on the scope")
	// 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

View on GitHub (pinned to f2483381fb)

Solutions

  1. Set Fill.Type to exactly "pattern" (case-sensitive lowercase) for solid/standard fills.
  2. Set Fill.Type to "gradient" for gradient fills.
  3. Leave Fill.Type as the empty string "" when no fill is desired.
  4. Remove a constant imported from another library (e.g. 'solid') that does not match this API.

Example fix

// before
style, err := f.NewStyle(&Style{Fill: Fill{Type: "solid", Color: []string{"FFFF00"}}})
// after
style, err := f.NewStyle(&Style{Fill: Fill{Type: "pattern", Pattern: 1, Color: []string{"FFFF00"}}})
Defensive patterns

Strategy: validation

Validate before calling

func validFillType(t string) bool { return t == "" || t == "gradient" || t == "pattern" }
if !validFillType(fill.Type) { return errors.New("Fill.Type must be \"gradient\", \"pattern\", or empty") }

Type guard

func isFillType(v string) bool { return v == "" || v == "gradient" || v == "pattern" }

Try / catch

if _, err := f.NewStyle(&Style{Fill: fill}); err != nil {
    if errors.Is(err, excelize.ErrFillType) {
        // fix or log the invalid fill type
    }
    return err
}

Prevention

When it happens

Trigger: Calling f.NewStyle(&Style{Fill: Fill{Type: "solid", ...}}) or any Fill.Type string other than "gradient", "pattern", or "".

Common situations: Copy-pasting fill type names from other spreadsheet libraries (e.g. 'solid', which is an OOXML pattern value, not a valid Type here), typos like 'Gradient' (case-sensitive), or hand-written style configs.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of qax-os/excelize@f2483381fb (2026-09-02). Data as JSON: /api/errors/178e7f0d965f37ca. Report an issue: GitHub.