![]() ![]() If(HSSFDateUtil.isCellDateFormatted(cell))ĭateFormat df = new SimpleDateFormat("dd/MM/yy") String cellValue = String.valueOf(cell.getNumericCellValue()) If(cell.getCellTypeEnum() = CellType.STRING)Įlse if(cell.getCellTypeEnum() = CellType.NUMERIC || cell.getCellTypeEnum() = CellType.FORMULA) If(row.getCell(i).getStringCellValue().trim().equals(im())) Public String getCellData(String sheetName, String colName, int rowNum)įor(int i = 0 i < row.getLastCellNum() i++) Public ExcelApiTest(String xlFilePath) throws Exception In this we will write a method called “ getCellData()” and it will accept 3 parameters called sheetName, columnName and rowNumber. For this we will write 2 classes, one will have the actual logic to read the excel data and another class will call this method.īelow is the excel read data util class. But for the best practice we will create a util method and will call that method where ever we need. In the above program we have hard-coded the row and column numbers in the program. ("Value of the Excel Cell is - "+ value) String value = cell.getStringCellValue() If(row.getCell(i).getStringCellValue().trim().equals("UserName")) XSSFSheet sheet = workbook.getSheet("Credentials") įor(int i=0 i < row.getLastCellNum() i++) XSSFWorkbook workbook = new XSSFWorkbook(fis) Public static void main(String args) throws ExceptionįileInputStream fis = new FileInputStream("/Volumes/Krishna/Jar Files/poi-3.16-beta1/TestData.xlsx") Now we will write a sample stand alone program that will read the data from the excel: We need to use different kind of methods to read String, Integer and Date values from the excel.apostrophe) value in front of that value. If you want to read integer value then you have to use “‘”(i.e.We can download the Apache POI Jar files from this link and can find the screenshots below for the same. getBooleanCellValue() – Get the value of the cell as a boolean.getDateCellValue() – Get the value of the cell as a date.getNumericCellValue() – Get the value of the cell as a number.getCell(int) – Get the cell representing a given column.getStringCellValue() – Get the value of the cell as a String.getLastCellNum() – Get the index of the last cell contained in the row Plus one as index starts from ZERO.getSheet(“sheetName”) – Get sheet with the given name.FileInputStream – A FileInputStream is an inputstream for reading data from a File.īelow are the methods will use to read the data which are available in the above classes:. ![]() To read excel data we will use Java and Apache POI classes.īelow are the classes will use to read the data: To interact with the excel, Apache POI given so many classes to interact with the excel and get the data. ![]() In this blog we will use Apache POI to read the data from the excel sheet. In those one of the famous is Apache POI. So, if you want to read data from excel we need to use some third party API which are available. In order to create a data driven framework then it is easy with using excel. So, we mostly use excel to maintain the test data. Among these Excel is very user friendly that we can organize the data very easily and we can read the data how we want. If an application need so much of data to be feeded to test then we will manage those data using external sources like text file, xml file and excel file etc…. We might get doubt that why we need to put the test data in excel and why to read data from that. Read data from excel using column name will discuss about how we can read test data from the excel sheet while automating any application using selenium webdriver. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |