33 lines
645 B
Go
33 lines
645 B
Go
package util
|
|
|
|
import (
|
|
"github.com/spf13/cast"
|
|
"github.com/tealeg/xlsx"
|
|
)
|
|
|
|
func ParsePersonXlsx(fileName string) (map[string]float64, error) {
|
|
// 打开Excel文件
|
|
xlFile, err := xlsx.OpenFile(fileName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
result := make(map[string]float64)
|
|
|
|
// 遍历所有的sheet
|
|
for _, sheet := range xlFile.Sheets {
|
|
// 遍历sheet中的行
|
|
for _, row := range sheet.Rows {
|
|
if len(row.Cells) < 41 || !ValidateIDCard(row.Cells[3].Value) {
|
|
continue
|
|
}
|
|
value := cast.ToFloat64(row.Cells[40].Value)
|
|
if value == 0 {
|
|
continue
|
|
}
|
|
result[row.Cells[3].Value] = value
|
|
}
|
|
}
|
|
return result, nil
|
|
}
|