As we know that selenium supports only Web Browser Automation and for excel we will need to take help of third party API like Apache POI and JExcel.
We are going to implement this with the use of Apache POI , so first of all we have to download the Apache POI jar file from the below URL.
1. Go to the below URL and Click on the Highlighted Link.
http://poi.apache.org/download.html
2. Then click on the below highlighted URL and download the zip file of Apache POI
3. All jar files will come in zip files, Extract it and you will get final jar folder looks like this
4. Add all jar files or below mention, jar files into Project.
In below example, I am reading simple .xlsx file
We are going to implement this with the use of Apache POI , so first of all we have to download the Apache POI jar file from the below URL.
1. Go to the below URL and Click on the Highlighted Link.
http://poi.apache.org/download.html
2. Then click on the below highlighted URL and download the zip file of Apache POI
3. All jar files will come in zip files, Extract it and you will get final jar folder looks like this
4. Add all jar files or below mention, jar files into Project.
In below example, I am reading simple .xlsx file
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class TestClass { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub try { File src = new File("D:\\test.xlsx"); FileInputStream fis = new FileInputStream(src); XSSFWorkbook xc = new XSSFWorkbook(fis); XSSFSheet sb = xc.getSheetAt(0); System.out.println(sb.getRow(0).getCell(0).getStringCellValue()); } catch(Exception e) { System.out.println(e.getMessage()); System.out.println("Not getting the value into the excel"); } } }
No comments:
Post a Comment