package xlsx import ( "testing" "time" "git.botann.com/lijun/xlsx/export" ) type CategoryReport struct { ProjectID int `json:"project_id"` ProjectName string `json:"project_name" export:"x:1,y:3"` ProjectUnit string `json:"project_unit" export:"x:2,y:3"` Developer string `json:"developer" export:"x:3,y:3"` Location string `json:"location" export:"x:4,y:3"` ProductionTime time.Time `json:"production_time" export:"x:5,y:3"` CompanyInvest int64 `json:"company_invest" export:"x:6,y:3"` Business []BusinessIndex `json:"business"` } type BusinessIndex struct { ProjectID int `json:"project_id"` IndexId int `json:"index_id"` Year int `json:"year"` Name string `json:"name"` Amount int64 `json:"amount" export:"x:7,y:3,loop:true"` Unit string `json:"unit"` } type BusinessIndexTotal struct { IndexId int `json:"index_id"` Name string `json:"name"` Amount int64 `json:"amount" export:"x:7,y:2,loop:true"` } type CategoryStatistics struct { Info Info `json:"info"` List []CategoryReport `json:"list"` } type Info struct { Total []BusinessIndexTotal `json:"total"` Title []BusinessIndex `json:"title"` } func TestMain(t *testing.T) { title := []export.Title{ { Name: "项目名称", Location: export.Location{X: 1, Y: 1}, }, { Name: "项目单位", Location: export.Location{X: 2, Y: 1}, }, { Name: "开发商", Location: export.Location{X: 3, Y: 1}, }, { Name: "位置", Location: export.Location{X: 4, Y: 1}, }, { Name: "生产时间", Location: export.Location{X: 5, Y: 1}, }, { Name: "公司投资", Location: export.Location{X: 6, Y: 1}, }, { Name: "生产规模", Location: export.Location{X: 7, Y: 1}, }, { Name: "权益规模", Location: export.Location{X: 8, Y: 1}, }, { Name: "总产量", Location: export.Location{X: 9, Y: 1}, }, { Name: "合计", Location: export.Location{X: 1, Y: 2}, Colspan: 6, }, } total := []BusinessIndexTotal{ {IndexId: 1, Name: "生产规模", Amount: 100}, {IndexId: 2, Name: "权益规模", Amount: 200}, {IndexId: 3, Name: "总产量", Amount: 300}, } report := []CategoryReport{ CategoryReport{ ProjectID: 1, ProjectName: "项目1", ProjectUnit: "单位1", Developer: "开发商1", Location: "位置1", ProductionTime: time.Now(), CompanyInvest: 1000, Business: []BusinessIndex{ {IndexId: 1, Name: "生产规模", Amount: 10, Unit: "吨"}, {IndexId: 2, Name: "权益规模", Amount: 20, Unit: "吨"}, {IndexId: 3, Name: "总产量", Amount: 30, Unit: "吨"}, }, }, CategoryReport{ ProjectID: 2, ProjectName: "项目2", ProjectUnit: "单位2", Developer: "开发商2", Location: "位置2", ProductionTime: time.Now(), CompanyInvest: 2000, Business: []BusinessIndex{ {IndexId: 1, Name: "生产规模", Amount: 20, Unit: "吨"}, {IndexId: 2, Name: "权益规模", Amount: 40, Unit: "吨"}, {IndexId: 3, Name: "总产量", Amount: 60, Unit: "吨"}, }, }, CategoryReport{ ProjectID: 3, ProjectName: "项目3", ProjectUnit: "单位3", Developer: "开发商3", Location: "位置3", ProductionTime: time.Now(), CompanyInvest: 3000, Business: []BusinessIndex{ {IndexId: 1, Name: "生产规模", Amount: 30, Unit: "吨"}, {IndexId: 2, Name: "权益规模", Amount: 60, Unit: "吨"}, {IndexId: 3, Name: "总产量", Amount: 90, Unit: "吨"}, }, }, } info := Info{ Total: total, } data := CategoryStatistics{ List: report, Info: info, } exporter := export.DefaultExporter() exporter.Titles = title exporter.Data = &data exporter.File = "test5.xlsx" exporter.Path = "./" exporter.Export(0) }