qax-os/excelize · error
ErrSparklineType
ErrSparklineType
Error message
parameter 'Type' value must be one of 'line', 'column' or 'win_loss'
What it means
ErrSparklineType is returned when SparklineOptions.Type is set to an unrecognized value (sparkline.go:412). Only "line", "column", and "win_loss" are valid; anything else cannot be mapped to a sparkline element name.
Source
Thrown at errors.go:170
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")
// ErrUnprotectWorkbook defined the error message on workbook has set no
// protection.
ErrUnprotectWorkbook = errors.New("workbook has set no protect")View on GitHub (pinned to f2483381fb)
Solutions
- Use exactly "line", "column" or "win_loss" for Type
- Leave Type as "" to get the default line sparkline
- Normalize/case-fold user input to one of the three valid values before the call
Example fix
// before
opts.Type = "bar"
f.AddSparkline("Sheet1", opts)
// after
opts.Type = "column" // one of: line, column, win_loss
f.AddSparkline("Sheet1", opts) Defensive patterns
Strategy: validation
Validate before calling
valid := map[string]bool{"line": true, "column": true, "win_loss": true}
if opts.Type != "" && !valid[opts.Type] {
return fmt.Errorf("invalid sparkline type %q", opts.Type)
} Type guard
func validSparklineType(t string) bool {
return t == "" || t == "line" || t == "column" || t == "win_loss"
} Try / catch
if err := f.AddSparkline("Sheet1", opts); err != nil {
if errors.Is(err, excelize.ErrSparklineType) {
opts.Type = "" // default to line
err = f.AddSparkline("Sheet1", opts)
}
return err
} Prevention
- Use the exact strings line/column/win_loss; define them as constants
- Leave Type empty for the default rather than guessing a name
- Normalize case/underscores from UI labels before assigning Type
When it happens
Trigger: Calling f.AddSparkline("Sheet1", &SparklineOptions{..., Type: "bar"}) or any Type string not in sparkTypes map, when Type != "" (empty means default/line).
Common situations: Typo variants like "Line" or "winloss"; guessing type names instead of using the documented constants; translating UI labels (e.g. 'bar') into the Type field.
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
- ErrSparkline
- ErrSparklineLocation
- ErrSparklineRange
- ErrSparklineStyle
- fill type value must be one of 'gradient' or 'pattern'
AI-assisted analysis of qax-os/excelize@f2483381fb (2026-09-02).
Data as JSON: /api/errors/58a4b06a1f2b8f6c.
Report an issue: GitHub.