qax-os/excelize · error

ErrSparklineLocation

ErrSparklineLocation

Error message

parameter 'Location' is required

What it means

Sentinel error ErrSparklineLocation returned by AddSparkline when the SparklineOptions.Location parameter is empty or omitted. It fires as a validation guard before any worksheet modification: a sparkline must have at least one cell location to anchor it, so callers adding a sparkline without setting Location get this error and the workbook is left unchanged.

Source

Thrown at errors.go:161

	ErrSheetIdx = errors.New("invalid worksheet index")
	// ErrSheetNameBlank defined the error message on receive the blank sheet
	// name.
	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")

View on GitHub (pinned to f2483381fb)

Solutions

  1. Set opts.Location to at least one cell reference (e.g. []string{"F3"}) before calling AddSparkline
  2. Validate len(opts.Location) >= 1 in your options builder
  3. Provide both Location and Range together when constructing options

Example fix

// before
f.AddSparkline("Sheet1", &SparklineOptions{Range: []string{"Sheet2!A3:E3"}})
// after
f.AddSparkline("Sheet1", &SparklineOptions{Location: []string{"F3"}, Range: []string{"Sheet2!A3:E3"}})
Defensive patterns

Strategy: validation

Validate before calling

if len(opts.Location) < 1 {
    return errors.New("SparklineOptions.Location 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.ErrSparklineLocation) {
        // add a Location before retrying
    }
    return err
}

Prevention

When it happens

Trigger: Calling f.AddSparkline("Sheet1", &SparklineOptions{Range: []string{"Sheet2!A3:E3"}}) with no Location field set, via parseFormatAddSparklineSet.

Common situations: Constructing SparklineOptions dynamically and forgetting Location; copying a struct literal from a Range-only example; unmarshaling options from JSON where the field is missing.

Related errors


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