1 2 17 18 package org.apache.poi.hwpf.usermodel; 19 20 21 import java.util.ArrayList ; 22 23 public class TableIterator 24 { 25 Range _range; 26 int _index; 27 int _levelNum; 28 29 TableIterator(Range range, int levelNum) 30 { 31 _range = range; 32 _index = 0; 33 _levelNum = levelNum; 34 } 35 36 public TableIterator(Range range) 37 { 38 this(range, 1); 39 } 40 41 42 public boolean hasNext() 43 { 44 int numParagraphs = _range.numParagraphs(); 45 for (;_index < numParagraphs; _index++) 46 { 47 Paragraph paragraph = _range.getParagraph(_index); 48 if (paragraph.isInTable() && paragraph.getTableLevel() == _levelNum) 49 { 50 return true; 51 } 52 } 53 return false; 54 } 55 56 public Table next() 57 { 58 int numParagraphs = _range.numParagraphs(); 59 int numRows = 0; 60 int startIndex = _index; 61 int endIndex = _index; 62 63 for (;_index < numParagraphs; _index++) 64 { 65 Paragraph paragraph = _range.getParagraph(_index); 66 if (!paragraph.isInTable() || paragraph.getTableLevel() < _levelNum) 67 { 68 endIndex = _index; 69 break; 70 } 71 } 72 return new Table(startIndex, endIndex, _range, _levelNum); 73 } 74 75 } 76 | Popular Tags |