{"record":{"id":"817346bb29ab962d","repo":"qax-os/excelize","slug":"comment-already-exist-on-cell-s","errorCode":null,"errorMessage":"comment already exist on cell %s","messagePattern":"comment already exist on cell (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":225,"sourceCode":"\t// ErrWorkbookPassword defined the error message on receiving the incorrect\n\t// workbook password.\n\tErrWorkbookPassword = errors.New(\"the supplied open workbook password is not correct\")\n)\n\n// ErrSheetNotExist defined an error of sheet that does not exist.\ntype ErrSheetNotExist struct {\n\tSheetName string\n}\n\n// Error returns the error message on receiving the non existing sheet name.\nfunc (err ErrSheetNotExist) Error() string {\n\treturn fmt.Sprintf(\"sheet %s does not exist\", err.SheetName)\n}\n\n// newAddCommentError defined the error message on the comment already exist in\n// the cell.\nfunc newAddCommentError(cell string) error {\n\treturn fmt.Errorf(\"comment already exist on cell %s\", cell)\n}\n\n// newCellNameToCoordinatesError defined the error message on converts\n// alphanumeric cell name to coordinates.\nfunc newCellNameToCoordinatesError(cell string, err error) error {\n\treturn fmt.Errorf(\"cannot convert cell %q to coordinates: %v\", cell, err)\n}\n\n// newChartTitleError defined the error message on receiving the invalid chart\n// title parameters.\nfunc newChartTitleError(name string) error {\n\treturn fmt.Errorf(\"chart title field %s value must be an integer from 0 to 100\", name)\n}\n\n// newCoordinatesToCellNameError defined the error message on converts [X, Y]\n// coordinates to alpha-numeric cell name.\nfunc newCoordinatesToCellNameError(col, row int) error {\n\treturn fmt.Errorf(\"invalid cell reference [%d, %d]\", col, row)","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L207-L243","documentation":"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.","triggerScenarios":"Calling f.AddComment(\"Sheet1\", &excelize.Comment{Cell: \"A1\", ...}) twice for the same cell without deleting the first comment.","commonSituations":"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.","solutions":["Delete the existing comment first (DeleteComment) before adding a new one","Skip cells that already have comments, or update/merge your comment text with the existing one","Write into a fresh workbook or a cleared sheet when regenerating output"],"exampleFix":"// before\nf.AddComment(\"Sheet1\", &excelize.Comment{Cell: \"A1\", Text: \"new\"}) // fails if A1 has a comment\n// after\nif f.GetComments(\"Sheet1\", \"A1\") != nil {\n\tf.DeleteComment(\"Sheet1\", \"A1\")\n}\nf.AddComment(\"Sheet1\", &excelize.Comment{Cell: \"A1\", Text: \"new\"})","handlingStrategy":"try-catch","validationCode":"if f.GetComments(sheet, cell) != nil { f.DeleteComment(sheet, cell) }","typeGuard":null,"tryCatchPattern":"if err := f.AddComment(sheet, &excelize.Comment{Cell: cell, Text: text}); err != nil {\n\tif strings.HasPrefix(err.Error(), \"comment already exist on cell\") {\n\t\terr = f.DeleteComment(sheet, cell)\n\t\tif err == nil { err = f.AddComment(sheet, &excelize.Comment{Cell: cell, Text: text}) }\n\t}\n}","preventionTips":["Check/delete existing comments before adding to the same cell","Don't regenerate comments into an already-annotated workbook without clearing them","Track which cells your code has annotated to avoid double-adds"],"tags":["excelize","comment","duplicate","conflict"],"backgroundTag":"duplicate-resource-conflict","analyzedSha":"f2483381fbfbe432a6baa98d48a1c277183f3285","analyzedAt":"2026-09-02T01:26:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}