|
@@ -17,20 +17,27 @@ import (
|
|
|
|
|
|
var (
|
|
|
defaultExcelBorder = xlsx.Border{ //边框样式
|
|
|
- Left: "thin",
|
|
|
- LeftColor: "00A6A6A6",
|
|
|
- Right: "thin",
|
|
|
- RightColor: "00A6A6A6",
|
|
|
- Top: "thin",
|
|
|
- TopColor: "00A6A6A6",
|
|
|
- Bottom: "thin",
|
|
|
- BottomColor: "00A6A6A6",
|
|
|
+ Left: "dotted",
|
|
|
+ LeftColor: "00000000",
|
|
|
+ Right: "dotted",
|
|
|
+ RightColor: "00000000",
|
|
|
+ Top: "dotted",
|
|
|
+ TopColor: "00000000",
|
|
|
+ Bottom: "dotted",
|
|
|
+ BottomColor: "00000000",
|
|
|
}
|
|
|
+
|
|
|
defaultExcelAlignment = xlsx.Alignment{ //对其方式
|
|
|
- Horizontal: "center",
|
|
|
+ Horizontal: "left",
|
|
|
Vertical: "center",
|
|
|
WrapText: true,
|
|
|
}
|
|
|
+ defaultFont = xlsx.NewFont(12, "等线")
|
|
|
+ blueFont = xlsx.Font{
|
|
|
+ Size: 12,
|
|
|
+ Name: "等线",
|
|
|
+ Color: "00376092",
|
|
|
+ }
|
|
|
)
|
|
|
|
|
|
// 获取
|
|
@@ -58,9 +65,9 @@ func GetDataExportFileDataLen(path string) (int, error) {
|
|
|
|
|
|
// 生成数据导出excel
|
|
|
func CreateDataExportExcelFile(list *[]map[string]interface{}, isSenior bool, filePath string) error {
|
|
|
- if list == nil || len(*list) == 0 {
|
|
|
- return errors.New("未查询到数据")
|
|
|
- }
|
|
|
+ //if list == nil || len(*list) == 0 {
|
|
|
+ // return errors.New("未查询到数据")
|
|
|
+ //}
|
|
|
//创建excel文件
|
|
|
file := xlsx.NewFile()
|
|
|
sheet, err := file.AddSheet("Sheet1")
|
|
@@ -78,18 +85,20 @@ func CreateDataExportExcelFile(list *[]map[string]interface{}, isSenior bool, fi
|
|
|
for index, excel := range excelHead {
|
|
|
cell = row.AddCell()
|
|
|
cell.SetString(excel.Name)
|
|
|
- cell.SetStyle(&xlsx.Style{
|
|
|
+ style := &xlsx.Style{
|
|
|
Fill: *xlsx.NewFill("solid", excel.Color, excel.Color),
|
|
|
- Border: defaultExcelBorder,
|
|
|
Alignment: defaultExcelAlignment,
|
|
|
- })
|
|
|
+ Font: *defaultFont,
|
|
|
+ Border: defaultExcelBorder,
|
|
|
+ }
|
|
|
+ cell.SetStyle(style)
|
|
|
sheet.Col(index).Width = excel.Width
|
|
|
}
|
|
|
} else {
|
|
|
excelHead = config.ExConf.Senior_Fields
|
|
|
//铺设第一层title
|
|
|
row = sheet.AddRow()
|
|
|
- row.SetHeight(12)
|
|
|
+ row.SetHeight(20)
|
|
|
lastF := false //合并行时标识
|
|
|
for _, excel := range excelHead {
|
|
|
if excel.VMerge != 1 && excel.HMerge == 0 {
|
|
@@ -108,15 +117,17 @@ func CreateDataExportExcelFile(list *[]map[string]interface{}, isSenior bool, fi
|
|
|
if excel.HMerge != 0 {
|
|
|
lastF = true
|
|
|
}
|
|
|
- cell.SetStyle(&xlsx.Style{
|
|
|
+ style := &xlsx.Style{
|
|
|
Fill: *xlsx.NewFill("solid", excel.Color, excel.Color),
|
|
|
- Border: defaultExcelBorder,
|
|
|
Alignment: defaultExcelAlignment,
|
|
|
- })
|
|
|
+ Font: *defaultFont,
|
|
|
+ Border: defaultExcelBorder,
|
|
|
+ }
|
|
|
+ cell.SetStyle(style)
|
|
|
}
|
|
|
//铺设第二层title并设置宽度
|
|
|
row = sheet.AddRow()
|
|
|
- row.SetHeight(12)
|
|
|
+ row.SetHeight(20)
|
|
|
cNum := 0
|
|
|
for _, excel := range excelHead {
|
|
|
if excel.HMerge != 0 {
|
|
@@ -132,98 +143,103 @@ func CreateDataExportExcelFile(list *[]map[string]interface{}, isSenior bool, fi
|
|
|
Fill: *xlsx.NewFill("solid", excel.Color, excel.Color),
|
|
|
Border: defaultExcelBorder,
|
|
|
Alignment: defaultExcelAlignment,
|
|
|
+ Font: *defaultFont,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
- //填充数据
|
|
|
- for k, data := range *list {
|
|
|
- winnerMaps := gconv.Maps(data["winnerMaps"])
|
|
|
- winnerTotal := len(winnerMaps)
|
|
|
- data["index"] = k + 1
|
|
|
- if winnerTotal > 0 {
|
|
|
- for index, winnerDatas := range winnerMaps {
|
|
|
+ if list != nil && len(*list) > 0 {
|
|
|
+ //填充数据
|
|
|
+ for k, data := range *list {
|
|
|
+ winnerMaps := gconv.Maps(data["winnerMaps"])
|
|
|
+ winnerTotal := len(winnerMaps)
|
|
|
+ data["index"] = k + 1
|
|
|
+ if winnerTotal > 0 {
|
|
|
+ for index, winnerDatas := range winnerMaps {
|
|
|
+ row = sheet.AddRow()
|
|
|
+ row.SetHeight(20)
|
|
|
+
|
|
|
+ for _, v := range excelHead {
|
|
|
+ if v.Filed == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ cell = row.AddCell()
|
|
|
+ style := &xlsx.Style{
|
|
|
+ Border: defaultExcelBorder,
|
|
|
+ Alignment: defaultExcelAlignment,
|
|
|
+ }
|
|
|
+
|
|
|
+ if v.Filed != "legal_person" && v.Filed != "company_phone" && v.Filed != "company_email" && v.Filed != "company_name" {
|
|
|
+ if index == 0 {
|
|
|
+ cell.VMerge = winnerTotal - 1
|
|
|
+
|
|
|
+ if v.Filed == "title" || v.Filed == "url" {
|
|
|
+ cell.SetFormula(fmt.Sprintf("=HYPERLINK(\"%s\",\"%s\")", data["url_jump"], data[v.Filed]))
|
|
|
+ } else if v.Filed == "href" {
|
|
|
+ cell.SetFormula(fmt.Sprintf("=HYPERLINK(\"%s\",\"%s\")", data["href"], data[v.Filed]))
|
|
|
+ } else {
|
|
|
+ cell.SetValue(data[v.Filed])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ cell.SetValue(winnerDatas[v.Filed])
|
|
|
+ }
|
|
|
+ if v.Filed == "title" {
|
|
|
+ style.Font = blueFont
|
|
|
+ }
|
|
|
+ cell.SetStyle(style)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
row = sheet.AddRow()
|
|
|
- row.SetHeight(50)
|
|
|
+ row.SetHeight(20)
|
|
|
|
|
|
for _, v := range excelHead {
|
|
|
if v.Filed == "" {
|
|
|
continue
|
|
|
}
|
|
|
cell = row.AddCell()
|
|
|
-
|
|
|
- if v.Filed != "legal_person" && v.Filed != "company_phone" && v.Filed != "company_email" && v.Filed != "company_name" {
|
|
|
- if index == 0 {
|
|
|
- cell.VMerge = winnerTotal - 1
|
|
|
-
|
|
|
- if v.Filed == "title" || v.Filed == "url" {
|
|
|
- cell.SetFormula(fmt.Sprintf("=HYPERLINK(\"%s\",\"%s\")", data["url_jump"], data[v.Filed]))
|
|
|
- } else if v.Filed == "href" {
|
|
|
- cell.SetFormula(fmt.Sprintf("=HYPERLINK(\"%s\",\"%s\")", data["href"], data[v.Filed]))
|
|
|
- } else {
|
|
|
- cell.SetValue(data[v.Filed])
|
|
|
- }
|
|
|
- cell.SetStyle(&xlsx.Style{
|
|
|
- Border: defaultExcelBorder,
|
|
|
- Alignment: defaultExcelAlignment,
|
|
|
- })
|
|
|
- }
|
|
|
+ style := &xlsx.Style{
|
|
|
+ Border: defaultExcelBorder,
|
|
|
+ Alignment: defaultExcelAlignment,
|
|
|
+ }
|
|
|
+ if v.Filed == "title" || v.Filed == "url" {
|
|
|
+ cell.SetFormula(fmt.Sprintf("=HYPERLINK(\"%s\",\"%s\")", data["url_jump"], data[v.Filed]))
|
|
|
+ } else if v.Filed == "href" {
|
|
|
+ cell.SetFormula(fmt.Sprintf("=HYPERLINK(\"%s\",\"%s\")", data["href"], data[v.Filed]))
|
|
|
} else {
|
|
|
- cell.SetValue(winnerDatas[v.Filed])
|
|
|
- cell.SetStyle(&xlsx.Style{
|
|
|
- Border: defaultExcelBorder,
|
|
|
- Alignment: defaultExcelAlignment,
|
|
|
- })
|
|
|
+ cell.SetValue(data[v.Filed])
|
|
|
}
|
|
|
+ if v.Filed == "title" {
|
|
|
+ style.Font = blueFont
|
|
|
+ }
|
|
|
+ cell.SetStyle(style)
|
|
|
}
|
|
|
}
|
|
|
- } else {
|
|
|
- row = sheet.AddRow()
|
|
|
- row.SetHeight(50)
|
|
|
-
|
|
|
- for _, v := range excelHead {
|
|
|
- if v.Filed == "" {
|
|
|
- continue
|
|
|
- }
|
|
|
- cell = row.AddCell()
|
|
|
-
|
|
|
- if v.Filed == "title" || v.Filed == "url" {
|
|
|
- cell.SetFormula(fmt.Sprintf("=HYPERLINK(\"%s\",\"%s\")", data["url_jump"], data[v.Filed]))
|
|
|
- } else if v.Filed == "href" {
|
|
|
- cell.SetFormula(fmt.Sprintf("=HYPERLINK(\"%s\",\"%s\")", data["href"], data[v.Filed]))
|
|
|
- } else {
|
|
|
- cell.SetValue(data[v.Filed])
|
|
|
- }
|
|
|
-
|
|
|
- cell.SetStyle(&xlsx.Style{
|
|
|
- Border: defaultExcelBorder,
|
|
|
- Alignment: defaultExcelAlignment,
|
|
|
- })
|
|
|
- }
|
|
|
+ //row = sheet.AddRow()
|
|
|
+ //row.SetHeight(50)
|
|
|
+ //data["index"] = k + 1
|
|
|
+ //for _, v := range excelHead {
|
|
|
+ // if v.Filed == "" {
|
|
|
+ // continue
|
|
|
+ // }
|
|
|
+ // cell = row.AddCell()
|
|
|
+ //
|
|
|
+ // if v.Filed == "title" || v.Filed == "url" {
|
|
|
+ // cell.SetFormula(fmt.Sprintf("=HYPERLINK(\"%s\",\"%s\")", data["url_jump"], data[v.Filed]))
|
|
|
+ // } else if v.Filed == "href" {
|
|
|
+ // cell.SetFormula(fmt.Sprintf("=HYPERLINK(\"%s\",\"%s\")", data["href"], data[v.Filed]))
|
|
|
+ // } else {
|
|
|
+ // cell.SetValue(data[v.Filed])
|
|
|
+ // }
|
|
|
+ // cell.SetStyle(&xlsx.Style{
|
|
|
+ // Border: defaultExcelBorder,
|
|
|
+ // Alignment: defaultExcelAlignment,
|
|
|
+ // })
|
|
|
+ //}
|
|
|
+ }
|
|
|
+ if err := FolderCheck(filePath); err != nil {
|
|
|
+ return err
|
|
|
}
|
|
|
- //row = sheet.AddRow()
|
|
|
- //row.SetHeight(50)
|
|
|
- //data["index"] = k + 1
|
|
|
- //for _, v := range excelHead {
|
|
|
- // if v.Filed == "" {
|
|
|
- // continue
|
|
|
- // }
|
|
|
- // cell = row.AddCell()
|
|
|
- //
|
|
|
- // if v.Filed == "title" || v.Filed == "url" {
|
|
|
- // cell.SetFormula(fmt.Sprintf("=HYPERLINK(\"%s\",\"%s\")", data["url_jump"], data[v.Filed]))
|
|
|
- // } else if v.Filed == "href" {
|
|
|
- // cell.SetFormula(fmt.Sprintf("=HYPERLINK(\"%s\",\"%s\")", data["href"], data[v.Filed]))
|
|
|
- // } else {
|
|
|
- // cell.SetValue(data[v.Filed])
|
|
|
- // }
|
|
|
- // cell.SetStyle(&xlsx.Style{
|
|
|
- // Border: defaultExcelBorder,
|
|
|
- // Alignment: defaultExcelAlignment,
|
|
|
- // })
|
|
|
- //}
|
|
|
- }
|
|
|
- if err := FolderCheck(filePath); err != nil {
|
|
|
- return err
|
|
|
}
|
|
|
return file.Save(filePath)
|
|
|
}
|