jxl解析Excel文件

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

    package util;  
      
    import java.io.File;  
    import java.io.IOException;  
    import java.text.SimpleDateFormat;  
    import java.util.ArrayList;  
    import java.util.Date;  
    import java.util.List;  
      
    import pojo.UserInfo;  
    import jxl.Cell;  
    import jxl.CellType;  
    import jxl.DateCell;  
    import jxl.Sheet;  
    import jxl.Workbook;  
    import jxl.read.biff.BiffException;  
      
    public class ExcelUtil {  
        /** 
         * 获取excel表格的数据 
         * @param path 文件路径 
         * @return 
         * @throws IOException  
         * @throws BiffException  
         */  
        public static List<UserInfo> getExcelDate() throws BiffException, IOException{  
            String[] info=null;  
            List<UserInfo> list=new ArrayList<UserInfo>();  
              
            File file = new File("F:\\userInfo.xls");  
            Workbook book = Workbook.getWorkbook(file);  
            // 获得第一个工作表对象  
            Sheet sheet = book.getSheet(0);  
            Cell cell=null;  
            int a=sheet.getRows();  
            int b=sheet.getColumns();  
            for (int i = 1; i < a ; i++){  
                info=new String[b];  
                for(int j = 0;j < b ; j++){  
                    cell = sheet.getCell(j, i);  
      
                    if(cell.getType()==CellType.DATE){//时间的处理  
                        DateCell dc = (DateCell)cell;  
                        Date date = dc.getDate();  
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
                        String sDate = sdf.format(date);  
                        info[j] = sDate;  
                    }else{  
                        info[j] = cell.getContents();  
                    }  
      
                }  
                UserInfo ui=arrayToObject(info);  
                list.add(ui);  
            }  
      
            return list;  
        }  
        /** 
         * 数组转对象 
         * @param info 
         * @return 
         */  
        private static UserInfo arrayToObject(String[] info){  
            UserInfo ui=new UserInfo();  
      
            ui.setAccountNum(info[0]);  
            ui.setCustomerName(info[1]);  
            ui.setMobile(info[2]);  
            ui.setServiceSales(info[3]);  
            ui.setTerminal(info[4]);  
            ui.setRecommend(info[5]);  
            ui.setSource(info[6]);  
            ui.setRegDate(info[7]);  
      
            return ui;  
        }  
      
    }