qax-os/excelize · error

ErrPivotTableClassicLayout

ErrPivotTableClassicLayout

Error message

cannot enable ClassicLayout and CompactData in the same time

What it means

ErrPivotTableClassicLayout is returned when a pivot table's options enable both CompactData and ClassicLayout, which are mutually exclusive layout modes in Excel. parseFormatPivotTableSet rejects the combination before building the pivot table.

Source

Thrown at errors.go:138

	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")
	// ErrSave defined the error message for saving file.
	ErrSave = errors.New("no path defined for file, consider File.WriteTo or File.Write")
	// ErrSheetIdx defined the error message on receive the invalid worksheet
	// index.
	ErrSheetIdx = errors.New("invalid worksheet index")
	// ErrSheetNameBlank defined the error message on receive the blank sheet
	// name.
	ErrSheetNameBlank = errors.New("the sheet name can not be blank")
	// ErrSheetNameInvalid defined the error message on receive the sheet name
	// contains invalid characters.
	ErrSheetNameInvalid = errors.New("the sheet can not contain any of the characters :\\/?*[or]")
	// ErrSheetNameLength defined the error message on receiving the sheet
	// name length exceeds the limit.
	ErrSheetNameLength = fmt.Errorf("the sheet name length exceeds the %d characters limit", MaxSheetNameLength)
	// ErrSheetNameSingleQuote defined the error message on the first or last
	// character of the sheet name was a single quote.
	ErrSheetNameSingleQuote = errors.New("the first or last character of the sheet name can not be a single quote")
	// ErrSparkline defined the error message on receive the invalid sparkline

View on GitHub (pinned to f2483381fb)

Solutions

  1. Set ClassicLayout: true and CompactData: false (or vice versa)
  2. Before calling, zero out one flag when the other is enabled
  3. Persist only one layout choice in your configuration

Example fix

// before
opts := &excelize.PivotTableOptions{CompactData: true, ClassicLayout: true}
f.AddPivotTable(opts)
// after
opts := &excelize.PivotTableOptions{CompactData: false, ClassicLayout: true}
f.AddPivotTable(opts)
Defensive patterns

Strategy: validation

Validate before calling

if opts.CompactData && opts.ClassicLayout {
    opts.CompactData = false // enforce one layout mode
}
err := f.AddPivotTable(opts)

Type guard

func layoutConflict(o excelize.PivotTableOptions) bool { return o.CompactData && o.ClassicLayout }

Try / catch

if err := f.AddPivotTable(opts); errors.Is(err, excelize.ErrPivotTableClassicLayout) { opts.ClassicLayout = false; err = f.AddPivotTable(opts) }

Prevention

When it happens

Trigger: f.AddPivotTable or f.SetPivotTable with a *PivotTableOptions where CompactData == true && ClassicLayout == true (pivotTable.go:359).

Common situations: Merging option sets from two configs where each enables one flag; toggling ClassicLayout without unsetting CompactData; copying example code for each flag independently.

Related errors


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