summaryrefslogtreecommitdiff
path: root/sheet.go
diff options
context:
space:
mode:
authorHarris <mike.harris@cerner.com>2019-08-07 08:53:37 -0500
committerHarris <mike.harris@cerner.com>2019-08-08 08:19:18 -0500
commitfaaaa52cb862499454a7f893b92e8430d00172a5 (patch)
tree9fbac7114aea985fb4c1dae4ba98695d7f2da654 /sheet.go
parentd8df51098f11eaa520112c6d043509b893bf0097 (diff)
Get sheet names based on index
SheetID only seems to indicate the file name for the sheet. Check the sheets list based on index instead. Reordering sheets in Excel changes the order they appear in that list. Fixes #457
Diffstat (limited to 'sheet.go')
-rw-r--r--sheet.go15
1 files changed, 6 insertions, 9 deletions
diff --git a/sheet.go b/sheet.go
index e02782a..935deac 100644
--- a/sheet.go
+++ b/sheet.go
@@ -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