2016-06-10 3 views
-2

다른 매개 변수와 같은 시나리오가 있으며 내 메서드의 변수는 Excel 시트의 데이터를 가져 와서 값을 가져야합니다. 예를 들어 countryname과 같은 변수가 있고 Excel 시트에는 국가 이름 목록이있는 8 번째 열이 있습니다. 따라서 코드를 처음 실행할 때 countryname 변수는 8 번째 열의 첫 번째 셀 값을 가져야하고 다음에 8 번째 열의 두 번째 셀 값을 가져야하는 코드를 실행합니다. 마찬가지로 Excel 시트에서 데이터를 가져와야하는 다른 변수가 있습니다. 어떻게 자바에서이 시나리오를 자동화합니까?Excel 시트에서 데이터를 읽는 Selenium Webdriver

+0

Excel POI 또는 JExcel을 사용하여 Excel 파일을 읽습니다. –

답변

0

엑셀 (XLSX) 파일을 사용하기 위해 프로젝트에 Apache POI jar 파일을 추가 할 수 있습니다. 또한 참조 용 샘플 코드 첨부

void readXLSXFile(String fileName) throws IOException 
    { 
     FileInputStream fs= new FileInputStream(fileName); 
     XSSFWorkbook wb = new XSSFWorkbook(fs); 

     XSSFSheet ws = wb.getSheetAt(0);//you can change the value to index value of your required sheet 
     Iterator<Row> rows = ws.rowIterator(); 

     XSSFRow row;    
     while(rows.hasNext()) 
     { 
     row=(XSSFRow) rows.next(); 
     XSSFCell cell=row.getCell(7);//8th cell of the row 
     String CName= cell.getStringCellValue(); //getting the cell value as string 

     countryNames(CName);// Your method for passing the country name to the method for your requirement 
     } 

     wb.close(); 
    } 
관련 문제