You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Guest <vi...@yahoo.com> on 2004/02/17 20:25:34 UTC

Row Iterator Problem

Hii,

I still have the problem with row iterator...i have a method which gives me the 
number of rows...it stops when it encountered empty cell > my defined columns

	public int getNumberOfRows(HSSFSheet sheet, int numberOfColumns) {
		int count = 0;
		Iterator rows = (Iterator) sheet.rowIterator();
		for (HSSFRow row = (HSSFRow) rows.next();
			rows.hasNext();
			row = (HSSFRow) rows.next()) {
				logger.debug("Row No."+row.getRowNum());
			int nullOrBlankCells = 0;
			for (int j = 0; j < numberOfColumns; j++) {
				HSSFCell cell = row.getCell((short) j);
				if(isCellEmpty(cell)){
					nullOrBlankCells++;
				}
			} // iterate over columns finished

			// if the row is empty break out of loop
			// and return the number of data rows
			if (nullOrBlankCells >= numberOfColumns)
				break;
			count++;
		}
		return count;
	}

	private boolean isCellEmpty(HSSFCell cell) {
		return (cell == null)
			|| (cell.getCellType() == HSSFCell.CELL_TYPE_BLANK)
			|| (cell.getCellType() == HSSFCell.CELL_TYPE_STRING
				&& cell.getStringCellValue().length() == 0);
	}


Why the above doesn't work???

PLEASE HELP
vicky


---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-user-help@jakarta.apache.org


Re: Row Iterator Problem

Posted by Danny Mui <da...@muibros.com>.
Is this for version 2?  Pleas submit a bugzilla report with a sample 
spreadsheet and of course the code to reproduce.

Thanks.

Anshul Patni wrote:
> Hii,
> I am also facing the same problem. The problem is: with the following for loop the iterator is not going to the last row 
>  
> 
> for (HSSFRow row = (HSSFRow) rows.next();
> 
> rows.hasNext();
> 
> row = (HSSFRow) rows.next()) {
> }
> 
> I don't know exactly where the problem is. Can someone help??
>  
> Regards
> pats
> 
> Guest <vi...@yahoo.com> wrote:
> Hii,
> 
> I still have the problem with row iterator...i have a method which gives me the 
> number of rows...it stops when it encountered empty cell > my defined columns
> 
> public int getNumberOfRows(HSSFSheet sheet, int numberOfColumns) {
> int count = 0;
> Iterator rows = (Iterator) sheet.rowIterator();
> for (HSSFRow row = (HSSFRow) rows.next();
> rows.hasNext();
> row = (HSSFRow) rows.next()) {
> logger.debug("Row No."+row.getRowNum());
> int nullOrBlankCells = 0;
> for (int j = 0; j < numberOfColumns; j++) {
> HSSFCell cell = row.getCell((short) j);
> if(isCellEmpty(cell)){
> nullOrBlankCells++;
> }
> } // iterate over columns finished
> 
> // if the row is empty break out of loop
> // and return the number of data rows
> if (nullOrBlankCells >= numberOfColumns)
> break;
> count++;
> }
> return count;
> }
> 
> private boolean isCellEmpty(HSSFCell cell) {
> return (cell == null)
> || (cell.getCellType() == HSSFCell.CELL_TYPE_BLANK)
> || (cell.getCellType() == HSSFCell.CELL_TYPE_STRING
> && cell.getStringCellValue().length() == 0);
> }
> 
> 
> Why the above doesn't work???
> 
> PLEASE HELP
> vicky
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: poi-user-help@jakarta.apache.org
> 
> 
> ---------------------------------
> Do you Yahoo!?
> Yahoo! Mail SpamGuard - Read only the mail you want.

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-user-help@jakarta.apache.org


Re: Row Iterator Problem

Posted by Anshul Patni <pa...@yahoo.com>.
Hii,
I am also facing the same problem. The problem is: with the following for loop the iterator is not going to the last row 
 

for (HSSFRow row = (HSSFRow) rows.next();

rows.hasNext();

row = (HSSFRow) rows.next()) {
}

I don't know exactly where the problem is. Can someone help??
 
Regards
pats

Guest <vi...@yahoo.com> wrote:
Hii,

I still have the problem with row iterator...i have a method which gives me the 
number of rows...it stops when it encountered empty cell > my defined columns

public int getNumberOfRows(HSSFSheet sheet, int numberOfColumns) {
int count = 0;
Iterator rows = (Iterator) sheet.rowIterator();
for (HSSFRow row = (HSSFRow) rows.next();
rows.hasNext();
row = (HSSFRow) rows.next()) {
logger.debug("Row No."+row.getRowNum());
int nullOrBlankCells = 0;
for (int j = 0; j < numberOfColumns; j++) {
HSSFCell cell = row.getCell((short) j);
if(isCellEmpty(cell)){
nullOrBlankCells++;
}
} // iterate over columns finished

// if the row is empty break out of loop
// and return the number of data rows
if (nullOrBlankCells >= numberOfColumns)
break;
count++;
}
return count;
}

private boolean isCellEmpty(HSSFCell cell) {
return (cell == null)
|| (cell.getCellType() == HSSFCell.CELL_TYPE_BLANK)
|| (cell.getCellType() == HSSFCell.CELL_TYPE_STRING
&& cell.getStringCellValue().length() == 0);
}


Why the above doesn't work???

PLEASE HELP
vicky


---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-user-help@jakarta.apache.org


---------------------------------
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.