From: Nick Burch Date: Tue, 4 Dec 2007 12:05:33 +0000 (+0000) Subject: Note about iterators X-Git-Tag: REL_3_0_3_BETA1~264 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6a73a361f2eddfb8dc9b86dd6b3a495a04393928;p=poi.git Note about iterators git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@600904 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/hssf/quick-guide.xml b/src/documentation/content/xdocs/hssf/quick-guide.xml index 6dc4dc909b..eb48074dff 100644 --- a/src/documentation/content/xdocs/hssf/quick-guide.xml +++ b/src/documentation/content/xdocs/hssf/quick-guide.xml @@ -41,6 +41,7 @@
  • How to create cells
  • How to create date cells
  • Working with different types of cells
  • +
  • Iterate over rows and cells
  • Text Extraction
  • Aligning cells
  • Working with borders
  • @@ -234,6 +235,26 @@ fileOut.close(); + +
    Iterate over rows and cells (including Java 5 foreach loops) +

    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.

    +

    Luckily, this is very easy. HSSFRow defines a + CellIterator inner class to handle iterating over + the cells (get one with a call to row.cellIterator()), + and HSSFSheet provides a rowIterator() method to + give an iterator over all the rows.

    + + HSSFSheet sheet = wb.getSheetAt(0); + for (HSSFRow row : sheet.rowIterator()) { + for (HSSFCell cell : row.cellIterator()) { + // Do something here + } + } + +
    Text Extraction

    For most text extraction requirements, the standard