# exceler **Repository Path**: joseelin/exceler ## Basic Information - **Project Name**: exceler - **Description**: golang excel data import & export - **Primary Language**: Go - **License**: CC-BY-4.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-04-08 - **Last Updated**: 2022-05-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Excel数据处理工具 ============ ### 安装 ```shell go get gitee.com/joseelin/exceler ``` ### 使用 ```go type Sample struct { Id int `comment:"编号"` Title string `comment:"标题"` } //导出模板头 func TestExportHeader(t *testing.T) { f := New() e := ExportHeader(f, &Sample{}) if e != nil { log.Fatalln(e) } file, e := os.Create("./bin/header.xlsx") if e != nil { log.Fatalln(e) } e = f.Write(file) if e != nil { log.Fatalln(e) } e = file.Close() if e != nil { log.Fatalln(e) } } //导出数据集 func TestExportData(t *testing.T) { f := New() a := []Sample{{1, "hello",},{2,""}} e := ExportData(f, &a) if e != nil { log.Fatalln(e) } file, e := os.Create("./bin/data.xlsx") if e != nil { log.Fatalln(e) } e = f.Write(file) if e != nil { log.Fatalln(e) } e = file.Close() if e != nil { log.Fatalln(e) } } //导入数据集 func TestImportData(t *testing.T) { f, e := excelize.OpenFile("./bin/data.xlsx") if e != nil { log.Fatalln(e) } var a []Sample e = ImportData(f, &a, 1, 2) if e != nil { log.Fatalln(e) } bt, _ := json.Marshal(a) t.Log(string(bt)) } ```