golang gin框架 get 请求下载随时生成的文件 eg:excel

package handler

import (
	"github.com/360EntSecGroup-Skylar/excelize"
	"github.com/gin-gonic/gin"
)

func DownloadExcel(c *gin.Context){
	xlsx := excelize.NewFile()
	xlsx.SetCellValue("Sheet1", "A2", "asdas")
	//_ = xlsx.SaveAs("./aaa.xlsx")
	c.Header("Content-Type", "application/octet-stream")
	c.Header("Content-Disposition", "attachment; filename="+"Workbook.xlsx")
	c.Header("Content-Transfer-Encoding", "binary")
	_ = xlsx.Write(c.Writer)
}

  

posted @ 2019-12-23 19:25  小酥肉是我  阅读(3365)  评论(0编辑  收藏  举报