{"record":{"id":"22c4c7500043bd5d","repo":"qax-os/excelize","slug":"cannot-set-both-formula-and-paragraph-for-char","errorCode":null,"errorMessage":"cannot set both 'Formula' and 'Paragraph' for chart title","messagePattern":"cannot set both 'Formula' and 'Paragraph' for chart title","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":34,"sourceCode":"\t\"fmt\"\n\t\"strings\"\n)\n\nvar (\n\t// ErrAddVBAProject defined the error message on add the VBA project in\n\t// the workbook.\n\tErrAddVBAProject = errors.New(\"unsupported VBA project\")\n\t// ErrAttrValBool defined the error message on marshal and unmarshal\n\t// boolean type XML attribute.\n\tErrAttrValBool = errors.New(\"unexpected child of attrValBool\")\n\t// ErrCellCharsLength defined the error message for receiving a cell\n\t// characters length that exceeds the limit.\n\tErrCellCharsLength = fmt.Errorf(\"cell value must be 0-%d characters\", TotalCellChars)\n\t// ErrCellStyles defined the error message on cell styles exceeds the limit.\n\tErrCellStyles = fmt.Errorf(\"the cell styles exceeds the %d limit\", MaxCellStyles)\n\t// ErrChartTitle defined the error message on both formula and rich text for\n\t// chart title.\n\tErrChartTitle = errors.New(\"cannot set both 'Formula' and 'Paragraph' for chart title\")\n\t// ErrColumnNumber defined the error message on receive an invalid column\n\t// number.\n\tErrColumnNumber = fmt.Errorf(\"the column number must be greater than or equal to %d and less than or equal to %d\", MinColumns, MaxColumns)\n\t// ErrColumnWidth defined the error message on receive an invalid column\n\t// width.\n\tErrColumnWidth = fmt.Errorf(\"the width of the column must be less than or equal to %d characters\", MaxColumnWidth)\n\t// ErrCoordinates defined the error message on invalid coordinates tuples\n\t// length.\n\tErrCoordinates = errors.New(\"coordinates length must be 4\")\n\t// ErrCustomNumFmt defined the error message on receive the empty custom\n\t// number format.\n\tErrCustomNumFmt = errors.New(\"custom number format can not be empty\")\n\t// ErrDataValidationFormulaLength defined the error message for receiving a\n\t// data validation formula length that exceeds the limit.\n\tErrDataValidationFormulaLength = fmt.Errorf(\"data validation must be 0-%d characters\", MaxFieldLength)\n\t// ErrDataValidationRange defined the error message on set decimal range\n\t// exceeds limit.\n\tErrDataValidationRange = errors.New(\"data validation range exceeds limit\")","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L16-L52","documentation":"ErrChartTitle is returned when a chart's Title options set both Formula (a cell-reference-driven title) and Paragraph (rich-text runs) at the same time. A chart title can have exactly one source of content, so parseTitle rejects the ambiguous combination up front.","triggerScenarios":"Calling AddChart with Chart{Title: ChartTitle{Formula: \"Sheet1!$A$27\", Paragraph: []RichTextRun{{...}}}} — both fields populated in the same ChartTitle struct.","commonSituations":"Merging two example snippets (formula title and rich-text title) into one options struct; copy-pasting config where a previous Paragraph was left in place while adding a Formula link; generating charts from templates that set both.","solutions":["Keep only one of Formula or Paragraph set in ChartTitle","If you want the title driven by a cell, clear the Paragraph slice and set Formula","If you want static rich text, clear Formula and keep the Paragraph runs","Guard your chart-config builder so it errors before calling AddChart when both are non-empty"],"exampleFix":"// before\nTitle: ChartTitle{Formula: \"Sheet1!$A$27\", Paragraph: []RichTextRun{{Text: \"Column Chart\"}}}\n// after\nTitle: ChartTitle{Paragraph: []RichTextRun{{Text: \"Column Chart\"}}}","handlingStrategy":"validation","validationCode":"if len(t.Paragraph) > 0 && t.Formula != \"\" {\n    return errors.New(\"chart title: set only one of Formula or Paragraph\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Choose one title source per chart at config time","Zero the other field when building ChartTitle programmatically","Add a unit test asserting the conflicting combo is never constructed"],"tags":["chart","config-conflict","validation"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"f2483381fbfbe432a6baa98d48a1c277183f3285","analyzedAt":"2026-09-02T01:26:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}