| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package main
- import (
- "fmt"
- "github.com/360EntSecGroup-Skylar/excelize"
- "time"
- )
- func main() {
- //创建excel文件
- xlsx := excelize.NewFile()
- fmt.Println("start time : ", time.Now())
- //创建新表单
- index := xlsx.NewSheet("test1")
- xlsx.SetCellValue("test1", "A1", "序号")
- xlsx.SetCellValue("test1", "B1", "测试数据1")
- xlsx.SetCellValue("test1", "C1", "测试数据2")
- for i := 2; i <= 1000001; i++ {
- //设置单元格的值
- xlsx.SetCellValue("test1", fmt.Sprintf("A%d", i), i-1)
- xlsx.SetCellValue("test1", fmt.Sprintf("B%d", i), time.Now().Unix())
- xlsx.SetCellValue("test1", fmt.Sprintf("C%d", i), time.Now())
- }
- fmt.Println("test1 end time : ", time.Now())
- xlsx.NewSheet("test2")
- xlsx.SetCellValue("test2", "A1", "序号")
- xlsx.SetCellValue("test2", "B1", "测试数据1")
- xlsx.SetCellValue("test2", "C1", "测试数据2")
- for i := 2; i <= 1000001; i++ {
- //设置单元格的值
- xlsx.SetCellValue("test2", fmt.Sprintf("A%d", i), i-1)
- xlsx.SetCellValue("test2", fmt.Sprintf("B%d", i), time.Now().Unix())
- xlsx.SetCellValue("test2", fmt.Sprintf("C%d", i), time.Now())
- }
- fmt.Println("test2 end time : ", time.Now())
- //设置默认打开的表单
- xlsx.SetActiveSheet(index)
- //保存文件到指定路径
- err := xlsx.SaveAs("./test.xlsx")
- if err != nil {
- fmt.Println(err.Error())
- }
- fmt.Println("end time : ", time.Now())
- }
|