|
@@ -1,6 +1,7 @@
|
|
package excelutils
|
|
package excelutils
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "bytes"
|
|
"fmt"
|
|
"fmt"
|
|
"git.sxidc.com/go-tools/utils/strutils"
|
|
"git.sxidc.com/go-tools/utils/strutils"
|
|
"github.com/xuri/excelize/v2"
|
|
"github.com/xuri/excelize/v2"
|
|
@@ -9,7 +10,7 @@ import (
|
|
"strconv"
|
|
"strconv"
|
|
)
|
|
)
|
|
|
|
|
|
-func ExportExcel(titleList []string, data []interface{}, sheetName string) (*excelize.File, error) {
|
|
+func ExportExcel(titleList []string, data []interface{}, sheetName string) ([]byte, error) {
|
|
f := excelize.NewFile()
|
|
f := excelize.NewFile()
|
|
defer func() {
|
|
defer func() {
|
|
err := f.Close()
|
|
err := f.Close()
|
|
@@ -40,8 +41,15 @@ func ExportExcel(titleList []string, data []interface{}, sheetName string) (*exc
|
|
},
|
|
},
|
|
})
|
|
})
|
|
|
|
|
|
- _ = f.SetSheetRow(sheetName, "A1", &header)
|
|
+ err = f.SetSheetRow(sheetName, "A1", &header)
|
|
- _ = f.SetRowHeight(sheetName, 1, 30)
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ err = f.SetRowHeight(sheetName, 1, 30)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
|
|
length := len(titleList)
|
|
length := len(titleList)
|
|
headStyle := strutils.GenerateUpperLetters(length)
|
|
headStyle := strutils.GenerateUpperLetters(length)
|
|
@@ -78,5 +86,11 @@ func ExportExcel(titleList []string, data []interface{}, sheetName string) (*exc
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- return f, nil
|
|
+ buffer := &bytes.Buffer{}
|
|
|
|
+ err = f.Write(buffer)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return buffer.Bytes(), nil
|
|
}
|
|
}
|