diff options
author | Harris <mike.harris@cerner.com> | 2019-08-07 08:53:37 -0500 |
---|---|---|
committer | Harris <mike.harris@cerner.com> | 2019-08-08 08:19:18 -0500 |
commit | faaaa52cb862499454a7f893b92e8430d00172a5 (patch) | |
tree | 9fbac7114aea985fb4c1dae4ba98695d7f2da654 /sheet_test.go | |
parent | d8df51098f11eaa520112c6d043509b893bf0097 (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_test.go')
-rw-r--r-- | sheet_test.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/sheet_test.go b/sheet_test.go index ef795ad..3baa084 100644 --- a/sheet_test.go +++ b/sheet_test.go @@ -225,3 +225,24 @@ func TestUngroupSheets(t *testing.T) { } assert.NoError(t, f.UngroupSheets()) } + +func TestGetSheetName(t *testing.T) { + f, _ := excelize.OpenFile(filepath.Join("test", "Book1.xlsx")) + assert.Equal(t, "Sheet1", f.GetSheetName(1)) + assert.Equal(t, "Sheet2", f.GetSheetName(2)) + assert.Equal(t, "", f.GetSheetName(0)) + assert.Equal(t, "", f.GetSheetName(3)) +} + +func TestGetSheetMap(t *testing.T) { + expectedMap := map[int]string{ + 1: "Sheet1", + 2: "Sheet2", + } + f, _ := excelize.OpenFile(filepath.Join("test", "Book1.xlsx")) + sheetMap := f.GetSheetMap() + for idx, name := range sheetMap { + assert.Equal(t, expectedMap[idx], name) + } + assert.Equal(t, len(sheetMap), 2) +} |