qax-os/excelize · error

the same name table already exists

Error message

the same name table already exists

What it means

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.

Source

Thrown at errors.go:63

	// number format.
	ErrCustomNumFmt = errors.New("custom number format can not be empty")
	// ErrDataValidationFormulaLength defined the error message for receiving a
	// data validation formula length that exceeds the limit.
	ErrDataValidationFormulaLength = fmt.Errorf("data validation must be 0-%d characters", MaxFieldLength)
	// ErrDataValidationRange defined the error message on set decimal range
	// exceeds limit.
	ErrDataValidationRange = errors.New("data validation range exceeds limit")
	// ErrDefinedNameDuplicate defined the error message on the same name
	// already exists on the scope.
	ErrDefinedNameDuplicate = errors.New("the same name already exists on the scope")
	// ErrDefinedNameScope defined the error message on not found defined name
	// in the given scope.
	ErrDefinedNameScope = errors.New("no defined name on the scope")
	// ErrExistsSheet defined the error message on given sheet already exists.
	ErrExistsSheet = errors.New("the same name sheet already exists")
	// ErrExistsTableName defined the error message on given table already
	// exists.
	ErrExistsTableName = errors.New("the same name table already exists")
	// ErrFillType defined the error message on receive an invalid fill type.
	ErrFillType = errors.New("fill type value must be one of 'gradient' or 'pattern'")
	// ErrFillGradientColor defined the error message on receive an invalid fill
	// color for 'gradient' type.
	ErrFillGradientColor = errors.New("fill color value must be an array of two colors for 'gradient' type")
	// ErrFillGradientShading defined the error message on receive an invalid
	// fill shading for 'gradient' type.
	ErrFillGradientShading = errors.New("fill shading value must be between 0 and 16 for 'gradient' type")
	// ErrFillPatternColor defined the error message on receive an invalid fill
	// color for 'pattern' type.
	ErrFillPatternColor = errors.New("fill color value must be empty or an array of one color for 'pattern' type")
	// ErrFillPattern defined the error message on receive an invalid fill
	// pattern.
	ErrFillPattern = errors.New("fill pattern value must be between 0 and 18")
	// ErrFontLength defined the error message on the length of the font
	// family name overflow.
	ErrFontLength = fmt.Errorf("the length of the font family name must be less than or equal to %d", MaxFontFamilyLength)
	// ErrFontSize defined the error message on the size of the font is invalid.

View on GitHub (pinned to f2483381fb)

Solutions

  1. Use unique table names, e.g. fmt.Sprintf("Table%d", i) or include sheet/range in the name.
  2. Let Excelize auto-name the table by leaving Table.Name empty.
  3. Check f.GetTables(sheet) for existing names before adding, and delete or rename accordingly.

Example fix

// before
f.AddTable("Sheet2", &Table{Name: "Table1"})
f.AddTable("Sheet2", &Table{Name: "Table1"}) // ErrExistsTableName
// after
f.AddTable("Sheet2", &Table{Name: "Table1"})
f.AddTable("Sheet2", &Table{Name: "Table2", Range: "D1:E10"})
Defensive patterns

Strategy: validation

Validate before calling

tables, _ := f.GetTables("Sheet2")
used := map[string]bool{}
for _, t := range tables { used[t.Name] = true }
name := "Table1"
for used[name] { name = nextName(name) }
f.AddTable("Sheet2", &excelize.Table{Range: "A1:B10", Name: name})

Try / catch

err := f.AddTable("Sheet2", tbl)
if errors.Is(err, excelize.ErrExistsTableName) {
	tbl.Name = fmt.Sprintf("%s_%d", tbl.Name, time.Now().UnixNano())
	err = f.AddTable("Sheet2", tbl)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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