其实直接通过POI,比较简单的就可以实现了,但是自己又开始抽筋了,要做一番设计。
封装一下POI吧,这样感觉干净些。
原生的POI少了两个特性,一个是过滤,一个是数据绑定。
我先定义接口:
public interface IWorkbook extends IConstants { public ISheet getSheetAt(int index); public ISheet createSheet(String name); public ISheet cloneSheet(int index); public ISheet cloneSheet(String name); public void removeSheet(String name); public Iterator<ISheet> iterator(); public Iterator<ISheet> iterator(ISheetFilter filter); public void write(File file) throws IOException, Exception; public IWorkbook read(File file) throws IOException, Exception; }
public interface ISheet extends IConstants { public IRow getRow(int index); public Iterator<IRow> iterator(); public Iterator<IRow> iterator(IRowFilter filter); public IRow createRow(int index); public String getName(); public ISheet setName(String name); public IWorkbook getWorkbook(); }
public interface IRow extends IConstants { public ICell getCell(String x); public <T> T bind(IRowBinder<T> irb); public ICell createCell(String x,int cellType); public ICell createCell(String x); public <T> void marshall(IRowMarshaller<T> marshaller,T t); public int getRowNum(); public ISheet getSheet(); }
public interface ICell extends IConstants, Evaluatable { public final static int CELL_TYPE_NUMERIC = 0; public final static int CELL_TYPE_STRING = 1; public final static int CELL_TYPE_FORMULA = 2; public final static int CELL_TYPE_BLANK = 3; public final static int CELL_TYPE_BOOLEAN = 4; public final static int CELL_TYPE_ERROR = 5; public void setValue(Object value); public void setValue(Object value, String dataFormat); public int getType(); public String getKey(); public IRow getRow(); public ICellValue getCellValue(); }