Bug 58495 - Rowcount returned is zero even when there rows of data in the excel.
Summary: Rowcount returned is zero even when there rows of data in the excel.
Status: RESOLVED WONTFIX
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.12-FINAL
Hardware: PC All
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-12 17:36 UTC by Raghu
Modified: 2015-10-30 17:38 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Raghu 2015-10-12 17:36:09 UTC
Sheetname:"Test Suite" 

test case	   Description	                                   Runmode
Login	        http://newtours.demoaut.com/ - login	              Y
Book a flight	Book a flight without changing any options.	      Y
Logout	        Logout successfully	                              N


Login test executed successfully because total rowcount returned=4 and the current row id=1. Before executing Book a flight,  the current row id=2 but rowcount returned=0. As a result, execution stops. 

POI code:

public class ExcelReader 
{
public String path;
public FileInputStream fis;
public FileOutputStream fos;
static XSSFWorkbook workbook;
static XSSFSheet sheet;
static XSSFRow row;
static XSSFCell cell;
int col_num=0;
int index=0;

public ExcelReader(String path)
{
	this.path=path;
    try
    {
    fis = new FileInputStream(path);
    workbook = new XSSFWorkbook(fis);
    fis.close();
    }
    catch(Exception e)
    {
    	System.out.println("File not found");
    }
}
public int getRowCount(String sheetname)
{
	index = workbook.getSheetIndex(sheetname);
	if(index==-1)
	return 0;
	else
	sheet = workbook.getSheetAt(index);
	int rownum=sheet.getPhysicalNumberOfRows();
	return rownum;
}
}

Even though the same sheetname is passed to getrowcount method after executing 'login' test, the rowcount returned is zero because the index is set to -1. 

        Integer suitetestID = new Integer(2);
	Integer casetestid = new Integer(2);
	Integer steptestid = new Integer(2);
	Integer datatestid = new Integer(2);
	
	
public SuiteDriver() throws Exception
{
       read = new ExcelReader("C:\\Learning_Framework\\xls\\testsuite.xlsx");
}

public void suite1() 
{	

try
{	
while(suitetestID.intValue()<=read.getrowcount(Constants.test_suite_sheet))
{
tid=suitetestID;
System.out.println("Number of rows in suite(before)"+read.getrowcount("Test Suite");

suite_runmode = read.getcelldata(Constants.test_suite_sheet, tid,Constants.runmode);
	
if(suite_runmode.equals(Constants.runmode_yes))
{

suitetestID++;

//Stores the test name
testcase=read.getcelldata(Constants.test_suite_sheet,tid, Constants.test_suite_sheet_test_case_col);

System.out.println("Suite T/F "+" "+(suitetestID<=read.getrowcount("Test Suite")));
//Here, the output is 4

testcaseDriver(testcase); -->Passes login String to another method to perform login actions.

System.out.println("Number of rows in suite(after)"+read.getrowcount(Constants.test_suite_sheet));
//Here, the output is 0

}
}
Comment 1 Raghu 2015-10-12 17:39:00 UTC
Please note, 

System.out.println("Number of rows in suite(after)"+read.getrowcount(Constants.test_suite_sheet));
//Here, the output is 0

In the above mentioned statement, Constants is a class and test_suite_sheet is a static String which is initialized as "Test Suite".
Comment 2 Nick Burch 2015-10-12 17:43:39 UTC
Any chance you could turn this into a small junit test that shows the problem, and upload the spreadsheet needed to trigger it? As it stands, it's a little hard to follow what the problem is

Also, make sure you've read the Sheet javadocs, eg the note on https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/Sheet.html#getPhysicalNumberOfRows%28%29
Comment 3 Javen O'Neal 2015-10-12 17:48:44 UTC
Can you please attach the file that is demonstrating the problem and reduce your code to the bare minimum needed to reproduce the problem?

Also, can you fix your code so that it compiles? Is getrowcount different from getRowCount?

I'm guessing the problem is in your code:
if (index==-1)
  return 0;

Make sure the sheet name you pass in is identical
Comment 4 Raghu 2015-10-12 18:35:48 UTC
Please have a look at the first comment written by me for more clarity. Sorry for changing the method name as getRowCount while pasting the code here.It is actually still getrowcount in my code. And also, 0 is returned even if getLastRowNum() is used instead of getPhysicalNumberOfRows().
Comment 5 Dominik Stadler 2015-10-30 17:38:37 UTC
Hm, it's very hard to see what happens with all the code-pieces that are not included in your code-extract. 

So unless you can provide a more self-contained example about your problem I fear we cannot do much, therefore I am closing this as WORKSFORME for now, please reopen if you can provide test-code which runs without all your specific things that prevent us from reproducing the problem.