qax-os/excelize · error

comment already exist on cell %s

Error message

comment already exist on cell %s

What it means

newAddCommentError builds the error returned when adding a comment to a cell that already has one, since a worksheet cell supports only a single comment per cell in this model. addComment detects the existing comment for the target cell and wraps the cell reference in this message.

Source

Thrown at errors.go:225

	// ErrWorkbookPassword defined the error message on receiving the incorrect
	// workbook password.
	ErrWorkbookPassword = errors.New("the supplied open workbook password is not correct")
)

// ErrSheetNotExist defined an error of sheet that does not exist.
type ErrSheetNotExist struct {
	SheetName string
}

// Error returns the error message on receiving the non existing sheet name.
func (err ErrSheetNotExist) Error() string {
	return fmt.Sprintf("sheet %s does not exist", err.SheetName)
}

// newAddCommentError defined the error message on the comment already exist in
// the cell.
func newAddCommentError(cell string) error {
	return fmt.Errorf("comment already exist on cell %s", cell)
}

// newCellNameToCoordinatesError defined the error message on converts
// alphanumeric cell name to coordinates.
func newCellNameToCoordinatesError(cell string, err error) error {
	return fmt.Errorf("cannot convert cell %q to coordinates: %v", cell, err)
}

// newChartTitleError defined the error message on receiving the invalid chart
// title parameters.
func newChartTitleError(name string) error {
	return fmt.Errorf("chart title field %s value must be an integer from 0 to 100", name)
}

// newCoordinatesToCellNameError defined the error message on converts [X, Y]
// coordinates to alpha-numeric cell name.
func newCoordinatesToCellNameError(col, row int) error {
	return fmt.Errorf("invalid cell reference [%d, %d]", col, row)

View on GitHub (pinned to f2483381fb)

Solutions

  1. Delete the existing comment first (DeleteComment) before adding a new one
  2. Skip cells that already have comments, or update/merge your comment text with the existing one
  3. Write into a fresh workbook or a cleared sheet when regenerating output

Example fix

// before
f.AddComment("Sheet1", &excelize.Comment{Cell: "A1", Text: "new"}) // fails if A1 has a comment
// after
if f.GetComments("Sheet1", "A1") != nil {
	f.DeleteComment("Sheet1", "A1")
}
f.AddComment("Sheet1", &excelize.Comment{Cell: "A1", Text: "new"})
Defensive patterns

Strategy: try-catch

Validate before calling

if f.GetComments(sheet, cell) != nil { f.DeleteComment(sheet, cell) }

Try / catch

if err := f.AddComment(sheet, &excelize.Comment{Cell: cell, Text: text}); err != nil {
	if strings.HasPrefix(err.Error(), "comment already exist on cell") {
		err = f.DeleteComment(sheet, cell)
		if err == nil { err = f.AddComment(sheet, &excelize.Comment{Cell: cell, Text: text}) }
	}
}

Prevention

When it happens

Trigger: Calling f.AddComment("Sheet1", &excelize.Comment{Cell: "A1", ...}) twice for the same cell without deleting the first comment.

Common situations: Regenerating a report into an existing file/template that already has comments; loops that add annotations to every cell but run more than once; merging data from two sources that both annotate the same cells.

Related errors


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