qax-os/excelize · error

ErrSparklineStyle

ErrSparklineStyle

Error message

parameter 'Style' value must be an integer from 0 to 35

What it means

Sentinel error ErrSparklineStyle returned by AddSparkline when the SparklineOptions.Style parameter falls outside the supported range 0-35. It fires as a validation guard (opts.Style < 0 || 35 < opts.Style) before the sparkline is written to the worksheet, so an out-of-range style choice is rejected and the workbook is left unchanged.

Source

Thrown at errors.go:167

	ErrSheetNameInvalid = errors.New("the sheet can not contain any of the characters :\\/?*[or]")
	// ErrSheetNameLength defined the error message on receiving the sheet
	// name length exceeds the limit.
	ErrSheetNameLength = fmt.Errorf("the sheet name length exceeds the %d characters limit", MaxSheetNameLength)
	// ErrSheetNameSingleQuote defined the error message on the first or last
	// character of the sheet name was a single quote.
	ErrSheetNameSingleQuote = errors.New("the first or last character of the sheet name can not be a single quote")
	// ErrSparkline defined the error message on receive the invalid sparkline
	// parameters.
	ErrSparkline = errors.New("must have the same number of 'Location' and 'Range' parameters")
	// ErrSparklineLocation defined the error message on missing Location
	// parameters
	ErrSparklineLocation = errors.New("parameter 'Location' is required")
	// ErrSparklineRange defined the error message on missing sparkline Range
	// parameters
	ErrSparklineRange = errors.New("parameter 'Range' is required")
	// ErrSparklineStyle defined the error message on receive the invalid
	// sparkline Style parameters.
	ErrSparklineStyle = errors.New("parameter 'Style' value must be an integer from 0 to 35")
	// ErrSparklineType defined the error message on receive the invalid
	// sparkline Type parameters.
	ErrSparklineType = errors.New("parameter 'Type' value must be one of 'line', 'column' or 'win_loss'")
	// ErrTotalSheetHyperlinks defined the error message on hyperlinks count
	// overflow.
	ErrTotalSheetHyperlinks = errors.New("over maximum limit hyperlinks in a worksheet")
	// ErrTransparency defined the error message for receiving a transparency
	// value exceeds limit.
	ErrTransparency = errors.New("transparency value must be an integer from 0 to 100")
	// ErrUnknownEncryptMechanism defined the error message on unsupported
	// encryption mechanism.
	ErrUnknownEncryptMechanism = errors.New("unknown encryption mechanism")
	// ErrUnprotectSheet defined the error message on worksheet has set no
	// protection.
	ErrUnprotectSheet = errors.New("worksheet has set no protect")
	// ErrUnprotectSheetPassword defined the error message on remove sheet
	// protection with password verification failed.
	ErrUnprotectSheetPassword = errors.New("worksheet protect password not match")

View on GitHub (pinned to f2483381fb)

Solutions

  1. Clamp Style into [0,35] before calling AddSparkline (e.g. opts.Style = 0 if unset)
  2. If migrating from a 1-based scheme, subtract 1 from the displayed style number
  3. Leave Style at 0 (the zero value) to use the default style

Example fix

// before
opts.Style = 36
f.AddSparkline("Sheet1", opts)
// after
if opts.Style < 0 || opts.Style > 35 {
    opts.Style = 0
}
f.AddSparkline("Sheet1", opts)
Defensive patterns

Strategy: validation

Validate before calling

if opts.Style < 0 || opts.Style > 35 {
    opts.Style = 0
}

Type guard

func sparklineStyleValid(s int) bool {
    return s >= 0 && s <= 35
}

Try / catch

if err := f.AddSparkline("Sheet1", opts); err != nil {
    if errors.Is(err, excelize.ErrSparklineStyle) {
        opts.Style = 0 // fall back to default style
        err = f.AddSparkline("Sheet1", opts)
    }
    return err
}

Prevention

When it happens

Trigger: Calling f.AddSparkline("Sheet1", &SparklineOptions{Location: ["F3"], Range: ["Sheet2!A3:E3"], Style: 36}) or Style < 0, via parseFormatAddSparklineSet.

Common situations: Hard-coding a style number taken from a 1-based UI list (Excel shows 1-36, the API expects 0-35); computing style from user input without clamping.

Related errors


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