123456789101112131415161718192021222324252627282930313233343536 |
- package excel
- import (
- "fmt"
- "kpt-tmr-group/config"
- "kpt-tmr-group/model"
- "math/rand"
- "time"
- "github.com/gin-gonic/gin"
- "github.com/xuri/excelize/v2"
- )
- type SheetService interface {
- ExportToPath(params []map[string]string, data []map[string]interface{}, path string) (string, error)
- ExportToWeb(params []map[string]string, data []map[string]interface{}, c *gin.Context)
- writeTop(params []map[string]string)
- writeData(params []map[string]string, data []map[string]interface{})
- Export(params []map[string]string, data []map[string]interface{})
- }
- func createFile(cfg *config.AppConfig) *excelize.File {
- f := excelize.NewFile()
- // 创建一个默认工作表
- index, _ := f.NewSheet(cfg.ExcelSetting.SheetName)
- // 设置工作簿的默认工作表
- f.SetActiveSheet(index)
- return f
- }
- func createFileName() string {
- name := time.Now().Format(model.LayoutTime)
- rand.Seed(time.Now().UnixNano())
- return fmt.Sprintf("excle-%v-%v.xlsx", name, rand.Int63n(time.Now().Unix()))
- }
|