diff options
author | xuri <xuri.me@gmail.com> | 2019-08-09 09:23:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-09 09:23:28 +0800 |
commit | e6b7ac9a03556fcf3b9c59abb93bfa9e3dd2dbcb (patch) | |
tree | 95c6d83c9912efa8e0004b3bdd561c2d1b0fac73 /sheet.go | |
parent | 448f5524a8ea621fd40978dcc518ff6d9bbcdf83 (diff) | |
parent | faaaa52cb862499454a7f893b92e8430d00172a5 (diff) |
Merge pull request #463 from mlh758/fix-457
Get sheet names based on index
Diffstat (limited to 'sheet.go')
-rw-r--r-- | sheet.go | 15 |
1 files changed, 6 insertions, 9 deletions
@@ -317,14 +317,11 @@ func (f *File) SetSheetName(oldName, newName string) { // string. func (f *File) GetSheetName(index int) string { wb := f.workbookReader() - if wb != nil { - for _, sheet := range wb.Sheets.Sheet { - if sheet.SheetID == index { - return sheet.Name - } - } + realIdx := index - 1 // sheets are 1 based index, but we're checking against an array + if wb == nil || realIdx < 0 || realIdx >= len(wb.Sheets.Sheet) { + return "" } - return "" + return wb.Sheets.Sheet[realIdx].Name } // GetSheetIndex provides a function to get worksheet index of XLSX by given @@ -357,8 +354,8 @@ func (f *File) GetSheetMap() map[int]string { wb := f.workbookReader() sheetMap := map[int]string{} if wb != nil { - for _, sheet := range wb.Sheets.Sheet { - sheetMap[sheet.SheetID] = sheet.Name + for i, sheet := range wb.Sheets.Sheet { + sheetMap[i+1] = sheet.Name } } return sheetMap |