You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2008/02/05 17:21:23 UTC

svn commit: r618690 - /poi/trunk/src/documentation/content/xdocs/hssf/quick-guide.xml

Author: nick
Date: Tue Feb  5 08:21:21 2008
New Revision: 618690

URL: http://svn.apache.org/viewvc?rev=618690&view=rev
Log:
Tweaks to the iterator use guides for hssf

Modified:
    poi/trunk/src/documentation/content/xdocs/hssf/quick-guide.xml

Modified: poi/trunk/src/documentation/content/xdocs/hssf/quick-guide.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/hssf/quick-guide.xml?rev=618690&r1=618689&r2=618690&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/hssf/quick-guide.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/hssf/quick-guide.xml Tue Feb  5 08:21:21 2008
@@ -236,16 +236,51 @@
                     </source>
                 </section>
                 <anchor id="Iterator"/>
-                <section><title>Iterate over rows and cells (including Java 5 foreach loops)</title>
+                <section><title>Iterate over rows and cells</title>
 				<p>Sometimes, you'd like to just iterate over all the rows in
-				a sheet, or all the cells in a row. If you are using Java
-				5 or later, then this is especially handy, as it'll allow the
-				new foreach loop support to work.</p>
+				a sheet, or all the cells in a row. This is possible with
+				a simple for loop.</p>
 				<p>Luckily, this is very easy. HSSFRow defines a 
 				<em>CellIterator</em> inner class to handle iterating over 
 				the cells (get one with a call to <em>row.cellIterator()</em>),
 				and HSSFSheet provides a <em>rowIterator()</em> method to
 				give an iterator over all the rows.</p>
+				<p>(Unfortunately, due to the broken and
+				backwards-incompatible way that Java 5 foreach loops were
+				implemented, it isn't possible to use them on a codebase
+				that supports Java 1.4, as POI does)</p>
+				<source>
+	HSSFSheet sheet = wb.getSheetAt(0);
+	for (Iterator rit = sheet.rowIterator(); rit.hasNext(); ) {
+		HSSFRow row = (HSSFRow)rit.next();
+		for (Iterator cit = row.cellIterator(); cit.hasNext(); ) {
+			HSSFCell cell = (HSSFCell)cit.next();
+			// Do something here
+		}
+	}
+				</source>
+				<source>
+	HSSFSheet sheet = wb.getSheetAt(0);
+	for (Iterator&lt;HSSFRow&gt; rit = (Iterator&lt;HSSFRow&gt;)sheet.rowIterator(); rit.hasNext(); ) {
+		HSSFRow row = rit.next();
+		for (Iterator&lt;HSSFCell&gt; cit = (Iterator&lt;HSSFCell&gt;)row.cellIterator(); cit.hasNext(); ) {
+			HSSFCell cell = cit.next();
+			// Do something here
+		}
+	}
+				</source>
+                </section>
+                <section><title>Iterate over rows and cells using Java 1.5 foreach loops - OOXML Branch Only</title>
+				<p>Sometimes, you'd like to just iterate over all the rows in
+				a sheet, or all the cells in a row. If you are using Java
+				5 or later, then this is especially handy, as it'll allow the
+				new foreach loop support to work.</p>
+				<p>Luckily, this is very easy. Both HSSFSheet and HSSFRow
+				implement <em>java.lang.Iterable</em> to allow foreach
+				loops. For HSSFRow this allows access to the 
+				<em>CellIterator</em> inner class to handle iterating over 
+				the cells, and for HSSFSheet gives the 
+				<em>rowIterator()</em> to iterator over all the rows.</p>
 				<source>
 	HSSFSheet sheet = wb.getSheetAt(0);
 	for (HSSFRow row : sheet.rowIterator()) {
@@ -254,6 +289,7 @@
 		}
 	}
 				</source>
+				<note>This only works on the OOXML branch of POI</note>
                 </section>
                 <anchor id="TextExtraction"/>
                 <section><title>Text Extraction</title>



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