qax-os/excelize · error
ErrSave
ErrSave
Error message
no path defined for file, consider File.WriteTo or File.Write
What it means
ErrSave is returned by File.Save when the file has no associated path (f.Path == ""). Save writes to the path the file was opened/created from; files created with excelize.NewFile have no path, so Save cannot know where to write.
Source
Thrown at errors.go:140
// 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
// parameters.
ErrSparkline = errors.New("must have the same number of 'Location' and 'Range' parameters")View on GitHub (pinned to f2483381fb)
Solutions
- Use f.SaveAs("path.xlsx") instead of f.Save() for newly created workbooks
- Set f.Path before calling Save (e.g. f.Path = "book.xlsx")
- Call Save only on files opened from an existing path via excelize.OpenFile
Example fix
// before
f := excelize.NewFile()
f.SetCellValue("Sheet1", "A1", 1)
f.Save() // ErrSave
// after
f := excelize.NewFile()
f.SetCellValue("Sheet1", "A1", 1)
f.SaveAs("output.xlsx") Defensive patterns
Strategy: validation
Validate before calling
if f.Path == "" {
return f.SaveAs("output.xlsx")
}
return f.Save() Type guard
func canSave(f *excelize.File) bool { return f.Path != "" } Try / catch
if err := f.Save(); errors.Is(err, excelize.ErrSave) { err = f.SaveAs("output.xlsx") } Prevention
- Use SaveAs for workbooks created with NewFile
- Call Save only on files opened via OpenFile from a real path
- Set f.Path explicitly if you construct File objects manually
When it happens
Trigger: Calling f.Save() on a workbook created via excelize.NewFile() without ever setting f.Path or using SaveAs; calling Save on a File constructed programmatically and not opened from disk.
Common situations: NewFile() followed by Save() instead of SaveAs(path); refactored code that switched from OpenFile to NewFile but kept the Save call; constructing File structs in tests.
Related errors
- fill type value must be one of 'gradient' or 'pattern'
- fill color value must be an array of two colors for 'gradien
- fill shading value must be between 0 and 16 for 'gradient' t
- fill color value must be empty or an array of one color for
- fill pattern value must be between 0 and 18
AI-assisted analysis of qax-os/excelize@f2483381fb (2026-09-02).
Data as JSON: /api/errors/6ea110a3cc63e327.
Report an issue: GitHub.