aranalex
6018 号测试 成员, 2022-06-30 17:31:11 加入
1.5k
个人主页浏览
1h47m
在线时长
  • go 语言如何读取 excel 测试数据

    2022-06-30 17:35
    
    func Read() ([]ExcelExportList, error) {
    	datas, err := excelize.OpenFile("../datas/case.xlsx")
    	if err != nil {
    		panic(err)
    	}
    	body := make([]ExcelExportList, 0)
    	sheetname := datas.GetSheetList()
    	for _, v := range sheetname {
    		fmt.Println(v)
    
    		cell, err := datas.GetRows(v)
    		if err != nil {
    			println(err.Error())
    		}
    		excel := &ExcelExportList{
    			ExcelSheetName: v,
    			ExcelSheetList: make([]*ExcelExport, 0),
    		}
    
    		fmt.Println(excel.ExcelSheetList)
    		for _, row := range cell[1:] {
    
    			fmt.Println(row)
    			data := &ExcelExport{
    				Id:          row[0],
    				Type:        row[1],
    				Title:       row[2],
    				Pre_sql:     row[3],
    				Method:      row[4],
    				Url:         row[5],
    				Req_data:    make(map[string]interfce{}),
    				Extract:     make(map[string]interfce{}),
    				Assert_list: make([]map[string]interfce{}, 0),
    				Assert_db:   make([]map[string]interfce{}, 0),
    			}
    			json.Unmarshal([]byte(row[6]), &data.Req_data)
    			json.Unmarshal([]byte(row[7]), &data.Extract)
    			json.Unmarshal([]byte(row[8]), &data.Assert_list)
    			if len(row) > 9 {
    				json.Unmarshal([]byte(row[9]), &data.Assert_db)
    			}
    
    			excel.ExcelSheetList = append(excel.ExcelSheetList, data)
    			// fmt.Println(data)
    
    		}
    		body = append(body, *excel)
    	}
    	return body, err
    }
    

    雨泽大佬,看看,用的这个excel转json或者yml

    居然不能打interf ace