| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package excel
- import (
- "fmt"
- "github.com/tealeg/xlsx"
- "monitor/db"
- )
- func Writing(userInfos []db.UserInfo) {
- file := xlsx.NewFile()
- sheet, err := file.AddSheet("Sheet1")
- if err != nil {
- fmt.Print(err.Error())
- }
- row := sheet.AddRow()
- row.SetHeightCM(0.5)
- cell := row.AddCell()
- cell.Value = "用户 ID"
- cell = row.AddCell()
- cell.Value = "用户名"
- style := xlsx.NewStyle()
- style.Border = xlsx.Border{
- Left: "thin",
- Right: "thin",
- Top: "thin",
- Bottom: "thin",
- }
- style.ApplyBorder = true;
- for _, info := range userInfos {
- row := sheet.AddRow()
- row.SetHeightCM(0.5)
- cell := row.AddCell()
- cell.Value = info.UserId
- cell.SetStyle(style)
- cell = row.AddCell()
- cell.Value = info.UserName
- cell.SetStyle(style)
- }
- // 保存
- err = file.Save("2019-_-_-2019-_-_Lag延时数据.xlsx")
- if err != nil {
- fmt.Printf(err.Error())
- }
- }
- func customStyle() *xlsx.Style {
- style := xlsx.NewStyle()
- font := *xlsx.NewFont(12, "Verdana")
- font.Bold = true
- font.Italic = true
- font.Underline = true
- style.Font = font
- //fill := *xlsx.NewFill("solid", "00FF0000", "FF000000")
- //style.Fill = fill
- border := *xlsx.NewBorder("thin", "thin", "thin", "thin")
- style.Border = border
- style.ApplyBorder = true
- style.ApplyFill = true
- style.ApplyFont = true
- return style
- }
|