完善excel2导出

This commit is contained in:
xiangheng
2024-08-13 01:21:10 +08:00
parent c1b3b91e32
commit 1fc96a59b0
7 changed files with 96 additions and 393 deletions

View File

@@ -1,6 +1,8 @@
package excel2
import (
"net/http"
"github.com/xuri/excelize/v2"
)
@@ -11,6 +13,28 @@ type Excel struct {
ContentStyle1 int // 主体样式1无背景色
ContentStyle2 int // 主体样式2有背景色
}
type Col struct {
Name string
Key string
Width int
Replace map[string]any
Encode func(value any) any //暂未使用
Decode func(value any) any
}
// 下载
func DownLoadExcel(fileName string, res http.ResponseWriter, file *excelize.File) {
// 设置响应头
res.Header().Set("Content-Type", "text/html; charset=UTF-8")
res.Header().Set("Content-Type", "application/octet-stream")
res.Header().Set("Content-Disposition", "attachment; filename="+fileName+".xlsx")
res.Header().Set("Access-Control-Expose-Headers", "Content-Disposition")
err := file.Write(res) // 写入Excel文件内容到响应体
if err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
return
}
}
// 初始化
func ExcelInit() (e *Excel) {