This closes #879, fix delete defined name failed in some case

v2
xuri 4 years ago
parent f62c45fe0c
commit fbcfdeae90
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7

@ -1520,11 +1520,15 @@ func (f *File) DeleteDefinedName(definedName *DefinedName) error {
wb := f.workbookReader() wb := f.workbookReader()
if wb.DefinedNames != nil { if wb.DefinedNames != nil {
for idx, dn := range wb.DefinedNames.DefinedName { for idx, dn := range wb.DefinedNames.DefinedName {
var scope string scope := "Workbook"
deleteScope := definedName.Scope
if deleteScope == "" {
deleteScope = "Workbook"
}
if dn.LocalSheetID != nil { if dn.LocalSheetID != nil {
scope = f.GetSheetName(*dn.LocalSheetID) scope = f.GetSheetName(*dn.LocalSheetID)
} }
if scope == definedName.Scope && dn.Name == definedName.Name { if scope == deleteScope && dn.Name == definedName.Name {
wb.DefinedNames.DefinedName = append(wb.DefinedNames.DefinedName[:idx], wb.DefinedNames.DefinedName[idx+1:]...) wb.DefinedNames.DefinedName = append(wb.DefinedNames.DefinedName[:idx], wb.DefinedNames.DefinedName[idx+1:]...)
return nil return nil
} }

Loading…
Cancel
Save