Note about iterators
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@600904 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
12705fe743
commit
92cb3654cb
@ -41,6 +41,7 @@
|
|||||||
<li><link href="#CreateCells">How to create cells</link></li>
|
<li><link href="#CreateCells">How to create cells</link></li>
|
||||||
<li><link href="#CreateDateCells">How to create date 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="#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="#TextExtraction">Text Extraction</link></li>
|
||||||
<li><link href="#Alignment">Aligning cells</link></li>
|
<li><link href="#Alignment">Aligning cells</link></li>
|
||||||
<li><link href="#Borders">Working with borders</link></li>
|
<li><link href="#Borders">Working with borders</link></li>
|
||||||
@ -234,6 +235,26 @@
|
|||||||
fileOut.close();
|
fileOut.close();
|
||||||
</source>
|
</source>
|
||||||
</section>
|
</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"/>
|
<anchor id="TextExtraction"/>
|
||||||
<section><title>Text Extraction</title>
|
<section><title>Text Extraction</title>
|
||||||
<p>For most text extraction requirements, the standard
|
<p>For most text extraction requirements, the standard
|
||||||
|
Loading…
Reference in New Issue
Block a user