qax-os/excelize · error

ErrPageSetupAdjustTo

ErrPageSetupAdjustTo

Error message

adjust to value must be an integer from 0 to 400

What it means

ErrPageSetupAdjustTo is returned by SetPageLayout when the AdjustTo option is outside the range Excel allows (10 to 400 percent of normal size). The declared message mentions 0-400, but sheet.go:1689 enforces 10 <= v <= 400.

Solutions

  1. Set AdjustTo to an integer between 10 and 400
  2. Omit AdjustTo (leave nil) if you do not need a custom scale
  3. Clamp user-supplied scaling percentages before assigning

Example fix

// before
f.SetPageLayout("Sheet1", &PageLayoutOptions{AdjustTo: uintPtr(5)})
// after
f.SetPageLayout("Sheet1", &PageLayoutOptions{AdjustTo: uintPtr(100)})
Defensive patterns

Strategy: validation

Validate before calling

func validAdjustTo(v uint) bool { return v >= 10 && v <= 400 }
if opts.AdjustTo != nil && validAdjustTo(*opts.AdjustTo) { err := f.SetPageLayout(sheet, opts) }

Type guard

func validAdjustTo(v uint) bool { return v >= 10 && v <= 400 }

Try / catch

if err := f.SetPageLayout(sheet, opts); errors.Is(err, excelize.ErrPageSetupAdjustTo) { // clamp and retry with 100 }

Prevention

When it happens

Trigger: Calling File.SetPageLayout(sheet, &PageLayoutOptions{AdjustTo: uintPtr(v)}) with v < 10 or v > 400, e.g. uintPtr(5) as in sheet_test.go:224.

Common situations: Hard-coding a scale value like 5 or 500 for a custom zoom; computing percentage from user input without bounds; confusing AdjustTo with a boolean fit-to-page flag.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of qax-os/excelize@f2483381fb (2026-09-02). Data as JSON: /api/errors/ede514ebd687bd88. Report an issue: GitHub.

Appendix: source

Thrown at errors.go:120

	ErrMaxRows = errors.New("row number exceeds maximum limit")
	// ErrNameLength defined the error message on receiving the defined name or
	// table name length exceeds the limit.
	ErrNameLength = fmt.Errorf("the name length exceeds the %d characters limit", MaxFieldLength)
	// ErrMaxGraphicAltTextLength defined the error message on receiving the
	// graphic alt text length exceeds the limit.
	ErrMaxGraphicAltTextLength = fmt.Errorf("the alt text length exceeds the %d characters limit", MaxGraphicAltTextLength)
	// ErrMaxGraphicNameLength defined the error message on receiving the
	// graphic name length exceeds the limit.
	ErrMaxGraphicNameLength = fmt.Errorf("the name length exceeds the %d characters limit", MaxGraphicNameLength)
	// ErrOptionsUnzipSizeLimit defined the error message for receiving
	// invalid UnzipSizeLimit and UnzipXMLSizeLimit.
	ErrOptionsUnzipSizeLimit = errors.New("the value of UnzipSizeLimit should be greater than or equal to UnzipXMLSizeLimit")
	// ErrOutlineLevel defined the error message on receive an invalid outline
	// level number.
	ErrOutlineLevel = errors.New("invalid outline level")
	// ErrPageSetupAdjustTo defined the error message for receiving a page setup
	// adjust to value exceeds limit.
	ErrPageSetupAdjustTo = errors.New("adjust to value must be an integer from 0 to 400")
	// ErrParameterInvalid defined the error message on receive the invalid
	// parameter.
	ErrParameterInvalid = errors.New("parameter is invalid")
	// ErrParameterRequired defined the error message on receive the empty
	// parameter.
	ErrParameterRequired = errors.New("parameter is required")
	// ErrPasswordLengthInvalid defined the error message on invalid password
	// length.
	ErrPasswordLengthInvalid = errors.New("password length invalid")
	// ErrPivotTableShowValuesAsBaseField defined the error message on enable
	// this kind of "show values as" type requires a base field.
	ErrPivotTableShowValuesAsBaseField = errors.New("this kind of show values as type requires a base field")
	// ErrPivotTableShowValuesAsBaseItem defined the error message on enable
	// this kind of "show values as" type and base field requires a base item.
	ErrPivotTableShowValuesAsBaseItem = errors.New("this kind of show values as type and base field requires a base item")
	// ErrPivotTableClassicLayout defined the error message on enable
	// ClassicLayout and CompactData in the same time.
	ErrPivotTableClassicLayout = errors.New("cannot enable ClassicLayout and CompactData in the same time")

View on GitHub (pinned to f2483381fb)