{"record":{"id":"acba465fada2e377","repo":"qax-os/excelize","slug":"the-sheet-name-length-exceeds-the-d-characters-li","errorCode":null,"errorMessage":"the sheet name length exceeds the %d characters limit","messagePattern":"the sheet name length exceeds the (.+?) characters limit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":152,"sourceCode":"\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\")\n\t// ErrSparklineType defined the error message on receive the invalid\n\t// sparkline Type parameters.\n\tErrSparklineType = errors.New(\"parameter 'Type' value must be one of 'line', 'column' or 'win_loss'\")","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L134-L170","documentation":"ErrSheetNameLength is returned by checkSheetName when a worksheet name exceeds MaxSheetNameLength (31) characters, matching Excel's hard limit on sheet titles. NewSheet and SetSheetName run the name through this validation and fail fast instead of producing a workbook Excel would refuse to open.","triggerScenarios":"f.NewSheet(strings.Repeat(\"x\", 32)) or f.SetSheetName(old, newName) where the new name is longer than 31 characters (the test uses ':\\\\/?*[]Maximum 31 characters allowed in sheet title.').","commonSituations":"Deriving sheet names from report titles, file names, or user-entered project names without truncation; date+label concatenations that push past 31 chars.","solutions":["Truncate the sheet name to 31 characters before calling NewSheet/SetSheetName","Also sanitize invalid characters (: \\/ ? * [ ]) in the same helper since those raise ErrSheetNameInvalid","Keep a short name plus put the long title in cell A1 of the sheet instead"],"exampleFix":"// before\nname := longReportTitle // e.g. 60 chars\n_, err := f.NewSheet(name)\n// after\nif len([]rune(name)) > 31 {\n\tname = name[:31]\n}\n_, err := f.NewSheet(name)","handlingStrategy":"validation","validationCode":"func safeSheetName(s string) string {\n\tif len([]rune(s)) > 31 { s = s[:31] }\n\treturn strings.Trim(s, \"'\")\n}","typeGuard":"func okSheetName(s string) bool { return len([]rune(s)) <= 31 && !strings.ContainsAny(s, \":\\\\/?*[]'\") }","tryCatchPattern":null,"preventionTips":["Always route sheet names through a 31-char truncation helper","Also strip illegal characters : \\/ ? * [ ] and leading/trailing quotes","Put long descriptive titles in cell A1 instead of the sheet name"],"tags":["excelize","sheet-name","length-limit","worksheet"],"backgroundTag":"sheet-name-limit-exceeded","analyzedSha":"f2483381fbfbe432a6baa98d48a1c277183f3285","analyzedAt":"2026-09-02T01:26:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}