qax-os/excelize · error

ErrSheetNameInvalid

ErrSheetNameInvalid

Error message

the sheet can not contain any of the characters :\/?*[or]

What it means

ErrSheetNameInvalid is returned when a sheet name contains characters forbidden by Excel: : \ / ? * [ ]. checkSheetName (sheet.go:1522) rejects these because Excel cannot store them in a worksheet name and references like Sheet1!A1 would become ambiguous.

Source

Thrown at errors.go:149

	// this kind of "show values as" type requires a base field.
	ErrPivotTableShowValuesAsBaseField = errors.New("this kind of show values as type requires a base field")
	// ErrPivotTableShowValuesAsBaseItem defined the error message on enable
	// this kind of "show values as" type and base field requires a base item.
	ErrPivotTableShowValuesAsBaseItem = errors.New("this kind of show values as type and base field requires a base item")
	// ErrPivotTableClassicLayout defined the error message on enable
	// ClassicLayout and CompactData in the same time.
	ErrPivotTableClassicLayout = errors.New("cannot enable ClassicLayout and CompactData in the same time")
	// ErrSave defined the error message for saving file.
	ErrSave = errors.New("no path defined for file, consider File.WriteTo or File.Write")
	// ErrSheetIdx defined the error message on receive the invalid worksheet
	// index.
	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")

View on GitHub (pinned to f2483381fb)

Solutions

  1. Strip or replace the invalid characters :\/?*[] from the sheet name before calling the API
  2. Validate with strings.ContainsAny(name, ":\\/?*[]") and reject or sanitize early
  3. Fix the test/setup data that passes a name like "Sheet:1"

Example fix

// before
_, err := f.CalcCellValue("Sheet:1", "A1")
// after
name := strings.ReplaceAll(rawName, ":", "-")
_, err := f.CalcCellValue(name, "A1")
Defensive patterns

Strategy: validation

Validate before calling

if strings.ContainsAny(name, ":\\/?*[]") {
    return fmt.Errorf("sheet name %q contains invalid characters", name)
}

Type guard

func validSheetName(name string) bool {
    return name != "" && !strings.ContainsAny(name, ":\\/?*[]") &&
        !strings.HasPrefix(name, "'") && !strings.HasSuffix(name, "'")
}

Try / catch

if _, err := f.GetCellValue(name, "A1"); err != nil {
    if errors.Is(err, excelize.ErrSheetNameInvalid) {
        name = sanitizeSheetName(name)
    }
    return err
}

Prevention

When it happens

Trigger: Calling CalcCellValue("Sheet:1", "A1"), SetCellFloat("Sheet:1", ...), SetCellValue, SetCellBool, GetCellValue, GetCellType or any API that resolves a sheet by a name containing :\/?*[].

Common situations: Deriving sheet names from file paths, dates, or user input that includes ':' or '/'; using timestamps like '2026-09-01:report' as sheet names; not sanitizing names on cross-platform code.

Related errors


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