package read;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import entity.XlsEntity;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
public class ReadXls {
Workbook rwb=null;
int sheets=0;
String index=null;
static int sum=1;
List<XlsEntity> list = new ArrayList<XlsEntity>();
public List<XlsEntity> qurry(String local,String idx){
try{
InputStream is = new FileInputStream(local);
rwb = Workbook.getWorkbook(is);
sheets=rwb.getNumberOfSheets();
}catch (Exception e)
{
e.printStackTrace();
}
index=idx;
for(int i=0;i<sheets;i++){
Sheet rs = rwb.getSheet(i);
for(int j=1;j<rs.getRows();j++){
for(int k=0;k<rs.getColumns();k++){
Cell cl=rs.getCell(k,j);
String str = cl.getContents();
if(str.equals(index)){
XlsEntity xe=new XlsEntity();
xe.setIndex(str);
xe.setCode(rs.getCell(4, j).getContents());
xe.setName(rs.getCell(5, j).getContents());
list.add(xe);
sum++; //测试量:显示记录数目
}
}
}
}
return list;
}
public static void main(String[] args){
ReadXls rx=new ReadXls();
Iterator<XlsEntity> it = rx.qurry("D:/纸业物资2010-8-14.XLS", "06-1").iterator();
while(it.hasNext()){
XlsEntity x1=it.next();
System.out.print(x1.getIndex()+" ");
System.out.print(x1.getCode()+" ");
System.out.println(x1.getName());
}
System.out.println(sum);
}
}