package xlsx import ( "testing" "git.botann.com/lijun/xlsx/export" ) type Fen int type Data struct { Name string TotalInvest Fen `export:"true,x:2,y:3"` ProjectName string `export:"true,x:1,y:3"` CenterInvest Fen CityInvest Fen CompanyInvest Fen Partner string `export:"true,x:6,y:3"` ExData []ExData ExData2 ExData2 } type ExData struct { Col1 string Col2 string } type ExData2 struct { CenterInvest Fen `export:"true,x:3,y:3"` CityInvest Fen `export:"true,x:4,y:3"` CompanyInvest Fen `export:"true,x:5,y:3"` } func Test(t *testing.T) { title := []export.Title{ { Name: "项目名称", Location: export.Location{X: 1, Y: 1}, Colspan: 1, Rowspan: 0, }, { Name: "总投资", Location: export.Location{X: 2, Y: 1}, Colspan: 1, Rowspan: 0, }, { Name: "资金来源", Location: export.Location{X: 3, Y: 1}, Colspan: 0, Rowspan: 2, }, { Name: "中央", Location: export.Location{X: 3, Y: 2}, Colspan: 0, Rowspan: 0, }, { Name: "地方", Location: export.Location{X: 4, Y: 2}, Colspan: 0, Rowspan: 0, }, { Name: "公司", Location: export.Location{X: 5, Y: 2}, Colspan: 0, Rowspan: 0, }, { Name: "合作主体", Location: export.Location{X: 6, Y: 1}, Colspan: 1, Rowspan: 0, }, } data := []Data{ { Name: "测试数据1", TotalInvest: 10000, ProjectName: "项目1", CenterInvest: 2000, CityInvest: 2000, CompanyInvest: 6000, Partner: "公司1", ExData: []ExData{ {Col1: "test1", Col2: "test2"}, {Col1: "测试1", Col2: "测试2"}, }, ExData2: ExData2{ CenterInvest: 3000, CityInvest: 1500, CompanyInvest: 5500, }, }, { Name: "测试数据", TotalInvest: 8000, ProjectName: "项目2", CenterInvest: 2000, CityInvest: 2000, CompanyInvest: 4000, Partner: "公司2", ExData2: ExData2{ CenterInvest: 6200, CityInvest: 1200, CompanyInvest: 2600, }, }, } exporter := export.DefaultExporter() exporter.Data = &data exporter.Titles = title exporter.File = "test.xlsx" exporter.Path = "./" exporter.Export(0) }