{"record":{"id":"9ea3be718f0dd486","repo":"qax-os/excelize","slug":"formula-not-valid","errorCode":null,"errorMessage":"formula not valid","messagePattern":"formula not valid","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":93,"sourceCode":"\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.\n\tErrFontSize = fmt.Errorf(\"font size must be an integer from %d to %d points\", MinFontSize, MaxFontSize)\n\t// ErrFormControlValue defined the error message for receiving a scroll\n\t// value exceeds limit.\n\tErrFormControlValue = fmt.Errorf(\"scroll value must be an integer from 0 to %d\", MaxFormControlValue)\n\t// ErrGroupSheets defined the error message on group sheets.\n\tErrGroupSheets = errors.New(\"group worksheet must contain an active worksheet\")\n\t// ErrImgExt defined the error message on receive an unsupported image\n\t// extension.\n\tErrImgExt = errors.New(\"unsupported image extension\")\n\t// ErrInvalidFormula defined the error message on receive an invalid\n\t// formula.\n\tErrInvalidFormula = errors.New(\"formula not valid\")\n\t// ErrMaxFilePathLength defined the error message on receive the file path\n\t// length overflow.\n\tErrMaxFilePathLength = fmt.Errorf(\"file path length exceeds maximum limit %d characters\", MaxFilePathLength)\n\t// ErrMaxRowHeight defined the error message on receive an invalid row\n\t// height.\n\tErrMaxRowHeight = fmt.Errorf(\"the height of the row must be less than or equal to %d points\", MaxRowHeight)\n\t// ErrMaxRows defined the error message on receive a row number exceeds\n\t// maximum limit.\n\tErrMaxRows = errors.New(\"row number exceeds maximum limit\")\n\t// ErrNameLength defined the error message on receiving the defined name or\n\t// table name length exceeds the limit.\n\tErrNameLength = fmt.Errorf(\"the name length exceeds the %d characters limit\", MaxFieldLength)\n\t// ErrMaxGraphicAltTextLength defined the error message on receiving the\n\t// graphic alt text length exceeds the limit.\n\tErrMaxGraphicAltTextLength = fmt.Errorf(\"the alt text length exceeds the %d characters limit\", MaxGraphicAltTextLength)\n\t// ErrMaxGraphicNameLength defined the error message on receiving the\n\t// graphic name length exceeds the limit.\n\tErrMaxGraphicNameLength = fmt.Errorf(\"the name length exceeds the %d characters limit\", MaxGraphicNameLength)","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L75-L111","documentation":"ErrInvalidFormula is returned by the formula calculator when a formula cannot be parsed or evaluated, e.g. when the operand stack is empty at a point where an operand is required, or a prefix operator like '-' has no operand. It signals a structurally invalid formula string.","triggerScenarios":"f.SetCellFormula with formulas like \"=\", \"=-\", \"=1+\", or other malformed expressions; also surfaces from CalcCellValue when evaluation runs out of operands.","commonSituations":"Building formulas by string concatenation with empty cell references or user input, truncated formulas from templates, or copying formulas between locales/functions that were mangled.","solutions":["Inspect the formula string and fix the syntax so every operator has its operands (e.g. \"=-A1\" instead of \"=-\").","Validate the formula with a parser or test evaluation via CalcCellValue before writing it.","Guard string concatenation that builds formulas so empty parts cannot produce dangling operators.","Escape or quote values correctly, e.g. text literals need double quotes inside the formula string."],"exampleFix":"// before\nf.SetCellFormula(\"A1\", \"=1+\")\n// after\nf.SetCellFormula(\"A1\", \"=1+B1\")","handlingStrategy":"validation","validationCode":"if strings.HasSuffix(strings.TrimSpace(formula), \"+\") || strings.HasSuffix(strings.TrimSpace(formula), \"-\") || strings.HasSuffix(strings.TrimSpace(formula), \"=\") {\n    return errors.New(\"formula ends with a dangling operator\")\n}","typeGuard":null,"tryCatchPattern":"if _, err := f.CalcCellValue(sheet, cell); errors.Is(err, excelize.ErrInvalidFormula) {\n    log.Printf(\"invalid formula %q: %v\", formula, err)\n    // fall back to storing the formula as text or repairing it\n}","preventionTips":["Build formulas with a builder/helper rather than raw string concatenation.","Check every interpolated cell reference is non-empty before composing the formula.","Test-round-trip critical formulas with CalcCellValue before writing to production files.","Escape string literals with double quotes inside formula strings."],"tags":["go","excelize","formula","parsing","validation"],"backgroundTag":"invalid-formula-syntax","analyzedSha":"f2483381fbfbe432a6baa98d48a1c277183f3285","analyzedAt":"2026-09-02T01:26:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}