github.com/kaiya/goutils@v1.0.1-0.20230226104005-4ae4a4dc3688/io/file/excel.go (about)

     1  package file
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/pkg/errors"
     7  	"github.com/xuri/excelize"
     8  )
     9  
    10  func ReadExcelRecords(fileName, sheetName string) ([][]string, error) {
    11  	f, err := excelize.OpenFile(fileName)
    12  	if err != nil {
    13  		return nil, errors.Wrap(err, "openFile")
    14  	}
    15  	defer func() {
    16  		// Close the spreadsheet.
    17  		if err := f.Close(); err != nil {
    18  			fmt.Println(err)
    19  		}
    20  	}()
    21  	return f.GetRows(sheetName)
    22  }