qax-os/excelize · error

ErrSheetNameSingleQuote

ErrSheetNameSingleQuote

Error message

the first or last character of the sheet name can not be a single quote

What it means

ErrSheetNameSingleQuote is returned when a worksheet name starts or ends with a single quote ('). checkSheetName (sheet.go:1520) rejects this because Excel reserves surrounding single quotes for quoting sheet names in formulas and references.

Source

Thrown at errors.go:155

	// 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")
	// 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")

View on GitHub (pinned to f2483381fb)

Solutions

  1. Trim leading/trailing single quotes with strings.Trim(name, "'") before use
  2. Do not pre-quote sheet names; the library quotes them itself when writing formulas
  3. Validate with strings.HasPrefix(name, "'") || strings.HasSuffix(name, "'") before calling the API

Example fix

// before
idx, err := f.NewSheet("'My Sheet'")
// after
idx, err := f.NewSheet(strings.Trim(rawName, "'"))
Defensive patterns

Strategy: validation

Validate before calling

if strings.HasPrefix(name, "'") || strings.HasSuffix(name, "'") {
    return errors.New("sheet name must not start or end with a single quote")
}

Type guard

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

Try / catch

if err := check; errors.Is(err, excelize.ErrSheetNameSingleQuote) {
    name = strings.Trim(name, "'")
    // retry with trimmed name
}

Prevention

When it happens

Trigger: Calling any sheet-creating or sheet-naming API (NewSheet, SetSheetName, etc.) with names like "'Sheet" or "Sheet'"; passing such names through checkSheetName via validation helpers.

Common situations: Programmatically quoting sheet names for formulas and accidentally including the quotes in the stored name; copying names from formula strings like 'My Sheet'!A1.

Related errors


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