Unable to write into excel sheet however no error is thrown | Selenium Forum
M
Posted on 17/12/2016
Hi Ashish/ Guys,

I have a requirement where i need to update specific rows of excel sheet only. I have created below function for writing back into excel sheet. Interesting part is code runs without any error but its not writing inside excel. Can anyone please let me know what I am doing wrong. Please note that i am using XLS_Reader file for interacting with excels designed by Ashish.

Appreaciate your help.

Thanks
Ahmed
//************************Code****************************

public void setData(String TestName, String application, String browser, String emailId ){
init();// initialize the Property file
Xls_Reader xls = new Xls_Reader(System.getProperty("user.dir")+"\\src\\com\\Digicomm\\datatables\\"+application+".xlsx");

int rows = xls.getRowCount("Data");
System.out.println("There are "+rows+" rows");

//Calculating row number for test case
int TestRowNum;
for(TestRowNum= 1; TestRowNum<= rows; TestRowNum++){
String TestNameXls = xls.getCellData(Constants.DATA_SHEET, 0, TestRowNum);//Constants.DATA_SHEET=data
if(TestNameXls.equalsIgnoreCase(TestName))
break;
}
System.out.println("Test starts from row number "+TestRowNum);

int colStartRowNum = TestRowNum +1;
int dataStartRowNum = TestRowNum +2;

//Number of data rows
int testrows =1;
while((!xls.getCellData(Constants.DATA_SHEET, 0, dataStartRowNum+testrows).equals(""))){
testrows++;
}
System.out.println("Total rows of data are "+testrows);

//Number of data cols
int testcols = 0;
while(!(xls.getCellData(Constants.DATA_SHEET, testcols, colStartRowNum)).equals("")){
testcols++;
}
System.out.println("Total cols of data are "+testcols);

for(int j=0;j<testcols;j++){
String CellData = xls.getCellData(Constants.DATA_SHEET, j, colStartRowNum);
System.out.println(CellData);
if(CellData.equalsIgnoreCase("Email")&& browser.equalsIgnoreCase("IE"))
xls.setCellData(Constants.DATA_SHEET, Constants.EMAIL_COL, dataStartRowNum, emailId);
else if (CellData.equalsIgnoreCase("Email")&& browser.equalsIgnoreCase("Chrome"))
xls.setCellData(Constants.DATA_SHEET, Constants.EMAIL_COL, dataStartRowNum +1,emailId);
else if(CellData.equalsIgnoreCase("Email")&& browser.equalsIgnoreCase("Mozilla"))
xls.setCellData(Constants.DATA_SHEET, Constants.EMAIL_COL, dataStartRowNum+2,emailId);
}

}
//*************************End of Code****************************

M
Replied on 18/12/2016

Ashish, request you to please reply on this. Its urgent pls. PFA excel sheet for more reference.


Thanks
Ahmed


M
Replied on 18/12/2016

try debugging with eclipse. it is very hard for us to solve a problem if no error comes up.

try debugging with eclipse. look at each step if it is working. if you cannot find anything I'll be happy to look at it.


M
Replied on 19/12/2016

Hi Ashish,
I debugged this portion of code already and code is working fine but when we call xls.setCellData function, its not working and not printing anything in excel. Kindly check at your end one time please.

Thanks
Ahmed


M
Replied on 19/12/2016

If you want i can show you what is actually happening by screenshare. Kindly let me know.

Thanks
Ahmed


M
Replied on 19/12/2016

tell me what time we can share the screen.