create_test.go 690 B

1234567891011121314151617181920212223242526272829303132
  1. package excelutil
  2. import (
  3. "context"
  4. "github.com/xuri/excelize/v2"
  5. "testing"
  6. )
  7. func TestExportExcel(t *testing.T) {
  8. titles := []interface{}{"学员名称", "学员手机号码"}
  9. values := make([][]interface{}, 0)
  10. values = append(values, []interface{}{
  11. "张三",
  12. "1231987",
  13. })
  14. if _, err := ExportExcel(context.Background(), titles, values, withExcelCellOption()); err != nil {
  15. t.Errorf("ExportExcel() error = %v", err)
  16. }
  17. }
  18. var sliceNameTitleStyleId = 0
  19. func withExcelCellOption() ExcelCellOptionFunc {
  20. return func(rowIndex, cellIndex int, cell *excelize.Cell) error {
  21. if rowIndex == 0 && cellIndex == 1 {
  22. cell.StyleID = sliceNameTitleStyleId
  23. }
  24. return nil
  25. }
  26. }