]> source.dussan.org Git - poi.git/commitdiff
Note about iterators
authorNick Burch <nick@apache.org>
Tue, 4 Dec 2007 12:05:33 +0000 (12:05 +0000)
committerNick Burch <nick@apache.org>
Tue, 4 Dec 2007 12:05:33 +0000 (12:05 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@600904 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/hssf/quick-guide.xml

index 6dc4dc909b907c55c8c30280b7de9deb547cda5d..eb48074dff14ed8430b09919ec0f921218d11c1a 100644 (file)
@@ -41,6 +41,7 @@
                     <li><link href="#CreateCells">How to create cells</link></li>
                     <li><link href="#CreateDateCells">How to create date cells</link></li>
                     <li><link href="#CellTypes">Working with different types of cells</link></li>
+                    <li><link href="#Iterator">Iterate over rows and cells</link></li>
                     <li><link href="#TextExtraction">Text Extraction</link></li>
                     <li><link href="#Alignment">Aligning cells</link></li>
                     <li><link href="#Borders">Working with borders</link></li>
     fileOut.close();
                     </source>
                 </section>
+                <anchor id="Iterator"/>
+                <section><title>Iterate over rows and cells (including Java 5 foreach loops)</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. 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>
+                               <source>
+    HSSFSheet sheet = wb.getSheetAt(0);
+       for (HSSFRow row : sheet.rowIterator()) {
+               for (HSSFCell cell : row.cellIterator()) {
+                       // Do something here
+               }
+       }
+                               </source>
+                </section>
                 <anchor id="TextExtraction"/>
                 <section><title>Text Extraction</title>
                                        <p>For most text extraction requirements, the standard