qax-os/excelize · warning

ErrUnprotectSheet

ErrUnprotectSheet

Error message

worksheet has set no protect

What it means

Sentinel error ErrUnprotectSheet returned by UnprotectSheet when the target worksheet has no SheetProtection element set, so there is nothing to remove; indicates removal of protection was attempted on an unprotected sheet.

Source

Thrown at errors.go:182

	ErrSparklineRange = errors.New("parameter 'Range' is required")
	// ErrSparklineStyle defined the error message on receive the invalid
	// sparkline Style parameters.
	ErrSparklineStyle = errors.New("parameter 'Style' value must be an integer from 0 to 35")
	// ErrSparklineType defined the error message on receive the invalid
	// sparkline Type parameters.
	ErrSparklineType = errors.New("parameter 'Type' value must be one of 'line', 'column' or 'win_loss'")
	// ErrTotalSheetHyperlinks defined the error message on hyperlinks count
	// overflow.
	ErrTotalSheetHyperlinks = errors.New("over maximum limit hyperlinks in a worksheet")
	// ErrTransparency defined the error message for receiving a transparency
	// value exceeds limit.
	ErrTransparency = errors.New("transparency value must be an integer from 0 to 100")
	// ErrUnknownEncryptMechanism defined the error message on unsupported
	// encryption mechanism.
	ErrUnknownEncryptMechanism = errors.New("unknown encryption mechanism")
	// ErrUnprotectSheet defined the error message on worksheet has set no
	// protection.
	ErrUnprotectSheet = errors.New("worksheet has set no protect")
	// ErrUnprotectSheetPassword defined the error message on remove sheet
	// protection with password verification failed.
	ErrUnprotectSheetPassword = errors.New("worksheet protect password not match")
	// ErrUnprotectWorkbook defined the error message on workbook has set no
	// protection.
	ErrUnprotectWorkbook = errors.New("workbook has set no protect")
	// ErrUnprotectWorkbookPassword defined the error message on remove workbook
	// protection with password verification failed.
	ErrUnprotectWorkbookPassword = errors.New("workbook protect password not match")
	// ErrUnsupportedEncryptMechanism defined the error message on unsupported
	// encryption mechanism.
	ErrUnsupportedEncryptMechanism = errors.New("unsupported encryption mechanism")
	// ErrUnsupportedHashAlgorithm defined the error message on unsupported
	// hash algorithm.
	ErrUnsupportedHashAlgorithm = errors.New("unsupported hash algorithm")
	// ErrUnsupportedNumberFormat defined the error message on unsupported
	// number format expression.
	ErrUnsupportedNumberFormat = errors.New("unsupported number format token")

View on GitHub (pinned to f2483381fb)

Solutions

  1. Check ws.SheetProtection is set before calling UnprotectSheet, or ignore this error
  2. Remove the UnprotectSheet call for unprotected sheets

Example fix

// before
err := f.UnprotectSheet("Sheet1", "pw")
// after
ws, _ := f.GetSheetProtection... // check protection first
if err != nil && err != ErrUnprotectSheet { return err }
Defensive patterns

Strategy: try-catch

Validate before calling

ws, err := f.GetSheetProtection... // or inspect f.WorkBook.Sheet metadata
// only call UnprotectSheet when protection options are present

Try / catch

if err := f.UnprotectSheet("Sheet1", "pw"); err != nil && !errors.Is(err, excelize.ErrUnprotectSheet) {
	return err
}

Prevention

When it happens

Trigger: Calling f.UnprotectSheet(sheetName, ...) (with or without password) when the sheet's SheetProtection element is absent or not enabled.

Common situations: Calling UnprotectSheet unconditionally without checking whether the sheet was protected; scripts processing mixed protected/unprotected sheets.

Related errors


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