View Javadoc

1   
2   package oscon2006.web.excel;
3   
4   import java.util.*;
5   import java.io.*;
6   import wicket.model.*;
7   import wicket.extensions.markup.html.repeater.data.IDataProvider;
8   import org.apache.poi.hssf.usermodel.*;
9   
10  public class ExcelDataProvider 
11  	extends wicket.extensions.markup.html.repeater.util.SortableDataProvider
12  {
13  	private HSSFWorkbook wb;
14  	private int sheetNumber;
15  	
16  	public ExcelDataProvider(HSSFWorkbook w, int sheetNum)
17  	{
18  		this.wb = w;
19  		this.sheetNumber = sheetNum;
20  	}
21  	
22  	public Iterator iterator(int first, int count)
23  	{
24  		List rows = new ArrayList();
25  		
26  		for (int rowIndex = first; rowIndex < (first + count); rowIndex++)
27  		{
28  			HSSFRow row = this.getSheet().getRow(rowIndex);
29  			rows.add(row);
30  		}
31  		
32  		return rows.iterator();
33  	}
34  
35  	protected HSSFSheet getSheet()
36  	{
37  		return this.wb.getSheetAt(this.sheetNumber);
38  	}
39  	
40  	public int getColumnCount()
41  	{
42  		return getFirstRow().getPhysicalNumberOfCells();
43  	}
44  	
45  	public HSSFRow getFirstRow()
46  	{
47  		HSSFSheet sheet = this.getSheet();
48  		return sheet.getRow(sheet.getFirstRowNum());
49  	}
50  	
51  	public int size()
52  	{
53  		return this.getSheet().getPhysicalNumberOfRows();
54  	}
55  
56  	public IModel model(Object obj)
57  	{
58  		return new ExcelRowModel( (HSSFRow) obj);
59  	}
60  
61  }