mirror of
https://gitee.com/xiangheng/x_admin.git
synced 2025-10-06 00:27:00 +08:00
完善excel2导出
This commit is contained in:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user