qax-os/excelize · error

the same name sheet already exists

Error message

the same name sheet already exists

What it means

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.

Source

Thrown at errors.go:60

	// length.
	ErrCoordinates = errors.New("coordinates length must be 4")
	// ErrCustomNumFmt defined the error message on receive the empty custom
	// 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

View on GitHub (pinned to f2483381fb)

Solutions

  1. Choose a unique sheet name for the chartsheet, e.g. derive it with a suffix counter.
  2. Check existence first with f.GetSheetIndex(name) and pick another name or delete the existing sheet.
  3. If the old sheet should be replaced, call f.DeleteSheet before AddChartSheet.

Example fix

// before
f.AddChartSheet("Sheet1", chart) // ErrExistsSheet
// after
name := "Chart"
for f.GetSheetIndex(name) != 0 {
    name += "_1"
}
f.AddChartSheet(name, chart)
Defensive patterns

Strategy: validation

Validate before calling

name := "MyChart"
if f.GetSheetIndex(name) != 0 {
	name = fmt.Sprintf("%s_%d", name, time.Now().UnixNano())
}
f.AddChartSheet(name, chart)

Type guard

func sheetExists(f *excelize.File, name string) bool {
	return f.GetSheetIndex(name) != 0
}

Try / catch

err := f.AddChartSheet(name, chart)
if errors.Is(err, excelize.ErrExistsSheet) {
	name = name + "_1"
	err = f.AddChartSheet(name, chart)
}

Prevention

When it happens

Trigger: Calling f.AddChartSheet("Sheet1", chart) when "Sheet1" already exists (created via NewSheet, the default sheet, or a previous AddChartSheet).

Common situations: Adding chartsheets to files created from a template that already contains sheets; hardcoding "Sheet1" which always exists in new workbooks; re-running generation scripts.

Related errors


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