qax-os/excelize · error
cannot set both 'Formula' and 'Paragraph' for chart title
Error message
cannot set both 'Formula' and 'Paragraph' for chart title
What it means
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.
Source
Thrown at errors.go:34
"fmt"
"strings"
)
var (
// ErrAddVBAProject defined the error message on add the VBA project in
// the workbook.
ErrAddVBAProject = errors.New("unsupported VBA project")
// ErrAttrValBool defined the error message on marshal and unmarshal
// boolean type XML attribute.
ErrAttrValBool = errors.New("unexpected child of attrValBool")
// ErrCellCharsLength defined the error message for receiving a cell
// characters length that exceeds the limit.
ErrCellCharsLength = fmt.Errorf("cell value must be 0-%d characters", TotalCellChars)
// ErrCellStyles defined the error message on cell styles exceeds the limit.
ErrCellStyles = fmt.Errorf("the cell styles exceeds the %d limit", MaxCellStyles)
// ErrChartTitle defined the error message on both formula and rich text for
// chart title.
ErrChartTitle = errors.New("cannot set both 'Formula' and 'Paragraph' for chart title")
// ErrColumnNumber defined the error message on receive an invalid column
// number.
ErrColumnNumber = fmt.Errorf("the column number must be greater than or equal to %d and less than or equal to %d", MinColumns, MaxColumns)
// ErrColumnWidth defined the error message on receive an invalid column
// width.
ErrColumnWidth = fmt.Errorf("the width of the column must be less than or equal to %d characters", MaxColumnWidth)
// ErrCoordinates defined the error message on invalid coordinates tuples
// 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")View on GitHub (pinned to f2483381fb)
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
Example fix
// before
Title: ChartTitle{Formula: "Sheet1!$A$27", Paragraph: []RichTextRun{{Text: "Column Chart"}}}
// after
Title: ChartTitle{Paragraph: []RichTextRun{{Text: "Column Chart"}}} Defensive patterns
Strategy: validation
Validate before calling
if len(t.Paragraph) > 0 && t.Formula != "" {
return errors.New("chart title: set only one of Formula or Paragraph")
} Prevention
- 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
When it happens
Trigger: Calling AddChart with Chart{Title: ChartTitle{Formula: "Sheet1!$A$27", Paragraph: []RichTextRun{{...}}}} — both fields populated in the same ChartTitle struct.
Common situations: 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.
Related errors
- ErrTransparency
- unsupported VBA project
- fill type value must be one of 'gradient' or 'pattern'
- fill color value must be an array of two colors for 'gradien
- fill shading value must be between 0 and 16 for 'gradient' t
AI-assisted analysis of qax-os/excelize@f2483381fb (2026-09-02).
Data as JSON: /api/errors/22c4c7500043bd5d.
Report an issue: GitHub.