jxl解析Excel文件(简洁易用)

来源:互联网 发布:淘宝秒杀js脚本 编辑:程序博客网 时间:2024/04/19 17:43
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;}}

http://www.cnblogs.com/raymond19840709/archive/2008/06/26/1230289.html

http://lavasoft.blog.51cto.com/62575/174244/

http://www.blogjava.net/xing5156/archive/2011/11/18/364221.html

http://blog.csdn.net/superman4125/article/details/6457339

http://wenku.baidu.com/link?url=FHrIvE69Qwi8wXmuRvyo0B1_XjfsMCdiriM1pWDVsleRClOpZ6TMuGinrH1diFdiXiZbJLjN3kKMYYUzs-dIBIrxeTYMfJVl2yZiJXlG6Iu

http://blog.csdn.net/nature_fly088/article/details/38975949

如果有疑问欢迎加群:398918539

0 0
原创粉丝点击