{"record":{"id":"899c868d4fa055de","repo":"qax-os/excelize","slug":"errsheetnameinvalid","errorCode":"ErrSheetNameInvalid","errorMessage":"the sheet can not contain any of the characters :\\/?*[or]","messagePattern":"the sheet can not contain any of the characters :\\\\/\\?\\*\\[or\\]","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":149,"sourceCode":"\t// this kind of \"show values as\" type requires a base field.\n\tErrPivotTableShowValuesAsBaseField = errors.New(\"this kind of show values as type requires a base field\")\n\t// ErrPivotTableShowValuesAsBaseItem defined the error message on enable\n\t// this kind of \"show values as\" type and base field requires a base item.\n\tErrPivotTableShowValuesAsBaseItem = errors.New(\"this kind of show values as type and base field requires a base item\")\n\t// ErrPivotTableClassicLayout defined the error message on enable\n\t// ClassicLayout and CompactData in the same time.\n\tErrPivotTableClassicLayout = errors.New(\"cannot enable ClassicLayout and CompactData in the same time\")\n\t// ErrSave defined the error message for saving file.\n\tErrSave = errors.New(\"no path defined for file, consider File.WriteTo or File.Write\")\n\t// ErrSheetIdx defined the error message on receive the invalid worksheet\n\t// index.\n\tErrSheetIdx = errors.New(\"invalid worksheet index\")\n\t// ErrSheetNameBlank defined the error message on receive the blank sheet\n\t// name.\n\tErrSheetNameBlank = errors.New(\"the sheet name can not be blank\")\n\t// ErrSheetNameInvalid defined the error message on receive the sheet name\n\t// contains invalid characters.\n\tErrSheetNameInvalid = errors.New(\"the sheet can not contain any of the characters :\\\\/?*[or]\")\n\t// ErrSheetNameLength defined the error message on receiving the sheet\n\t// name length exceeds the limit.\n\tErrSheetNameLength = fmt.Errorf(\"the sheet name length exceeds the %d characters limit\", MaxSheetNameLength)\n\t// ErrSheetNameSingleQuote defined the error message on the first or last\n\t// character of the sheet name was a single quote.\n\tErrSheetNameSingleQuote = errors.New(\"the first or last character of the sheet name can not be a single quote\")\n\t// ErrSparkline defined the error message on receive the invalid sparkline\n\t// parameters.\n\tErrSparkline = errors.New(\"must have the same number of 'Location' and 'Range' parameters\")\n\t// ErrSparklineLocation defined the error message on missing Location\n\t// parameters\n\tErrSparklineLocation = errors.New(\"parameter 'Location' is required\")\n\t// ErrSparklineRange defined the error message on missing sparkline Range\n\t// parameters\n\tErrSparklineRange = errors.New(\"parameter 'Range' is required\")\n\t// ErrSparklineStyle defined the error message on receive the invalid\n\t// sparkline Style parameters.\n\tErrSparklineStyle = errors.New(\"parameter 'Style' value must be an integer from 0 to 35\")","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L131-L167","documentation":"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.","triggerScenarios":"Calling CalcCellValue(\"Sheet:1\", \"A1\"), SetCellFloat(\"Sheet:1\", ...), SetCellValue, SetCellBool, GetCellValue, GetCellType or any API that resolves a sheet by a name containing :\\/?*[].","commonSituations":"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.","solutions":["Strip or replace the invalid characters :\\/?*[] from the sheet name before calling the API","Validate with strings.ContainsAny(name, \":\\\\/?*[]\") and reject or sanitize early","Fix the test/setup data that passes a name like \"Sheet:1\""],"exampleFix":"// before\n_, err := f.CalcCellValue(\"Sheet:1\", \"A1\")\n// after\nname := strings.ReplaceAll(rawName, \":\", \"-\")\n_, err := f.CalcCellValue(name, \"A1\")","handlingStrategy":"validation","validationCode":"if strings.ContainsAny(name, \":\\\\/?*[]\") {\n    return fmt.Errorf(\"sheet name %q contains invalid characters\", name)\n}","typeGuard":"func validSheetName(name string) bool {\n    return name != \"\" && !strings.ContainsAny(name, \":\\\\/?*[]\") &&\n        !strings.HasPrefix(name, \"'\") && !strings.HasSuffix(name, \"'\")\n}","tryCatchPattern":"if _, err := f.GetCellValue(name, \"A1\"); err != nil {\n    if errors.Is(err, excelize.ErrSheetNameInvalid) {\n        name = sanitizeSheetName(name)\n    }\n    return err\n}","preventionTips":["Sanitize sheet names derived from file paths, URLs, or timestamps","Centralize a sanitizeSheetName helper used by all sheet creation","Avoid ':' and '/' which commonly slip in from dates and paths"],"tags":["go","excelize","sheet-name","validation"],"backgroundTag":"invalid-sheet-name-characters","analyzedSha":"f2483381fbfbe432a6baa98d48a1c277183f3285","analyzedAt":"2026-09-02T01:26:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}