提交 3b100f1c 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

import data from excel

上级 1d4db7dc
package main
import (
"fmt"
"github.com/easysoft/zendata/src/test/import/comm"
"github.com/easysoft/zendata/src/test/import/model"
stringUtils "github.com/easysoft/zendata/src/utils/string"
)
func main() {
filePath := "data/name/cn.family.v1.xlsx"
sheetName := "中文姓"
db := comm.GetDB()
db.Exec(fmt.Sprintf(comm.TruncateTable, model.DataChineseFamily{}.TableName()))
db.AutoMigrate(
&model.DataChineseFamily{},
)
records := comm.GetExcelTable(filePath, sheetName)
for _, record := range records {
po := model.DataChineseFamily{
Name: record["name"].(string),
Pinyin: record["pinyin"].(string),
Double: stringUtils.ParseBool(record["double"].(string)),
}
db.Save(&po)
}
}
package main
import (
"fmt"
"github.com/easysoft/zendata/src/test/import/comm"
"github.com/easysoft/zendata/src/test/import/model"
)
func main() {
filePath := "data/name/cn.given.v1.xlsx"
sheetName := "中文名"
db := comm.GetDB()
db.Exec(fmt.Sprintf(comm.TruncateTable, model.DataChineseGiven{}.TableName()))
db.AutoMigrate(
&model.DataChineseGiven{},
)
records := comm.GetExcelTable(filePath, sheetName)
for _, record := range records {
po := model.DataChineseGiven{
Name: record["name"].(string),
Pinyin: record["pinyin"].(string),
Sex: record["sex"].(string),
}
db.Save(&po)
}
}
package main
import (
"fmt"
"github.com/easysoft/zendata/src/test/import/comm"
"github.com/easysoft/zendata/src/test/import/model"
)
func main() {
filePath := "data/name/en.family.v1.xlsx"
sheetName := "英文姓"
db := comm.GetDB()
db.Exec(fmt.Sprintf(comm.TruncateTable, model.DataEnglishFamily{}.TableName()))
db.AutoMigrate(
&model.DataEnglishFamily{},
)
records := comm.GetExcelTable(filePath, sheetName)
for _, record := range records {
po := model.DataEnglishFamily{
Name: record["name"].(string),
Index: record["index"].(string),
}
db.Save(&po)
}
}
package main
import (
"fmt"
"github.com/easysoft/zendata/src/test/import/comm"
"github.com/easysoft/zendata/src/test/import/model"
)
func main() {
filePath := "data/name/en.given.v1.xlsx"
sheetName := "英文名"
db := comm.GetDB()
db.Exec(fmt.Sprintf(comm.TruncateTable, model.DataEnglishGiven{}.TableName()))
db.AutoMigrate(
&model.DataEnglishGiven{},
)
records := comm.GetExcelTable(filePath, sheetName)
for _, record := range records {
po := model.DataEnglishGiven{
Name: record["name"].(string),
Index: record["index"].(string),
Sex: record["sex"].(string),
}
db.Save(&po)
}
}
......@@ -82,7 +82,7 @@ type DataChineseFamily struct {
Name string `json:"name"`
Pinyin string `json:"pinyin"`
Double string `json:"double"`
Double bool `json:"double"`
}
func (DataChineseFamily) TableName() string {
......
......@@ -294,3 +294,8 @@ func ParseInt(str string) (ret int) {
return
}
func ParseBool(str string) (ret bool) {
ret, _ = strconv.ParseBool(str)
return
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册