From fbcfdeae90b7e755a70c6ceef27346c7d0552937 Mon Sep 17 00:00:00 2001 From: xuri Date: Thu, 15 Jul 2021 23:24:01 +0800 Subject: [PATCH] This closes #879, fix delete defined name failed in some case --- sheet.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sheet.go b/sheet.go index ac22b88..05dc2cf 100644 --- a/sheet.go +++ b/sheet.go @@ -1520,11 +1520,15 @@ func (f *File) DeleteDefinedName(definedName *DefinedName) error { wb := f.workbookReader() if wb.DefinedNames != nil { for idx, dn := range wb.DefinedNames.DefinedName { - var scope string + scope := "Workbook" + deleteScope := definedName.Scope + if deleteScope == "" { + deleteScope = "Workbook" + } if dn.LocalSheetID != nil { 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:]...) return nil }