golang发送xlsx文件到浏览器端

niechaoya ·
更多评论
可以直接把内存中的xlsx文件发送到浏览器,不用先保存到本地磁盘: ``` func DownloadXlsx(w http.ResponseWriter, req *http.Request, filename string, file *xlsx.File) { w.Header().Add("Content-Disposition", "attachment") //w.Header().Add("Content-Type", "application/vnd.ms-excel") w.Header().Add("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") var buffer bytes.Buffer file.Write(&buffer) r := bytes.NewReader(buffer.Bytes()) http.ServeContent(w, req, filename, time.Now(), r) } ```
#2
分享一个功能丰富、兼容性好、高性能的专业 Excel 文档基础库 Excelize: https://github.com/xuri/excelize
#3