qax-os/excelize · error
data validation range exceeds limit
Error message
data validation range exceeds limit
What it means
ErrDataValidationRange is returned by Excelize when a data validation formula value is a float64 whose absolute value exceeds math.MaxFloat32. Data validation ranges in Excel are constrained to 32-bit float precision, so out-of-range values like math.MaxFloat64 would be silently corrupted or rejected by Excel. The library throws it from SetRange (datavalidation.go:174) to surface this early instead of writing an invalid XLSX.
Source
Thrown at errors.go:52
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")
// ErrDefinedNameDuplicate defined the error message on the same name
// already exists on the scope.
ErrDefinedNameDuplicate = errors.New("the same name already exists on the scope")
// ErrDefinedNameScope defined the error message on not found defined name
// in the given scope.
ErrDefinedNameScope = errors.New("no defined name on the scope")
// ErrExistsSheet defined the error message on given sheet already exists.
ErrExistsSheet = errors.New("the same name sheet already exists")
// ErrExistsTableName defined the error message on given table already
// exists.
ErrExistsTableName = errors.New("the same name table already exists")
// ErrFillType defined the error message on receive an invalid fill type.
ErrFillType = errors.New("fill type value must be one of 'gradient' or 'pattern'")
// ErrFillGradientColor defined the error message on receive an invalid fill
// color for 'gradient' type.
ErrFillGradientColor = errors.New("fill color value must be an array of two colors for 'gradient' type")
// ErrFillGradientShading defined the error message on receive an invalid
// fill shading for 'gradient' type.View on GitHub (pinned to f2483381fb)
Solutions
- Clamp the validation bounds to math.MaxFloat32 (or smaller, e.g. whole-number limit 2147483647) before calling SetRange.
- Use operator-based validations (GreaterThanOrEqual with a sentinel like 0) instead of extreme min/max bounds to express 'unbounded'.
- Convert 64-bit inputs from config/DB to float32 first and handle overflow at your application's boundary.
Example fix
// before dv.SetRange(-math.MaxFloat64, math.MaxFloat64, DataValidationTypeDecimal, DataValidationOperatorBetween) // after limit := float64(math.MaxFloat32) dv.SetRange(-limit, limit, DataValidationTypeDecimal, DataValidationOperatorBetween)
Defensive patterns
Strategy: validation
Validate before calling
func inRange(v float64) bool { return !math.IsInf(v, 0) && !math.IsNaN(v) && math.Abs(v) <= math.MaxFloat32 }
// before calling: if !inRange(min) || !inRange(max) { clamp or skip SetRange } Type guard
func safeValidationBound(v float64) (float64, bool) {
if math.Abs(v) > math.MaxFloat32 {
return 0, false
}
return v, true
} Try / catch
err := dv.SetRange(min, max, excelize.DataValidationTypeDecimal, excelize.DataValidationOperatorBetween)
if errors.Is(err, excelize.ErrDataValidationRange) {
// clamp bounds to math.MaxFloat32 and retry
} Prevention
- Clamp all user/config numeric inputs to math.MaxFloat32 before using as validation bounds
- Never use math.MaxFloat64 or math.SmallestNonzeroFloat64 as sentinel bounds for Excel validations
- Remember whole-number validations should stay within ±2147483647
When it happens
Trigger: Calling DataValidation.SetRange with a DataValidationTypeDecimal or DataValidationTypeWhole range whose float64 min or max has absolute value > math.MaxFloat32, e.g. SetRange(-math.MaxFloat64, math.MaxFloat32, DataValidationTypeWhole, DataValidationOperatorGreaterThan) or passing math.MaxFloat64 / math.SmallestNonzeroFloat64 extremes as bounds.
Common situations: Developers compute validation bounds from untyped config values or database numerics that are 64-bit floats; using Go's math.MaxFloat64/SmallestNonzeroFloat64 as 'no limit' sentinels when Excel's effective range is only ±3.4e38 (and integers up to ~2.1e9 for whole-number validations).
Related errors
- the same name already exists on the scope
- no defined name on the scope
- the same name sheet already exists
- the same name table already exists
- fill type value must be one of 'gradient' or 'pattern'
AI-assisted analysis of qax-os/excelize@f2483381fb (2026-09-02).
Data as JSON: /api/errors/2a5fc8cf32196b79.
Report an issue: GitHub.