interface.go 992 B

123456789101112131415161718192021222324252627282930313233343536
  1. package excel
  2. import (
  3. "fmt"
  4. "kpt-tmr-group/config"
  5. "kpt-tmr-group/model"
  6. "math/rand"
  7. "time"
  8. "github.com/gin-gonic/gin"
  9. "github.com/xuri/excelize/v2"
  10. )
  11. type SheetService interface {
  12. ExportToPath(params []map[string]string, data []map[string]interface{}, path string) (string, error)
  13. ExportToWeb(params []map[string]string, data []map[string]interface{}, c *gin.Context)
  14. writeTop(params []map[string]string)
  15. writeData(params []map[string]string, data []map[string]interface{})
  16. Export(params []map[string]string, data []map[string]interface{})
  17. }
  18. func createFile(cfg *config.AppConfig) *excelize.File {
  19. f := excelize.NewFile()
  20. // 创建一个默认工作表
  21. index, _ := f.NewSheet(cfg.ExcelSetting.SheetName)
  22. // 设置工作簿的默认工作表
  23. f.SetActiveSheet(index)
  24. return f
  25. }
  26. func createFileName() string {
  27. name := time.Now().Format(model.LayoutTime)
  28. rand.Seed(time.Now().UnixNano())
  29. return fmt.Sprintf("excle-%v-%v.xlsx", name, rand.Int63n(time.Now().Unix()))
  30. }