qax-os/excelize · error

fill color value must be empty or an array of one color for

Error message

fill color value must be empty or an array of one color for 'pattern' type

What it means

ErrFillPatternColor is returned by parseFormatStyleSet when Fill.Type is "pattern" and Fill.Color contains more than one color string. Pattern fills accept either no color (empty slice) or exactly one foreground color.

Source

Thrown at errors.go:74

	// 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
	// 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.

View on GitHub (pinned to f2483381fb)

Solutions

  1. Trim Fill.Color to at most one entry for pattern fills.
  2. If you need two colors, keep Fill.Type as "gradient" instead of "pattern".
  3. Validate len(style.Fill.Color) <= 1 before calling NewStyle.

Example fix

// before
f.NewStyle(&Style{Fill: Fill{Type: "pattern", Color: []string{"FFFFFF", "4E71BE"}}})
// after
f.NewStyle(&Style{Fill: Fill{Type: "pattern", Color: []string{"FFFF00"}, Pattern: 1}})
Defensive patterns

Strategy: validation

Validate before calling

if fill.Type == "pattern" && len(fill.Color) > 1 {
    return errors.New("pattern fill accepts at most one color")
}

Type guard

func hasAtMostOneColor(c []string) bool { return len(c) <= 1 }

Try / catch

_, err := f.NewStyle(&Style{Fill: fill})
if errors.Is(err, excelize.ErrFillPatternColor) {
    fill.Color = fill.Color[:1] // keep first color only
    _, err = f.NewStyle(&Style{Fill: fill})
}

Prevention

When it happens

Trigger: Calling f.NewStyle(&Style{Fill: Fill{Type: "pattern", Color: []string{"FFFFFF", "4E71BE"}}}) with two or more colors.

Common situations: Reusing the same two-element Color slice built for a gradient fill when switching the fill type to "pattern", or merging multiple configured colors into one slice.

Related errors


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