更新
This commit is contained in:
parent
b44429d720
commit
accf04e319
@ -190,6 +190,8 @@ func ExportRegister(c *gin.Context) {
|
||||
fmt.Println("=======================转换成excel============================")
|
||||
_, _ = utils.ToExcelByType(columns, data, "slice", filePath)
|
||||
//处理图片
|
||||
fmt.Println("=======================转换成excel============================")
|
||||
fmt.Println("=======================处理图片============================")
|
||||
err = logic.DealExcelImg(filePath)
|
||||
if err != nil {
|
||||
response.ResponseQuickMsg(c, msg.Fail, err.Error(), nil)
|
||||
|
@ -57,16 +57,19 @@ func Get(url string) string {
|
||||
// ToExcelByType 转成Excel类型
|
||||
func ToExcelByType(titleList []string, dataList []interface{}, dataType string, filePath string) (content io.ReadSeeker, err error) {
|
||||
// 生成一个新的文件
|
||||
|
||||
file := xlsx.NewFile()
|
||||
// 添加sheet页
|
||||
sheet, _ := file.AddSheet("Sheet1")
|
||||
// 插入表头
|
||||
fmt.Println("=======================插入表头============================")
|
||||
titleRow := sheet.AddRow()
|
||||
for _, v := range titleList {
|
||||
cell := titleRow.AddCell()
|
||||
cell.Value = v
|
||||
}
|
||||
// 插入内容
|
||||
fmt.Println("=======================插入内容============================")
|
||||
for _, v := range dataList {
|
||||
row := sheet.AddRow()
|
||||
if dataType == "struct" {
|
||||
@ -77,6 +80,7 @@ func ToExcelByType(titleList []string, dataList []interface{}, dataType string,
|
||||
}
|
||||
var buffer bytes.Buffer
|
||||
_ = file.Write(&buffer)
|
||||
fmt.Println("=======================Save============================")
|
||||
if filePath != "" {
|
||||
if err = file.Save(filePath); err != nil {
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user