qax-os/excelize · error

group worksheet must contain an active worksheet

Error message

group worksheet must contain an active worksheet

What it means

ErrGroupSheets is returned when grouping worksheets (GroupSheets) because the selection does not include the workbook's active sheet. Excel requires that a group of worksheets always contains the currently active worksheet.

Source

Thrown at errors.go:87

	// ErrFillGradientShading defined the error message on receive an invalid
	// fill shading for 'gradient' type.
	ErrFillGradientShading = errors.New("fill shading value must be between 0 and 16 for 'gradient' type")
	// ErrFillPatternColor defined the error message on receive an invalid fill
	// color for 'pattern' type.
	ErrFillPatternColor = errors.New("fill color value must be empty or an array of one color for 'pattern' type")
	// ErrFillPattern defined the error message on receive an invalid fill
	// pattern.
	ErrFillPattern = errors.New("fill pattern value must be between 0 and 18")
	// ErrFontLength defined the error message on the length of the font
	// family name overflow.
	ErrFontLength = fmt.Errorf("the length of the font family name must be less than or equal to %d", MaxFontFamilyLength)
	// ErrFontSize defined the error message on the size of the font is invalid.
	ErrFontSize = fmt.Errorf("font size must be an integer from %d to %d points", MinFontSize, MaxFontSize)
	// ErrFormControlValue defined the error message for receiving a scroll
	// value exceeds limit.
	ErrFormControlValue = fmt.Errorf("scroll value must be an integer from 0 to %d", MaxFormControlValue)
	// ErrGroupSheets defined the error message on group sheets.
	ErrGroupSheets = errors.New("group worksheet must contain an active worksheet")
	// ErrImgExt defined the error message on receive an unsupported image
	// extension.
	ErrImgExt = errors.New("unsupported image extension")
	// ErrInvalidFormula defined the error message on receive an invalid
	// formula.
	ErrInvalidFormula = errors.New("formula not valid")
	// ErrMaxFilePathLength defined the error message on receive the file path
	// length overflow.
	ErrMaxFilePathLength = fmt.Errorf("file path length exceeds maximum limit %d characters", MaxFilePathLength)
	// ErrMaxRowHeight defined the error message on receive an invalid row
	// height.
	ErrMaxRowHeight = fmt.Errorf("the height of the row must be less than or equal to %d points", MaxRowHeight)
	// ErrMaxRows defined the error message on receive a row number exceeds
	// maximum limit.
	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)

View on GitHub (pinned to f2483381fb)

Solutions

  1. Include the currently active sheet in the list passed to GroupSheets (check f.GetActiveSheetName()).
  2. Call f.SetActiveSheet(index) to make one of the target sheets active before grouping.
  3. Verify the active sheet index with f.GetActiveSheetIndex() and adjust your sheet list accordingly.

Example fix

// before
f.SetActiveSheet(2)
f.GroupSheets([]string{"Sheet1", "Sheet2"}) // active sheet missing
// after
f.SetActiveSheet(0) // make Sheet1 active
f.GroupSheets([]string{"Sheet1", "Sheet2"})
Defensive patterns

Strategy: validation

Validate before calling

active := f.GetActiveSheetName()
if !slices.Contains(sheetNames, active) {
    return fmt.Errorf("active sheet %q must be included in group", active)
}
err := f.GroupSheets(sheetNames)

Type guard

func canGroupSheets(f *excelize.File, names []string) bool {
    return slices.Contains(names, f.GetActiveSheetName())
}

Try / catch

if err := f.GroupSheets(names); errors.Is(err, excelize.ErrGroupSheets) {
    // activate one of the target sheets and retry
    _ = f.SetActiveSheet(indexOf(names[0]))
    err = f.GroupSheets(names)
}

Prevention

When it happens

Trigger: Calling f.GroupSheets([]string{"Sheet1", "Sheet2"}) when the workbook's active sheet is Sheet3 (or another sheet not in the list).

Common situations: Grouping sheets by name after the user or earlier code changed the active tab, or grouping a subset of sheets that accidentally excludes the active one.

Related errors


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