qax-os/excelize · error
ErrSparklineRange
ErrSparklineRange
Error message
parameter 'Range' is required
What it means
Sentinel error ErrSparklineRange returned by AddSparkline when SparklineOptions.Range is empty; the guard `len(opts.Range) < 1` fires after Location is validated and before range/location count matching, i.e. no source data ranges were given.
Source
Thrown at errors.go:164
ErrSheetNameBlank = errors.New("the sheet name can not be blank")
// ErrSheetNameInvalid defined the error message on receive the sheet name
// contains invalid characters.
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")View on GitHub (pinned to f2483381fb)
Solutions
- Set opts.Range to at least one range reference (e.g. []string{"Sheet2!A3:E3"}) before calling AddSparkline
- Validate len(opts.Range) >= 1 before the call
- Ensure Range and Location are always supplied as a pair
Example fix
// before
f.AddSparkline("Sheet1", &SparklineOptions{Location: []string{"F3"}})
// after
f.AddSparkline("Sheet1", &SparklineOptions{Location: []string{"F3"}, Range: []string{"Sheet2!A3:E3"}}) Defensive patterns
Strategy: validation
Validate before calling
if len(opts.Range) < 1 {
return errors.New("SparklineOptions.Range is required")
} Type guard
func sparklineOptsValid(o *excelize.SparklineOptions) bool {
return len(o.Location) > 0 && len(o.Location) == len(o.Range)
} Try / catch
if err := f.AddSparkline("Sheet1", opts); err != nil {
if errors.Is(err, excelize.ErrSparklineRange) {
// supply a data range before retrying
}
return err
} Prevention
- Always set Range together with Location in SparklineOptions literals
- When options come from config/JSON, default an empty Range to the adjacent data block
- Cover required-field cases in unit tests
When it happens
Trigger: Calling f.AddSparkline("Sheet1", &SparklineOptions{Location: []string{"F3"}}) with no Range set, via parseFormatAddSparklineSet.
Common situations: Setting only the display cell and forgetting the data source; building options from user config where the Range key was omitted or empty.
Related errors
- ErrSparkline
- ErrSparklineLocation
- ErrSparklineStyle
- ErrSparklineType
- 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/9169c44a06a89a16.
Report an issue: GitHub.