初始
This commit is contained in:
515
api/v1/common/coryCommon/excelUtil/excel.go
Normal file
515
api/v1/common/coryCommon/excelUtil/excel.go
Normal file
@ -0,0 +1,515 @@
|
||||
package excelUtil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/common/coryCommon"
|
||||
"github.com/tiger1103/gfast/v3/api/wxApplet/wxApplet"
|
||||
"github.com/xuri/excelize/v2"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ExcelOne 每条数据一个工作簿
|
||||
func ExcelOne(oneDateOneList []*wxApplet.PunchingCardRecordOne) (file string, filePath string, fileName string) {
|
||||
f := excelize.NewFile()
|
||||
defer func() {
|
||||
if err := f.Close(); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}()
|
||||
|
||||
for x, one := range oneDateOneList {
|
||||
itoa := strconv.Itoa(x + 1)
|
||||
// -----创建一个工作表
|
||||
_, err := f.NewSheet("Sheet" + itoa)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// -----表数据
|
||||
//设置1、2行高度
|
||||
err = f.SetRowHeight("Sheet"+itoa, 1, 36)
|
||||
err = f.SetRowHeight("Sheet"+itoa, 2, 14)
|
||||
//1、左侧固定 ABC的1~2
|
||||
f.SetCellValue("Sheet"+itoa, "A1", "序号")
|
||||
f.MergeCell("Sheet"+itoa, "A1", "A2")
|
||||
|
||||
f.SetCellValue("Sheet"+itoa, "B1", "姓名")
|
||||
f.MergeCell("Sheet"+itoa, "B1", "B2")
|
||||
|
||||
f.SetCellValue("Sheet"+itoa, "C1", "")
|
||||
f.MergeCell("Sheet"+itoa, "C1", "C2")
|
||||
//2、左侧固定 ABC的3~4
|
||||
f.SetCellValue("Sheet"+itoa, "A3", "1")
|
||||
f.MergeCell("Sheet"+itoa, "A3", "A4")
|
||||
|
||||
f.SetCellValue("Sheet"+itoa, "B3", one.Name)
|
||||
f.MergeCell("Sheet"+itoa, "B3", "B4")
|
||||
|
||||
f.SetCellValue("Sheet"+itoa, "C3", "打卡记录")
|
||||
f.SetCellValue("Sheet"+itoa, "C4", "工时")
|
||||
|
||||
//3、中间数据---------从4开始创建列
|
||||
var num = "0" //循环生成列
|
||||
var numInt = 1 //循环列对应的编号
|
||||
var numi = 0 //循环过后需要的列
|
||||
for i := 0; i < len(one.PunchCard); i++ {
|
||||
num = getColumnName(4 + i)
|
||||
f.SetCellValue("Sheet"+itoa, num+"2", numInt) //循环列对应的编号
|
||||
f.SetCellValue("Sheet"+itoa, num+"3", one.PunchCard[i].Clock) //循环生成列 时间
|
||||
f.SetCellValue("Sheet"+itoa, num+"4", one.PunchCard[i].Hour) //循环生成列 统计
|
||||
numi = 4 + i
|
||||
numInt = numInt + 1
|
||||
//最后一个总计
|
||||
if i == len(one.PunchCard)-1 {
|
||||
f.SetCellValue("Sheet"+itoa, num+"5", "总计") //循环生成列
|
||||
}
|
||||
}
|
||||
f.MergeCell("Sheet"+itoa, getColumnName(4)+"1", getColumnName(numi)+"1")
|
||||
f.SetCellValue("Sheet"+itoa, num+"1", "8月")
|
||||
|
||||
numi = numi + 1
|
||||
num = getColumnName(numi)
|
||||
//4、右侧不清楚
|
||||
f.SetCellValue("Sheet"+itoa, num+"1", "合计工时")
|
||||
f.SetCellValue("Sheet"+itoa, num+"4", one.SumHour)
|
||||
f.SetCellValue("Sheet"+itoa, num+"5", one.SumHour)
|
||||
f.MergeCell("Sheet"+itoa, num+"1", num+"2")
|
||||
|
||||
numi = numi + 1
|
||||
num = getColumnName(numi)
|
||||
f.SetCellValue("Sheet"+itoa, num+"1", "合计工天")
|
||||
f.SetCellValue("Sheet"+itoa, num+"4", one.SumDay)
|
||||
f.SetCellValue("Sheet"+itoa, num+"5", one.SumDay)
|
||||
f.MergeCell("Sheet"+itoa, num+"1", num+"2")
|
||||
|
||||
numi = numi + 1
|
||||
num = getColumnName(numi)
|
||||
f.SetCellValue("Sheet"+itoa, num+"1", "工人签名")
|
||||
f.MergeCell("Sheet"+itoa, num+"1", num+"2")
|
||||
|
||||
numi = numi + 1
|
||||
num = getColumnName(numi)
|
||||
f.SetCellValue("Sheet"+itoa, num+"1", "备注")
|
||||
f.MergeCell("Sheet"+itoa, num+"1", num+"2")
|
||||
}
|
||||
|
||||
// 设置工作簿的默认工作表
|
||||
f.SetActiveSheet(1)
|
||||
|
||||
// 根据指定路径保存文件
|
||||
str := FileName()
|
||||
filePath = coryCommon.Temporary + "/" + str
|
||||
getwd, err := os.Getwd()
|
||||
err = f.SaveAs(getwd + filePath)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return "", "", ""
|
||||
}
|
||||
return getwd + filePath, filePath, str
|
||||
}
|
||||
|
||||
// ExcelTwo 多条数据在一个工作簿
|
||||
func ExcelTwo(oneDateOneList []*wxApplet.PunchingCardRecordOne) (file string, filePath string, fileName string) {
|
||||
|
||||
f := excelize.NewFile()
|
||||
defer func() {
|
||||
if err := f.Close(); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}()
|
||||
|
||||
bottomStyleId, err := f.NewStyle(&excelize.Style{
|
||||
Border: []excelize.Border{
|
||||
{Type: "bottom", Color: "000000", Style: 1},
|
||||
//{Type: "diagonalDown", Color: "000000", Style: 5},
|
||||
//{Type: "diagonalUp", Color: "A020F0", Style: 6},
|
||||
},
|
||||
//背景
|
||||
Fill: excelize.Fill{
|
||||
Type: "pattern",
|
||||
Color: []string{"#e6ecf0"},
|
||||
Pattern: 1,
|
||||
},
|
||||
////字体
|
||||
//Font: &excelize.Font{
|
||||
// Color: "#ffffff", // 字体颜色,这里使用蓝色 (#0000FF)
|
||||
//},
|
||||
})
|
||||
|
||||
//全样式
|
||||
styleId, err := f.NewStyle(&excelize.Style{
|
||||
//边框
|
||||
Border: []excelize.Border{
|
||||
{Type: "left", Color: "000000", Style: 1},
|
||||
{Type: "top", Color: "000000", Style: 1},
|
||||
{Type: "bottom", Color: "000000", Style: 1},
|
||||
{Type: "right", Color: "000000", Style: 1},
|
||||
},
|
||||
//居中
|
||||
Alignment: &excelize.Alignment{
|
||||
Vertical: "center", // 上下居中
|
||||
Horizontal: "center", // 左右居中
|
||||
},
|
||||
//背景
|
||||
Fill: excelize.Fill{
|
||||
Type: "pattern",
|
||||
Color: []string{"#e6ecf0"},
|
||||
Pattern: 1,
|
||||
},
|
||||
////字体
|
||||
//Font: &excelize.Font{
|
||||
// Color: "#ffffff", // 字体颜色,这里使用蓝色 (#0000FF)
|
||||
//},
|
||||
})
|
||||
// 每组数据隔N行另起
|
||||
bookNum := 0
|
||||
for x, one := range oneDateOneList {
|
||||
if one.Name == "" {
|
||||
continue
|
||||
}
|
||||
itoa := "1" //第一个工作簿
|
||||
var num = "0" //循环生成列
|
||||
var numInt = 1 //循环列对应的编号
|
||||
var numi = 0 //循环过后需要的列
|
||||
for i := 0; i < len(one.PunchCard); i++ {
|
||||
//设置1、2行高度
|
||||
err := f.SetRowHeight("Sheet"+itoa, bookNum+1, 36)
|
||||
err = f.SetRowHeight("Sheet"+itoa, bookNum+2, 14)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
//1、左侧固定 ABC的1~2
|
||||
f.SetCellValue("Sheet"+itoa, "A"+strconv.Itoa((bookNum+1)), "序号")
|
||||
f.MergeCell("Sheet"+itoa, "A"+strconv.Itoa((bookNum+1)), "A"+strconv.Itoa((bookNum+2)))
|
||||
f.SetCellStyle("Sheet"+itoa, "A"+strconv.Itoa((bookNum+1)), "A"+strconv.Itoa((bookNum+2)), styleId)
|
||||
|
||||
f.SetCellValue("Sheet"+itoa, "B"+strconv.Itoa((bookNum+1)), "姓名")
|
||||
f.MergeCell("Sheet"+itoa, "B"+strconv.Itoa((bookNum+1)), "B"+strconv.Itoa((bookNum+2)))
|
||||
f.SetCellStyle("Sheet"+itoa, "B"+strconv.Itoa((bookNum+1)), "B"+strconv.Itoa((bookNum+2)), styleId)
|
||||
|
||||
f.SetCellValue("Sheet"+itoa, "C"+strconv.Itoa((bookNum+1)), "")
|
||||
f.MergeCell("Sheet"+itoa, "C"+strconv.Itoa((bookNum+1)), "C"+strconv.Itoa((bookNum+2)))
|
||||
f.SetCellStyle("Sheet"+itoa, "C"+strconv.Itoa((bookNum+1)), "C"+strconv.Itoa((bookNum+2)), styleId)
|
||||
//2、左侧固定 ABC的3~4
|
||||
f.SetCellValue("Sheet"+itoa, "A"+strconv.Itoa((bookNum+3)), x+1)
|
||||
f.MergeCell("Sheet"+itoa, "A"+strconv.Itoa((bookNum+3)), "A"+strconv.Itoa((bookNum+4)))
|
||||
f.SetCellStyle("Sheet"+itoa, "A"+strconv.Itoa((bookNum+3)), "A"+strconv.Itoa((bookNum+4)), styleId)
|
||||
|
||||
f.SetCellValue("Sheet"+itoa, "B"+strconv.Itoa((bookNum+3)), one.Name)
|
||||
f.MergeCell("Sheet"+itoa, "B"+strconv.Itoa((bookNum+3)), "B"+strconv.Itoa((bookNum+4)))
|
||||
f.SetCellStyle("Sheet"+itoa, "B"+strconv.Itoa((bookNum+3)), "B"+strconv.Itoa((bookNum+4)), styleId)
|
||||
|
||||
//f.SetCellValue("Sheet"+itoa, "c"+strconv.Itoa((bookNum+3)), "打卡记录")
|
||||
f.SetCellValue("Sheet"+itoa, "c"+strconv.Itoa((bookNum+3)), "工时")
|
||||
f.MergeCell("Sheet"+itoa, "c"+strconv.Itoa((bookNum+3)), "c"+strconv.Itoa((bookNum+4)))
|
||||
f.SetCellStyle("Sheet"+itoa, "c"+strconv.Itoa((bookNum+3)), "c"+strconv.Itoa((bookNum+4)), styleId)
|
||||
|
||||
//3、中间数据---------从4开始创建列
|
||||
num = getColumnName(4 + i)
|
||||
f.SetCellValue("Sheet"+itoa, num+strconv.Itoa((bookNum+2)), numInt) //循环列对应的编号
|
||||
f.SetCellStyle("Sheet"+itoa, num+strconv.Itoa((bookNum+2)), num+strconv.Itoa((bookNum+2)), styleId) //循环列对应的编号
|
||||
f.SetCellValue("Sheet"+itoa, num+strconv.Itoa((bookNum+3)), one.PunchCard[i].Clock) //循环生成列 时间
|
||||
f.SetCellStyle("Sheet"+itoa, num+strconv.Itoa((bookNum+3)), num+strconv.Itoa((bookNum+3)), styleId) //循环生成列 时间
|
||||
f.SetCellValue("Sheet"+itoa, num+strconv.Itoa((bookNum+4)), one.PunchCard[i].Hour) //循环生成列 统计
|
||||
f.SetCellStyle("Sheet"+itoa, num+strconv.Itoa((bookNum+4)), num+strconv.Itoa((bookNum+4)), styleId) //循环生成列 统计
|
||||
numi = 4 + i
|
||||
numInt = numInt + 1
|
||||
//最后一个总计
|
||||
if i == len(one.PunchCard)-1 {
|
||||
f.SetCellValue("Sheet"+itoa, num+strconv.Itoa((bookNum+5)), "总计") //循环生成列
|
||||
f.SetCellStyle("Sheet"+itoa, num+strconv.Itoa((bookNum+5)), "总计", styleId) //循环生成列
|
||||
}
|
||||
}
|
||||
f.SetCellValue("Sheet"+itoa, "D"+strconv.Itoa((bookNum+1)), one.Years)
|
||||
f.MergeCell("Sheet"+itoa, getColumnName(4)+strconv.Itoa(bookNum+1), getColumnName(numi)+strconv.Itoa(bookNum+1))
|
||||
f.SetCellStyle("Sheet"+itoa, getColumnName(4)+strconv.Itoa(bookNum+1), getColumnName(numi)+strconv.Itoa(bookNum+1), styleId)
|
||||
|
||||
numi = numi + 1
|
||||
num = getColumnName(numi)
|
||||
//4、右侧不清楚
|
||||
f.SetCellValue("Sheet"+itoa, num+strconv.Itoa((bookNum+1)), "合计工时")
|
||||
f.MergeCell("Sheet"+itoa, num+strconv.Itoa(bookNum+1), getColumnName(numi)+strconv.Itoa(bookNum+3))
|
||||
f.SetCellStyle("Sheet"+itoa, num+strconv.Itoa(bookNum+1), getColumnName(numi)+strconv.Itoa(bookNum+3), styleId)
|
||||
|
||||
f.SetCellValue("Sheet"+itoa, num+strconv.Itoa((bookNum+4)), one.SumHour)
|
||||
f.MergeCell("Sheet"+itoa, num+strconv.Itoa(bookNum+4), getColumnName(numi)+strconv.Itoa(bookNum+4))
|
||||
f.SetCellStyle("Sheet"+itoa, num+strconv.Itoa(bookNum+4), getColumnName(numi)+strconv.Itoa(bookNum+4), styleId)
|
||||
|
||||
f.SetCellValue("Sheet"+itoa, num+strconv.Itoa((bookNum+5)), one.SumHour)
|
||||
f.MergeCell("Sheet"+itoa, num+strconv.Itoa(bookNum+5), getColumnName(numi)+strconv.Itoa(bookNum+5))
|
||||
f.SetCellStyle("Sheet"+itoa, num+strconv.Itoa(bookNum+5), getColumnName(numi)+strconv.Itoa(bookNum+5), styleId)
|
||||
|
||||
numi = numi + 1
|
||||
num = getColumnName(numi)
|
||||
f.SetCellValue("Sheet"+itoa, num+strconv.Itoa((bookNum+1)), "合计工天")
|
||||
f.MergeCell("Sheet"+itoa, num+strconv.Itoa(bookNum+1), getColumnName(numi)+strconv.Itoa(bookNum+3))
|
||||
f.SetCellStyle("Sheet"+itoa, num+strconv.Itoa(bookNum+1), getColumnName(numi)+strconv.Itoa(bookNum+3), styleId)
|
||||
|
||||
f.SetCellValue("Sheet"+itoa, num+strconv.Itoa((bookNum+4)), one.SumDay)
|
||||
f.MergeCell("Sheet"+itoa, num+strconv.Itoa(bookNum+4), getColumnName(numi)+strconv.Itoa(bookNum+4))
|
||||
f.SetCellStyle("Sheet"+itoa, num+strconv.Itoa(bookNum+4), getColumnName(numi)+strconv.Itoa(bookNum+4), styleId)
|
||||
|
||||
f.SetCellValue("Sheet"+itoa, num+strconv.Itoa((bookNum+5)), one.SumDay)
|
||||
f.MergeCell("Sheet"+itoa, num+strconv.Itoa(bookNum+5), getColumnName(numi)+strconv.Itoa(bookNum+5))
|
||||
f.SetCellStyle("Sheet"+itoa, num+strconv.Itoa(bookNum+5), getColumnName(numi)+strconv.Itoa(bookNum+5), styleId)
|
||||
|
||||
numi = numi + 1
|
||||
num = getColumnName(numi)
|
||||
f.SetCellValue("Sheet"+itoa, num+strconv.Itoa((bookNum+1)), "工人签名")
|
||||
f.MergeCell("Sheet"+itoa, num+strconv.Itoa((bookNum+1)), num+strconv.Itoa((bookNum+3)))
|
||||
f.SetCellStyle("Sheet"+itoa, num+strconv.Itoa((bookNum+1)), num+strconv.Itoa((bookNum+3)), styleId)
|
||||
|
||||
f.SetCellValue("Sheet"+itoa, num+strconv.Itoa((bookNum+4)), "")
|
||||
f.MergeCell("Sheet"+itoa, num+strconv.Itoa((bookNum+4)), num+strconv.Itoa((bookNum+5)))
|
||||
f.SetCellStyle("Sheet"+itoa, num+strconv.Itoa((bookNum+4)), num+strconv.Itoa((bookNum+5)), styleId)
|
||||
|
||||
numi = numi + 1
|
||||
num = getColumnName(numi)
|
||||
f.SetCellValue("Sheet"+itoa, num+strconv.Itoa((bookNum+1)), "备注")
|
||||
f.MergeCell("Sheet"+itoa, num+strconv.Itoa((bookNum+1)), num+strconv.Itoa((bookNum+3)))
|
||||
f.SetCellStyle("Sheet"+itoa, num+strconv.Itoa((bookNum+1)), num+strconv.Itoa((bookNum+3)), styleId)
|
||||
|
||||
f.SetCellValue("Sheet"+itoa, num+strconv.Itoa((bookNum+4)), "")
|
||||
f.MergeCell("Sheet"+itoa, num+strconv.Itoa((bookNum+4)), num+strconv.Itoa((bookNum+5)))
|
||||
f.SetCellStyle("Sheet"+itoa, num+strconv.Itoa((bookNum+4)), num+strconv.Itoa((bookNum+5)), styleId)
|
||||
|
||||
f.SetCellStyle("Sheet"+itoa, "A"+strconv.Itoa((bookNum+5)), getColumnName(numi-4)+strconv.Itoa((bookNum+5)), bottomStyleId)
|
||||
|
||||
bookNum = bookNum + 10
|
||||
}
|
||||
|
||||
// 设置工作簿的默认工作表
|
||||
f.SetActiveSheet(1)
|
||||
|
||||
// 根据指定路径保存文件
|
||||
str := FileName()
|
||||
filePath = coryCommon.Temporary + "/" + str
|
||||
getwd, err := os.Getwd()
|
||||
err = f.SaveAs(getwd + filePath)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return "", "", ""
|
||||
}
|
||||
return getwd + filePath, filePath, str
|
||||
}
|
||||
|
||||
// ExcelThree 多个工作簿,每个工作簿有多条数据
|
||||
func ExcelThree(gey []*wxApplet.GroupEntity) (file string, filePath string, fileName string) {
|
||||
f := excelize.NewFile()
|
||||
defer func() {
|
||||
if err := f.Close(); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}()
|
||||
|
||||
bottomStyleId, err := f.NewStyle(&excelize.Style{
|
||||
Border: []excelize.Border{
|
||||
{Type: "bottom", Color: "000000", Style: 1},
|
||||
//{Type: "diagonalDown", Color: "000000", Style: 5},
|
||||
//{Type: "diagonalUp", Color: "A020F0", Style: 6},
|
||||
},
|
||||
//背景
|
||||
Fill: excelize.Fill{
|
||||
Type: "pattern",
|
||||
Color: []string{"#e6ecf0"},
|
||||
Pattern: 1,
|
||||
},
|
||||
////字体
|
||||
//Font: &excelize.Font{
|
||||
// Color: "#ffffff", // 字体颜色,这里使用蓝色 (#0000FF)
|
||||
//},
|
||||
})
|
||||
|
||||
//全样式
|
||||
styleId, err := f.NewStyle(&excelize.Style{
|
||||
//边框
|
||||
Border: []excelize.Border{
|
||||
{Type: "left", Color: "000000", Style: 1},
|
||||
{Type: "top", Color: "000000", Style: 1},
|
||||
{Type: "bottom", Color: "000000", Style: 1},
|
||||
{Type: "right", Color: "000000", Style: 1},
|
||||
},
|
||||
//居中
|
||||
Alignment: &excelize.Alignment{
|
||||
Vertical: "center", // 上下居中
|
||||
Horizontal: "center", // 左右居中
|
||||
},
|
||||
//背景
|
||||
Fill: excelize.Fill{
|
||||
Type: "pattern",
|
||||
Color: []string{"#e6ecf0"},
|
||||
Pattern: 1,
|
||||
},
|
||||
////字体
|
||||
//Font: &excelize.Font{
|
||||
// Color: "#ffffff", // 字体颜色,这里使用蓝色 (#0000FF)
|
||||
//},
|
||||
})
|
||||
|
||||
//工作簿
|
||||
for _, data := range gey {
|
||||
//itoa := strconv.Itoa(y + 1)
|
||||
itoa := data.GroupName
|
||||
_, err = f.NewSheet(itoa)
|
||||
|
||||
oneDateOneList := data.PunchingCardRecordOne
|
||||
//工作簿里面的数据
|
||||
bookNum := 0 // 每组数据隔N行另起
|
||||
for x, one := range oneDateOneList {
|
||||
//itoa := "1" //第一个工作簿
|
||||
var num = "0" //循环生成列
|
||||
var numInt = 1 //循环列对应的编号
|
||||
var numi = 0 //循环过后需要的列
|
||||
for i := 0; i < len(one.PunchCard); i++ {
|
||||
//设置1、2行高度
|
||||
err := f.SetRowHeight(itoa, bookNum+1, 36)
|
||||
err = f.SetRowHeight(itoa, bookNum+2, 14)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
//1、左侧固定 ABC的1~2
|
||||
f.SetCellValue(itoa, "A"+strconv.Itoa((bookNum+1)), "序号")
|
||||
f.MergeCell(itoa, "A"+strconv.Itoa((bookNum+1)), "A"+strconv.Itoa((bookNum+2)))
|
||||
f.SetCellStyle(itoa, "A"+strconv.Itoa((bookNum+1)), "A"+strconv.Itoa((bookNum+2)), styleId)
|
||||
|
||||
f.SetCellValue(itoa, "B"+strconv.Itoa((bookNum+1)), "姓名")
|
||||
f.MergeCell(itoa, "B"+strconv.Itoa((bookNum+1)), "B"+strconv.Itoa((bookNum+2)))
|
||||
f.SetCellStyle(itoa, "B"+strconv.Itoa((bookNum+1)), "B"+strconv.Itoa((bookNum+2)), styleId)
|
||||
|
||||
f.SetCellValue(itoa, "C"+strconv.Itoa((bookNum+1)), "")
|
||||
f.MergeCell(itoa, "C"+strconv.Itoa((bookNum+1)), "C"+strconv.Itoa((bookNum+2)))
|
||||
f.SetCellStyle(itoa, "C"+strconv.Itoa((bookNum+1)), "C"+strconv.Itoa((bookNum+2)), styleId)
|
||||
//2、左侧固定 ABC的3~4
|
||||
f.SetCellValue(itoa, "A"+strconv.Itoa((bookNum+3)), x+1)
|
||||
f.MergeCell(itoa, "A"+strconv.Itoa((bookNum+3)), "A"+strconv.Itoa((bookNum+4)))
|
||||
f.SetCellStyle(itoa, "A"+strconv.Itoa((bookNum+3)), "A"+strconv.Itoa((bookNum+4)), styleId)
|
||||
|
||||
f.SetCellValue(itoa, "B"+strconv.Itoa((bookNum+3)), one.Name)
|
||||
f.MergeCell(itoa, "B"+strconv.Itoa((bookNum+3)), "B"+strconv.Itoa((bookNum+4)))
|
||||
f.SetCellStyle(itoa, "B"+strconv.Itoa((bookNum+3)), "B"+strconv.Itoa((bookNum+4)), styleId)
|
||||
|
||||
//f.SetCellValue(itoa, "c"+strconv.Itoa((bookNum+3)), "打卡记录")
|
||||
f.SetCellValue(itoa, "c"+strconv.Itoa((bookNum+3)), "工时")
|
||||
f.MergeCell(itoa, "c"+strconv.Itoa((bookNum+3)), "c"+strconv.Itoa((bookNum+4)))
|
||||
f.SetCellStyle(itoa, "c"+strconv.Itoa((bookNum+3)), "c"+strconv.Itoa((bookNum+4)), styleId)
|
||||
|
||||
//3、中间数据---------从4开始创建列
|
||||
num = getColumnName(4 + i)
|
||||
f.SetCellValue(itoa, num+strconv.Itoa((bookNum+2)), numInt) //循环列对应的编号
|
||||
f.SetCellStyle(itoa, num+strconv.Itoa((bookNum+2)), num+strconv.Itoa((bookNum+2)), styleId) //循环列对应的编号
|
||||
f.SetCellValue(itoa, num+strconv.Itoa((bookNum+3)), one.PunchCard[i].Clock) //循环生成列 时间
|
||||
f.SetCellStyle(itoa, num+strconv.Itoa((bookNum+3)), num+strconv.Itoa((bookNum+3)), styleId) //循环生成列 时间
|
||||
f.SetCellValue(itoa, num+strconv.Itoa((bookNum+4)), one.PunchCard[i].Hour) //循环生成列 统计
|
||||
f.SetCellStyle(itoa, num+strconv.Itoa((bookNum+4)), num+strconv.Itoa((bookNum+4)), styleId) //循环生成列 统计
|
||||
numi = 4 + i
|
||||
numInt = numInt + 1
|
||||
//最后一个总计
|
||||
if i == len(one.PunchCard)-1 {
|
||||
f.SetCellValue(itoa, num+strconv.Itoa((bookNum+5)), "总计") //循环生成列
|
||||
f.SetCellStyle(itoa, num+strconv.Itoa((bookNum+5)), "总计", styleId) //循环生成列
|
||||
}
|
||||
}
|
||||
f.SetCellValue(itoa, "D"+strconv.Itoa((bookNum+1)), one.Years)
|
||||
f.MergeCell(itoa, getColumnName(4)+strconv.Itoa(bookNum+1), getColumnName(numi)+strconv.Itoa(bookNum+1))
|
||||
f.SetCellStyle(itoa, getColumnName(4)+strconv.Itoa(bookNum+1), getColumnName(numi)+strconv.Itoa(bookNum+1), styleId)
|
||||
|
||||
numi = numi + 1
|
||||
num = getColumnName(numi)
|
||||
//4、右侧不清楚
|
||||
f.SetCellValue(itoa, num+strconv.Itoa((bookNum+1)), "合计工时")
|
||||
f.MergeCell(itoa, num+strconv.Itoa(bookNum+1), getColumnName(numi)+strconv.Itoa(bookNum+3))
|
||||
f.SetCellStyle(itoa, num+strconv.Itoa(bookNum+1), getColumnName(numi)+strconv.Itoa(bookNum+3), styleId)
|
||||
|
||||
f.SetCellValue(itoa, num+strconv.Itoa((bookNum+4)), one.SumHour)
|
||||
f.MergeCell(itoa, num+strconv.Itoa(bookNum+4), getColumnName(numi)+strconv.Itoa(bookNum+4))
|
||||
f.SetCellStyle(itoa, num+strconv.Itoa(bookNum+4), getColumnName(numi)+strconv.Itoa(bookNum+4), styleId)
|
||||
|
||||
f.SetCellValue(itoa, num+strconv.Itoa((bookNum+5)), one.SumHour)
|
||||
f.MergeCell(itoa, num+strconv.Itoa(bookNum+5), getColumnName(numi)+strconv.Itoa(bookNum+5))
|
||||
f.SetCellStyle(itoa, num+strconv.Itoa(bookNum+5), getColumnName(numi)+strconv.Itoa(bookNum+5), styleId)
|
||||
|
||||
numi = numi + 1
|
||||
num = getColumnName(numi)
|
||||
f.SetCellValue(itoa, num+strconv.Itoa((bookNum+1)), "合计工天")
|
||||
f.MergeCell(itoa, num+strconv.Itoa(bookNum+1), getColumnName(numi)+strconv.Itoa(bookNum+3))
|
||||
f.SetCellStyle(itoa, num+strconv.Itoa(bookNum+1), getColumnName(numi)+strconv.Itoa(bookNum+3), styleId)
|
||||
|
||||
f.SetCellValue(itoa, num+strconv.Itoa((bookNum+4)), one.SumDay)
|
||||
f.MergeCell(itoa, num+strconv.Itoa(bookNum+4), getColumnName(numi)+strconv.Itoa(bookNum+4))
|
||||
f.SetCellStyle(itoa, num+strconv.Itoa(bookNum+4), getColumnName(numi)+strconv.Itoa(bookNum+4), styleId)
|
||||
|
||||
f.SetCellValue(itoa, num+strconv.Itoa((bookNum+5)), one.SumDay)
|
||||
f.MergeCell(itoa, num+strconv.Itoa(bookNum+5), getColumnName(numi)+strconv.Itoa(bookNum+5))
|
||||
f.SetCellStyle(itoa, num+strconv.Itoa(bookNum+5), getColumnName(numi)+strconv.Itoa(bookNum+5), styleId)
|
||||
|
||||
numi = numi + 1
|
||||
num = getColumnName(numi)
|
||||
f.SetCellValue(itoa, num+strconv.Itoa((bookNum+1)), "工人签名")
|
||||
f.MergeCell(itoa, num+strconv.Itoa((bookNum+1)), num+strconv.Itoa((bookNum+3)))
|
||||
f.SetCellStyle(itoa, num+strconv.Itoa((bookNum+1)), num+strconv.Itoa((bookNum+3)), styleId)
|
||||
|
||||
f.SetCellValue(itoa, num+strconv.Itoa((bookNum+4)), "")
|
||||
f.MergeCell(itoa, num+strconv.Itoa((bookNum+4)), num+strconv.Itoa((bookNum+5)))
|
||||
f.SetCellStyle(itoa, num+strconv.Itoa((bookNum+4)), num+strconv.Itoa((bookNum+5)), styleId)
|
||||
|
||||
numi = numi + 1
|
||||
num = getColumnName(numi)
|
||||
f.SetCellValue(itoa, num+strconv.Itoa((bookNum+1)), "备注")
|
||||
f.MergeCell(itoa, num+strconv.Itoa((bookNum+1)), num+strconv.Itoa((bookNum+3)))
|
||||
f.SetCellStyle(itoa, num+strconv.Itoa((bookNum+1)), num+strconv.Itoa((bookNum+3)), styleId)
|
||||
|
||||
f.SetCellValue(itoa, num+strconv.Itoa((bookNum+4)), "")
|
||||
f.MergeCell(itoa, num+strconv.Itoa((bookNum+4)), num+strconv.Itoa((bookNum+5)))
|
||||
f.SetCellStyle(itoa, num+strconv.Itoa((bookNum+4)), num+strconv.Itoa((bookNum+5)), styleId)
|
||||
|
||||
f.SetCellStyle(itoa, "A"+strconv.Itoa((bookNum+5)), getColumnName(numi-4)+strconv.Itoa((bookNum+5)), bottomStyleId)
|
||||
|
||||
//err = f.SetCellStyle("Sheet1", "A"+strconv.Itoa((bookNum+1)), "A"+strconv.Itoa((bookNum+5)), leftStyleId)
|
||||
//err = f.SetCellStyle("Sheet1", "I"+strconv.Itoa((bookNum+1)), "I"+strconv.Itoa((bookNum+5)), rightStyleId)
|
||||
//err = f.SetCellStyle("Sheet1", "A"+strconv.Itoa((bookNum+1)), "I"+strconv.Itoa((bookNum+1)), topStyleId)
|
||||
//err = f.SetCellStyle("Sheet1", "A"+strconv.Itoa((bookNum+5)), "I"+strconv.Itoa((bookNum+5)), bottomStyleId)
|
||||
|
||||
bookNum = bookNum + 10
|
||||
}
|
||||
}
|
||||
|
||||
// 设置工作簿的默认工作表
|
||||
f.SetActiveSheet(1)
|
||||
|
||||
// 根据指定路径保存文件
|
||||
str := FileName()
|
||||
filePath = coryCommon.Temporary + "/" + str
|
||||
getwd, err := os.Getwd()
|
||||
err = f.SaveAs(getwd + filePath)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return "", "", ""
|
||||
}
|
||||
return getwd + filePath, filePath, str
|
||||
}
|
||||
|
||||
// 根据列索引获取列的字母标识 比如1就是A 30就是AD
|
||||
func getColumnName(index int) string {
|
||||
var columnName string
|
||||
for index > 0 {
|
||||
mod := (index - 1) % 26
|
||||
columnName = string('A'+mod) + columnName
|
||||
index = (index - 1) / 26
|
||||
}
|
||||
return columnName
|
||||
}
|
||||
|
||||
// FileName 生成时间戳文件名
|
||||
func FileName() (str string) {
|
||||
// 获取当前时间
|
||||
currentTime := time.Now()
|
||||
// 格式化时间戳为字符串
|
||||
timestamp := currentTime.Format("20060102150405")
|
||||
// 生成文件名
|
||||
fileName := fmt.Sprintf("zm_%s.xlsx", timestamp)
|
||||
return fileName
|
||||
}
|
55
api/v1/common/coryCommon/excelUtil/excelEntity.go
Normal file
55
api/v1/common/coryCommon/excelUtil/excelEntity.go
Normal file
@ -0,0 +1,55 @@
|
||||
package excelUtil
|
||||
|
||||
type Style struct {
|
||||
Border []Border
|
||||
Fill Fill
|
||||
Font *Font
|
||||
Alignment *Alignment
|
||||
Protection *Protection
|
||||
NumFmt int
|
||||
DecimalPlaces int
|
||||
CustomNumFmt *string
|
||||
NegRed bool
|
||||
}
|
||||
|
||||
type Fill struct {
|
||||
Type string
|
||||
Pattern int
|
||||
Color []string
|
||||
Shading int
|
||||
}
|
||||
|
||||
type Protection struct {
|
||||
Hidden bool
|
||||
Locked bool
|
||||
}
|
||||
|
||||
type Font struct {
|
||||
Bold bool
|
||||
Italic bool
|
||||
Underline string
|
||||
Family string
|
||||
Size float64
|
||||
Strike bool
|
||||
Color string
|
||||
ColorIndexed int
|
||||
ColorTheme *int
|
||||
ColorTint float64
|
||||
VertAlign string
|
||||
}
|
||||
type Border struct {
|
||||
Type string
|
||||
Color string
|
||||
Style int
|
||||
}
|
||||
type Alignment struct {
|
||||
Horizontal string
|
||||
Indent int
|
||||
JustifyLastLine bool
|
||||
ReadingOrder uint64
|
||||
RelativeIndent int
|
||||
ShrinkToFit bool
|
||||
TextRotation int
|
||||
Vertical string
|
||||
WrapText bool
|
||||
}
|
Reference in New Issue
Block a user