12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- package excel
- import "github.com/tealeg/xlsx"
- type LuckySheet struct {
- SheetList []LuckySheetData `description:"sheet数据"`
- }
- // GetExcelData 通过 luckySheetData获取excel表格数据
- func (item *LuckySheet) GetExcelData(isRemoveBlankCell bool) (xlsxFile *xlsx.File, err error) {
- xlsxFile = xlsx.NewFile()
- if err != nil {
- return
- }
- for _, sheet := range item.SheetList {
- tableData, tmpErr := sheet.GetTableDataByLuckySheetDataStr(isRemoveBlankCell)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- err = tableData.WriteExcelSheetData(xlsxFile, sheet.Name)
- if err != nil {
- return
- }
- }
- return
- }
- // ToExcel 通过 luckySheetData生成excel表格文件
- func (item *LuckySheet) ToExcel(isRemoveBlankCell bool) (downloadFilePath string, err error) {
- // 获取生成的excel路径
- downloadFilePath, err = getDownloadPath()
- if err != nil {
- return
- }
- // 获取excel表格数据
- xlsxFile, err := item.GetExcelData(isRemoveBlankCell)
- if err != nil {
- return
- }
- // 文件保存
- err = xlsxFile.Save(downloadFilePath)
- return
- }
|