{"record":{"id":"ad0ff11aa0a096cc","repo":"qax-os/excelize","slug":"the-same-name-sheet-already-exists","errorCode":null,"errorMessage":"the same name sheet already exists","messagePattern":"the same name sheet already exists","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":60,"sourceCode":"\t// length.\n\tErrCoordinates = errors.New(\"coordinates length must be 4\")\n\t// ErrCustomNumFmt defined the error message on receive the empty custom\n\t// number format.\n\tErrCustomNumFmt = errors.New(\"custom number format can not be empty\")\n\t// ErrDataValidationFormulaLength defined the error message for receiving a\n\t// data validation formula length that exceeds the limit.\n\tErrDataValidationFormulaLength = fmt.Errorf(\"data validation must be 0-%d characters\", MaxFieldLength)\n\t// ErrDataValidationRange defined the error message on set decimal range\n\t// exceeds limit.\n\tErrDataValidationRange = errors.New(\"data validation range exceeds limit\")\n\t// ErrDefinedNameDuplicate defined the error message on the same name\n\t// already exists on the scope.\n\tErrDefinedNameDuplicate = errors.New(\"the same name already exists on the scope\")\n\t// ErrDefinedNameScope defined the error message on not found defined name\n\t// in the given scope.\n\tErrDefinedNameScope = errors.New(\"no defined name on the scope\")\n\t// ErrExistsSheet defined the error message on given sheet already exists.\n\tErrExistsSheet = errors.New(\"the same name sheet already exists\")\n\t// ErrExistsTableName defined the error message on given table already\n\t// exists.\n\tErrExistsTableName = errors.New(\"the same name table already exists\")\n\t// ErrFillType defined the error message on receive an invalid fill type.\n\tErrFillType = errors.New(\"fill type value must be one of 'gradient' or 'pattern'\")\n\t// ErrFillGradientColor defined the error message on receive an invalid fill\n\t// color for 'gradient' type.\n\tErrFillGradientColor = errors.New(\"fill color value must be an array of two colors for 'gradient' type\")\n\t// ErrFillGradientShading defined the error message on receive an invalid\n\t// fill shading for 'gradient' type.\n\tErrFillGradientShading = errors.New(\"fill shading value must be between 0 and 16 for 'gradient' type\")\n\t// ErrFillPatternColor defined the error message on receive an invalid fill\n\t// color for 'pattern' type.\n\tErrFillPatternColor = errors.New(\"fill color value must be empty or an array of one color for 'pattern' type\")\n\t// ErrFillPattern defined the error message on receive an invalid fill\n\t// pattern.\n\tErrFillPattern = errors.New(\"fill pattern value must be between 0 and 18\")\n\t// ErrFontLength defined the error message on the length of the font","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L42-L78","documentation":"ErrExistsSheet is returned by AddChartSheet when a worksheet with the given name already exists in the workbook (chart.go:1301). Excel requires unique sheet names, so creating a chartsheet named e.g. \"Sheet1\" when a regular sheet of that name exists is rejected.","triggerScenarios":"Calling f.AddChartSheet(\"Sheet1\", chart) when \"Sheet1\" already exists (created via NewSheet, the default sheet, or a previous AddChartSheet).","commonSituations":"Adding chartsheets to files created from a template that already contains sheets; hardcoding \"Sheet1\" which always exists in new workbooks; re-running generation scripts.","solutions":["Choose a unique sheet name for the chartsheet, e.g. derive it with a suffix counter.","Check existence first with f.GetSheetIndex(name) and pick another name or delete the existing sheet.","If the old sheet should be replaced, call f.DeleteSheet before AddChartSheet."],"exampleFix":"// before\nf.AddChartSheet(\"Sheet1\", chart) // ErrExistsSheet\n// after\nname := \"Chart\"\nfor f.GetSheetIndex(name) != 0 {\n    name += \"_1\"\n}\nf.AddChartSheet(name, chart)","handlingStrategy":"validation","validationCode":"name := \"MyChart\"\nif f.GetSheetIndex(name) != 0 {\n\tname = fmt.Sprintf(\"%s_%d\", name, time.Now().UnixNano())\n}\nf.AddChartSheet(name, chart)","typeGuard":"func sheetExists(f *excelize.File, name string) bool {\n\treturn f.GetSheetIndex(name) != 0\n}","tryCatchPattern":"err := f.AddChartSheet(name, chart)\nif errors.Is(err, excelize.ErrExistsSheet) {\n\tname = name + \"_1\"\n\terr = f.AddChartSheet(name, chart)\n}","preventionTips":["Never hardcode \"Sheet1\" for new sheets/chartsheets in new workbooks","Generate unique sheet names with a counter or timestamp","Check GetSheetIndex before any NewSheet/AddChartSheet call"],"tags":["excelize","sheet-management","duplicate-name"],"backgroundTag":"duplicate-identifier","analyzedSha":"f2483381fbfbe432a6baa98d48a1c277183f3285","analyzedAt":"2026-09-02T01:26:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}