golang excel 导出功能

package myutils

import (
   "feinail/app/config"
   "github.com/jinzhu/gorm"
   "github.com/tealeg/xlsx"
   "strconv"
   "time"
)

func ExcelExportData(db *gorm.DB, config config.Config, header []string, data []map[string]interface{}, sheetName string) string {
   timeStr:=time.Now().Format("2006-01-02 15:04:05")
   var file *xlsx.File
   var sheet *xlsx.Sheet
   var row *xlsx.Row
   var cell *xlsx.Cell

   style := &xlsx.Style{}
   style.Fill = *xlsx.NewFill("solid", "EFEFDE", "EFEFDE")
   style.Border = xlsx.Border{RightColor: "FF"}
   file = xlsx.NewFile()
   sheet, _ = file.AddSheet(sheetName)
   row = sheet.AddRow()
   for i := 0; i < len(header); i++ { //looping from 0 to the length of the array
      cell = row.AddCell()
      cell.Value = header[i]
      cell.SetStyle(style)
   }
   for _, obj := range data {
      row = sheet.AddRow()
      for i := 0;i  
 

你可能感兴趣的:(golang excel 导出功能)