{"record":{"id":"6ea110a3cc63e327","repo":"qax-os/excelize","slug":"errsave","errorCode":"ErrSave","errorMessage":"no path defined for file, consider File.WriteTo or File.Write","messagePattern":"no path defined for file, consider File\\.WriteTo or File\\.Write","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":140,"sourceCode":"\t// parameter.\n\tErrParameterInvalid = errors.New(\"parameter is invalid\")\n\t// ErrParameterRequired defined the error message on receive the empty\n\t// parameter.\n\tErrParameterRequired = errors.New(\"parameter is required\")\n\t// ErrPasswordLengthInvalid defined the error message on invalid password\n\t// length.\n\tErrPasswordLengthInvalid = errors.New(\"password length invalid\")\n\t// ErrPivotTableShowValuesAsBaseField defined the error message on enable\n\t// this kind of \"show values as\" type requires a base field.\n\tErrPivotTableShowValuesAsBaseField = errors.New(\"this kind of show values as type requires a base field\")\n\t// ErrPivotTableShowValuesAsBaseItem defined the error message on enable\n\t// this kind of \"show values as\" type and base field requires a base item.\n\tErrPivotTableShowValuesAsBaseItem = errors.New(\"this kind of show values as type and base field requires a base item\")\n\t// ErrPivotTableClassicLayout defined the error message on enable\n\t// ClassicLayout and CompactData in the same time.\n\tErrPivotTableClassicLayout = errors.New(\"cannot enable ClassicLayout and CompactData in the same time\")\n\t// ErrSave defined the error message for saving file.\n\tErrSave = errors.New(\"no path defined for file, consider File.WriteTo or File.Write\")\n\t// ErrSheetIdx defined the error message on receive the invalid worksheet\n\t// index.\n\tErrSheetIdx = errors.New(\"invalid worksheet index\")\n\t// ErrSheetNameBlank defined the error message on receive the blank sheet\n\t// name.\n\tErrSheetNameBlank = errors.New(\"the sheet name can not be blank\")\n\t// ErrSheetNameInvalid defined the error message on receive the sheet name\n\t// contains invalid characters.\n\tErrSheetNameInvalid = errors.New(\"the sheet can not contain any of the characters :\\\\/?*[or]\")\n\t// ErrSheetNameLength defined the error message on receiving the sheet\n\t// name length exceeds the limit.\n\tErrSheetNameLength = fmt.Errorf(\"the sheet name length exceeds the %d characters limit\", MaxSheetNameLength)\n\t// ErrSheetNameSingleQuote defined the error message on the first or last\n\t// character of the sheet name was a single quote.\n\tErrSheetNameSingleQuote = errors.New(\"the first or last character of the sheet name can not be a single quote\")\n\t// ErrSparkline defined the error message on receive the invalid sparkline\n\t// parameters.\n\tErrSparkline = errors.New(\"must have the same number of 'Location' and 'Range' parameters\")","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L122-L158","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nf := excelize.NewFile()\nf.SetCellValue(\"Sheet1\", \"A1\", 1)\nf.Save() // ErrSave\n// after\nf := excelize.NewFile()\nf.SetCellValue(\"Sheet1\", \"A1\", 1)\nf.SaveAs(\"output.xlsx\")","handlingStrategy":"validation","validationCode":"if f.Path == \"\" {\n    return f.SaveAs(\"output.xlsx\")\n}\nreturn f.Save()","typeGuard":"func canSave(f *excelize.File) bool { return f.Path != \"\" }","tryCatchPattern":"if err := f.Save(); errors.Is(err, excelize.ErrSave) { err = f.SaveAs(\"output.xlsx\") }","preventionTips":["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"],"tags":["go","excelize","save","missing-path"],"backgroundTag":"missing-file-path","analyzedSha":"f2483381fbfbe432a6baa98d48a1c277183f3285","analyzedAt":"2026-09-02T01:26:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}