In previous blog post, I have explained about how use XML for making a data driven framework for automation testing . It can be found here. I have also written about how to use jxl library for reading from excel and writing into Excel.
Below is another code snippet to read all values of a row and save it into a hash map for accessing later during automation test.
1234567891011121314151617181920212223242526272829
publicHashMapGetAllDataForARow(Stringsheet,intRow){HashMapDataMap=newHashMap();try{Workbookwrk1=Workbook.getWorkbook(newFile(dataPath));//Obtain the reference to the first sheet in the workbookSheetsheet1=wrk1.getSheet(sheet);intx=0;CellcolArow1,colArow2;do{colArow1=sheet1.getCell(x,0);colArow2=sheet1.getCell(x,Row);DataMap.put(colArow1.getContents(),colArow2.getContents());x=x+1;}while(colArow1.getContents()!="");}catch(BiffExceptione){e.printStackTrace();}catch(IOExceptione){e.printStackTrace();}catch(IndexOutOfBoundsExceptione){}returnDataMap;}