github.com/easysoft/zendata@v0.0.0-20240513203326-705bd5a7fd67/cmd/test/helper/excel.go (about)

     1  package testHelper
     2  
     3  import (
     4  	"log"
     5  
     6  	"github.com/360EntSecGroup-Skylar/excelize/v2"
     7  )
     8  
     9  func GetExcelData(pth string, sheetIndex, rowIndex, colIndex int) (ret interface{}) {
    10  	excel, err := excelize.OpenFile(pth)
    11  	if err != nil {
    12  		log.Println("fail to read file " + pth + ", error: " + err.Error())
    13  		return
    14  	}
    15  
    16  	for sheetIdx, sheet := range excel.GetSheetList() {
    17  		if sheetIdx != sheetIndex {
    18  			continue
    19  		}
    20  		if sheetIdx > sheetIndex {
    21  			break
    22  		}
    23  
    24  		rows, _ := excel.GetRows(sheet)
    25  		if len(rows) == 0 {
    26  			continue
    27  		}
    28  
    29  		for rowIdx, row := range rows {
    30  			if rowIdx != rowIndex {
    31  				continue
    32  			}
    33  			if rowIdx > rowIndex {
    34  				break
    35  			}
    36  
    37  			for colIdx, col := range row {
    38  				if colIdx != colIndex {
    39  					continue
    40  				}
    41  				if colIdx > colIndex {
    42  					break
    43  				}
    44  
    45  				ret = col
    46  			}
    47  		}
    48  	}
    49  
    50  	return
    51  }