{"record":{"id":"1bc64f44300eddcd","repo":"qax-os/excelize","slug":"the-same-name-table-already-exists","errorCode":null,"errorMessage":"the same name table already exists","messagePattern":"the same name table already exists","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":63,"sourceCode":"\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\n\t// family name overflow.\n\tErrFontLength = fmt.Errorf(\"the length of the font family name must be less than or equal to %d\", MaxFontFamilyLength)\n\t// ErrFontSize defined the error message on the size of the font is invalid.","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L45-L81","documentation":"ErrExistsTableName is returned by AddTable when a table with the same name already exists in the worksheet (table.go:100). Excel table (ListObject) names must be unique, so adding \"Table1\" twice is rejected before writing invalid XML.","triggerScenarios":"Calling f.AddTable(\"Sheet2\", &Table{Name: \"Table1\"}) when a table named \"Table1\" already exists anywhere in the workbook; also triggered by re-running code that adds tables with default/constant names.","commonSituations":"Looping over ranges and adding tables with hardcoded names; augmenting a template file that already contains tables; re-running data-import scripts against the same file.","solutions":["Use unique table names, e.g. fmt.Sprintf(\"Table%d\", i) or include sheet/range in the name.","Let Excelize auto-name the table by leaving Table.Name empty.","Check f.GetTables(sheet) for existing names before adding, and delete or rename accordingly."],"exampleFix":"// before\nf.AddTable(\"Sheet2\", &Table{Name: \"Table1\"})\nf.AddTable(\"Sheet2\", &Table{Name: \"Table1\"}) // ErrExistsTableName\n// after\nf.AddTable(\"Sheet2\", &Table{Name: \"Table1\"})\nf.AddTable(\"Sheet2\", &Table{Name: \"Table2\", Range: \"D1:E10\"})","handlingStrategy":"validation","validationCode":"tables, _ := f.GetTables(\"Sheet2\")\nused := map[string]bool{}\nfor _, t := range tables { used[t.Name] = true }\nname := \"Table1\"\nfor used[name] { name = nextName(name) }\nf.AddTable(\"Sheet2\", &excelize.Table{Range: \"A1:B10\", Name: name})","typeGuard":null,"tryCatchPattern":"err := f.AddTable(\"Sheet2\", tbl)\nif errors.Is(err, excelize.ErrExistsTableName) {\n\ttbl.Name = fmt.Sprintf(\"%s_%d\", tbl.Name, time.Now().UnixNano())\n\terr = f.AddTable(\"Sheet2\", tbl)\n}","preventionTips":["Leave Table.Name empty to let Excelize/Excel assign a unique default name","Derive table names from the range or an incrementing counter instead of constants","Inspect existing tables with GetTables before adding to template-based files"],"tags":["excelize","tables","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"}