xlsx/export2_test.go

116 lines
2.0 KiB
Go

package xlsx
import (
"testing"
"git.botann.com/lijun/xlsx/export"
)
type Data2 struct {
Name string
ProjectName string `export:"true,x:1,y:2,rowspan:3"`
TotalInvest int `export:"true,x:2,y:2,rowspan:3"`
Partner string `export:"true,x:3,y:2,rowspan:3"`
Radio []InvestRadio
}
type InvestRadio struct {
Name string `export:"true,x:4,y:2"`
Invest int `export:"true,x:5,y:2"`
}
type ExDataEx struct {
Name string
Invest int
}
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},
Colspan: 2,
},
}
data := []Data2{
{
Name: "项目1",
ProjectName: "项目1",
TotalInvest: 100,
Partner: "合作主体1",
Radio: []InvestRadio{
{
Name: "1合作主体1",
Invest: 10,
},
{
Name: "1合作主体2",
Invest: 20,
},
{
Name: "1合作主体3",
Invest: 30,
},
},
},
{
Name: "项目2",
ProjectName: "项目2",
TotalInvest: 200,
Partner: "合作主体2",
Radio: []InvestRadio{
{
Name: "2合作主体1",
Invest: 10,
},
{
Name: "2合作主体2",
Invest: 20,
},
{
Name: "2合作主体3",
Invest: 30,
},
},
},
{
Name: "项目3",
ProjectName: "项目3",
TotalInvest: 200,
Partner: "合作主体3",
Radio: []InvestRadio{
{
Name: "3合作主体1",
Invest: 10,
},
{
Name: "3合作主体2",
Invest: 20,
},
{
Name: "3合作主体3",
Invest: 30,
},
},
},
}
exporter := export.DefaultExporter()
exporter.Titles = title
exporter.Data = &data
exporter.File = "test2.xlsx"
exporter.Path = "./"
exporter.Export(0)
}