调整Excel导出时使用的方法
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -1648,16 +1649,27 @@ func (f *Factory) ExportToExcel(w io.Writer, sheetName string, columns []ExportC
|
||||
// filePath: 文件路径
|
||||
// sheetName: 工作表名称(可选,默认为"Sheet1")
|
||||
// columns: 列定义
|
||||
// data: 数据列表
|
||||
// data: 数据列表(可以是结构体切片或实现了ExportData接口的对象)
|
||||
// 返回错误信息
|
||||
//
|
||||
// 示例:
|
||||
//
|
||||
// fac.ExportToExcelFile("users.xlsx", "用户列表", columns, users)
|
||||
//
|
||||
// 注意:此方法内部创建文件并调用 ExportToWriter,确保行为与 ExportToExcel 一致
|
||||
func (f *Factory) ExportToExcelFile(filePath string, sheetName string, columns []ExportColumn, data interface{}) error {
|
||||
e, err := f.getExcelClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return e.ExportToFile(filePath, sheetName, columns, data)
|
||||
|
||||
// 创建文件
|
||||
file, err := os.Create(filePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create file: %w", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// 调用 ExportToWriter,复用核心逻辑
|
||||
return e.ExportToWriter(file, sheetName, columns, data)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user