You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by PeteF <p_...@yahoo.com> on 2009/12/21 23:54:08 UTC

Only single row gets created in my excel

I am trying to write a Java collection to an excel document. Here is my code,
but I only get a single row created in the excel. What am I doing
incorrectly?

[code]
		while(iterator.hasNext()) {
			Rule rule = (Rule)iterator.next();
			
			HSSFRow row = sheet.createRow((short)rowNumber++);
						
			HSSFCell cell = row.createCell((short) 0);
			cell.setCellStyle(cellStyle);
			cell.setCellType(HSSFCell.CELL_TYPE_STRING);
			cell.setCellValue(rule.getNum());
			
			cell = row.createCell((short) 1);
			cell.setCellStyle(cellStyle);
			cell.setCellType(HSSFCell.CELL_TYPE_STRING);
			cell.setCellValue(rule.getDescription());
			
			cell = row.createCell((short) 2);
			cell.setCellStyle(cellStyle);
			cell.setCellType(HSSFCell.CELL_TYPE_STRING);
			cell.setCellValue(rule.getType());
		}

[/code]
-- 
View this message in context: http://old.nabble.com/Only-single-row-gets-created-in-my-excel-tp26881426p26881426.html
Sent from the POI - User mailing list archive at Nabble.com.


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


Re: Only single row gets created in my excel

Posted by PeteF <p_...@yahoo.com>.
Sorry, never mind. I had my data setup incorrectly. It is fine now.

Thanks.
-- 
View this message in context: http://old.nabble.com/Only-single-row-gets-created-in-my-excel-tp26881426p26883780.html
Sent from the POI - User mailing list archive at Nabble.com.


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


Re: Only single row gets created in my excel

Posted by PeteF <p_...@yahoo.com>.
The loop gets executed more than once. Here is the code. When I run the
program, I get the following output. When I look at the generated excel
after I write it to the file, only the 3 row is there!!!

Row number is 0
Row number is 1
Row number is 2

                          int rowNumber = 0;
		while(iterator.hasNext()) {
			Rule rule = (Rule)iterator.next();
			
			HSSFRow dataRow = sheet.createRow(rowNumber);
			System.out.println("Row number is "  + dataRow.getRowNum());
			
			dataRow.createCell(0).setCellValue(rule.getRuleNumber());
			dataRow.createCell(1).setCellValue(rule.getRuleDescription());
			dataRow.createCell(2).setCellValue(rule.getRuleType());
			
			rowNumber++;
		}
-- 
View this message in context: http://old.nabble.com/Only-single-row-gets-created-in-my-excel-tp26881426p26883701.html
Sent from the POI - User mailing list archive at Nabble.com.


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


Re: Only single row gets created in my excel

Posted by Josh Micich <jo...@gmail.com>.
The code looks fine.  Are you sure the loop body gets executed more
than once?  It would be very surprising for the to call
"sheet.createRow(rowNumber)" twice with different values of rowNumber
but only get one row.  If you are *certain* this is happening, please
create a bugzilla entry and upload some simple but working example
code to reproduce this bug.

btw - remove all the "(short)" typecasts - they are not required.

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