Skip to content

Commit 5ec6131

Browse files
authored
fix: LocalSheetID in DefinedName should be equal to SheetIndex instead of SheetID (qax-os#868)
1 parent f27624a commit 5ec6131

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

sheet.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -507,17 +507,17 @@ func (f *File) DeleteSheet(name string) {
507507
wb := f.workbookReader()
508508
wbRels := f.relsReader(f.getWorkbookRelsPath())
509509
activeSheetName := f.GetSheetName(f.GetActiveSheetIndex())
510-
deleteSheetID := f.getSheetID(name)
510+
deleteLocalSheetID := f.GetSheetIndex(name)
511511
// Delete and adjust defined names
512512
if wb.DefinedNames != nil {
513513
for idx := 0; idx < len(wb.DefinedNames.DefinedName); idx++ {
514514
dn := wb.DefinedNames.DefinedName[idx]
515515
if dn.LocalSheetID != nil {
516-
sheetID := *dn.LocalSheetID + 1
517-
if sheetID == deleteSheetID {
516+
localSheetID := *dn.LocalSheetID
517+
if localSheetID == deleteLocalSheetID {
518518
wb.DefinedNames.DefinedName = append(wb.DefinedNames.DefinedName[:idx], wb.DefinedNames.DefinedName[idx+1:]...)
519519
idx--
520-
} else if sheetID > deleteSheetID {
520+
} else if localSheetID > deleteLocalSheetID {
521521
wb.DefinedNames.DefinedName[idx].LocalSheetID = intPtr(*dn.LocalSheetID - 1)
522522
}
523523
}
@@ -1495,7 +1495,7 @@ func (f *File) SetDefinedName(definedName *DefinedName) error {
14951495
for _, dn := range wb.DefinedNames.DefinedName {
14961496
var scope string
14971497
if dn.LocalSheetID != nil {
1498-
scope = f.getSheetNameByID(*dn.LocalSheetID + 1)
1498+
scope = f.GetSheetName(*dn.LocalSheetID)
14991499
}
15001500
if scope == definedName.Scope && dn.Name == definedName.Name {
15011501
return errors.New("the same name already exists on the scope")
@@ -1525,7 +1525,7 @@ func (f *File) DeleteDefinedName(definedName *DefinedName) error {
15251525
for idx, dn := range wb.DefinedNames.DefinedName {
15261526
var scope string
15271527
if dn.LocalSheetID != nil {
1528-
scope = f.getSheetNameByID(*dn.LocalSheetID + 1)
1528+
scope = f.GetSheetName(*dn.LocalSheetID)
15291529
}
15301530
if scope == definedName.Scope && dn.Name == definedName.Name {
15311531
wb.DefinedNames.DefinedName = append(wb.DefinedNames.DefinedName[:idx], wb.DefinedNames.DefinedName[idx+1:]...)
@@ -1550,7 +1550,7 @@ func (f *File) GetDefinedName() []DefinedName {
15501550
Scope: "Workbook",
15511551
}
15521552
if dn.LocalSheetID != nil && *dn.LocalSheetID >= 0 {
1553-
definedName.Scope = f.getSheetNameByID(*dn.LocalSheetID + 1)
1553+
definedName.Scope = f.GetSheetName(*dn.LocalSheetID)
15541554
}
15551555
definedNames = append(definedNames, definedName)
15561556
}

0 commit comments

Comments
 (0)