main.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/360EntSecGroup-Skylar/excelize"
  5. "time"
  6. )
  7. func main() {
  8. //创建excel文件
  9. xlsx := excelize.NewFile()
  10. fmt.Println("start time : ", time.Now())
  11. //创建新表单
  12. index := xlsx.NewSheet("test1")
  13. xlsx.SetCellValue("test1", "A1", "序号")
  14. xlsx.SetCellValue("test1", "B1", "测试数据1")
  15. xlsx.SetCellValue("test1", "C1", "测试数据2")
  16. for i := 2; i <= 1000001; i++ {
  17. //设置单元格的值
  18. xlsx.SetCellValue("test1", fmt.Sprintf("A%d", i), i-1)
  19. xlsx.SetCellValue("test1", fmt.Sprintf("B%d", i), time.Now().Unix())
  20. xlsx.SetCellValue("test1", fmt.Sprintf("C%d", i), time.Now())
  21. }
  22. fmt.Println("test1 end time : ", time.Now())
  23. xlsx.NewSheet("test2")
  24. xlsx.SetCellValue("test2", "A1", "序号")
  25. xlsx.SetCellValue("test2", "B1", "测试数据1")
  26. xlsx.SetCellValue("test2", "C1", "测试数据2")
  27. for i := 2; i <= 1000001; i++ {
  28. //设置单元格的值
  29. xlsx.SetCellValue("test2", fmt.Sprintf("A%d", i), i-1)
  30. xlsx.SetCellValue("test2", fmt.Sprintf("B%d", i), time.Now().Unix())
  31. xlsx.SetCellValue("test2", fmt.Sprintf("C%d", i), time.Now())
  32. }
  33. fmt.Println("test2 end time : ", time.Now())
  34. //设置默认打开的表单
  35. xlsx.SetActiveSheet(index)
  36. //保存文件到指定路径
  37. err := xlsx.SaveAs("./test.xlsx")
  38. if err != nil {
  39. fmt.Println(err.Error())
  40. }
  41. fmt.Println("end time : ", time.Now())
  42. }