-
Notifications
You must be signed in to change notification settings - Fork 40
/
utils.go
40 lines (37 loc) · 869 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package excel
import (
"fmt"
"reflect"
)
func (conn *connect) parseSheetName(i interface{}) string {
// log.Printf("%T", i)
switch s := i.(type) {
case string:
return s
case int, int8, int32, int64, uint, uint8, uint16, uint32, uint64:
if name, ok := conn.worksheetIDToNameMap[fmt.Sprintf("%d", s)]; ok {
return name
}
return ""
case interface {
GetXLSXSheetName() string
}:
return s.GetXLSXSheetName()
default:
val := reflect.ValueOf(i)
typ := reflect.Indirect(val).Type()
switch typ.Kind() {
case reflect.Slice, reflect.Array:
// 数组、切片的元素类型
typ = typ.Elem()
if typ.Kind() == reflect.Ptr {
typ = typ.Elem()
}
return conn.parseSheetName(reflect.New(typ).Interface())
case reflect.Ptr:
return conn.parseSheetName(reflect.New(typ).Elem().Interface())
default:
return typ.Name()
}
}
}