package excelutil import ( "context" "github.com/xuri/excelize/v2" "testing" ) func TestExportExcel(t *testing.T) { titles := []interface{}{"学员名称", "学员手机号码"} values := make([][]interface{}, 0) values = append(values, []interface{}{ "张三", "1231987", }) if _, err := ExportExcel(context.Background(), titles, values, withExcelCellOption()); err != nil { t.Errorf("ExportExcel() error = %v", err) } } var sliceNameTitleStyleId = 0 func withExcelCellOption() ExcelCellOptionFunc { return func(rowIndex, cellIndex int, cell *excelize.Cell) error { if rowIndex == 0 && cellIndex == 1 { cell.StyleID = sliceNameTitleStyleId } return nil } }