github.com/easysoft/zendata@v0.0.0-20240513203326-705bd5a7fd67/cmd/test/others/func/import/name-cnfamily.go (about) 1 package main 2 3 import ( 4 "fmt" 5 6 "github.com/easysoft/zendata/cmd/test/others/func/comm" 7 "github.com/easysoft/zendata/cmd/test/others/func/model" 8 stringUtils "github.com/easysoft/zendata/pkg/utils/string" 9 ) 10 11 func main() { 12 filePath := "data/name/cn.family.v1.xlsx" 13 sheetName := "中文姓" 14 15 db := comm.GetDB() 16 db.Exec(fmt.Sprintf(comm.TruncateTable, model.DataChineseFamily{}.TableName())) 17 db.AutoMigrate( 18 &model.DataChineseFamily{}, 19 ) 20 21 records := comm.GetExcelTable(filePath, sheetName) 22 23 for _, record := range records { 24 po := model.DataChineseFamily{ 25 Name: record["name"].(string), 26 Pinyin: record["pinyin"].(string), 27 Double: stringUtils.ParseBool(record["double"].(string)), 28 } 29 30 db.Save(&po) 31 } 32 }