qax-os/excelize · error
ErrWorkbookFileFormat
ErrWorkbookFileFormat
Error message
unsupported workbook file format
What it means
ErrWorkbookFileFormat indicates that an encrypted workbook's EncryptedPackage stream is malformed — specifically shorter than packageOffset bytes — so the library cannot parse the package. decryptPackage and openReaderAt return it when the encrypted file structure does not meet the minimum size requirements.
Source
Thrown at errors.go:206
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")
// ErrUnsupportedPivotTableShowValuesAsType defined the error message on
// receiving the unsupported pivot table "show values as" type.
ErrUnsupportedPivotTableShowValuesAsType = errors.New("unsupported pivot table show values as type")
// ErrWorkbookFileFormat defined the error message on receive an
// unsupported workbook file format.
ErrWorkbookFileFormat = errors.New("unsupported workbook file format")
// ErrWorkbookPassword defined the error message on receiving the incorrect
// workbook password.
ErrWorkbookPassword = errors.New("the supplied open workbook password is not correct")
)
// ErrSheetNotExist defined an error of sheet that does not exist.
type ErrSheetNotExist struct {
SheetName string
}
// Error returns the error message on receiving the non existing sheet name.
func (err ErrSheetNotExist) Error() string {
return fmt.Sprintf("sheet %s does not exist", err.SheetName)
}
// newAddCommentError defined the error message on the comment already exist in
// the cell.
func newAddCommentError(cell string) error {View on GitHub (pinned to f2483381fb)
Solutions
- Verify the file is a genuine Excel workbook (encrypted or not) and not renamed/misgenerated
- Re-obtain or re-save the file from its source
- If the file is truly encrypted, decrypt it fully with the producing tool before opening
Example fix
// before
f, err := OpenReader(brokenReader) // EncryptedPackage too short
// after
buf, _ := io.ReadAll(src)
if len(buf) < 1024 { return errors.New("file truncated") }
f, err := OpenReader(bytes.NewReader(buf)) Defensive patterns
Strategy: validation
Validate before calling
data, _ := io.ReadAll(r)
if len(data) < 1024 { return errors.New("encrypted package too small / truncated") } Type guard
func isCompoundFile(b []byte) bool {
return len(b) > 8 && bytes.Equal(b[:8], []byte{0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1})
} Try / catch
f, err := excelize.OpenReader(r)
if errors.Is(err, excelize.ErrWorkbookFileFormat) {
return fmt.Errorf("file is not a valid encrypted workbook package")
} Prevention
- Confirm files are genuine .xlsx (ZIP) or properly encrypted compound files
- Check file integrity (size/checksum) after transfer
- Do not rename arbitrary files to .xlsx and open them
When it happens
Trigger: OpenReader/OpenFile on an encrypted OLE compound file with an empty or undersized EncryptedPackage stream (test builds compoundFile with EncryptionInfo but empty package); truncated encrypted files.
Common situations: Opening a non-workbook file renamed to .xlsx that is also a compound file; corrupted download; file encrypted by a tool writing incomplete streams.
Related errors
- ErrUnknownEncryptMechanism
- unsupported image extension
- ErrPasswordLengthInvalid
- ErrUnsupportedEncryptMechanism
- 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/3325674f47051908.
Report an issue: GitHub.