国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

jxl解析excel表格代碼

2019-11-14 10:14:25
字體:
來源:轉載
供稿:網友

jxl解析Excel表格代碼

/** * @author Yuansheng.Lei * excel表格導入工具類 */public class Excel { /** * 提取excel表信息 * @param filePath * @return * @throws IOException */ public static List<Dto> getData(String filePath){ //構造excel文件輸入流對象 InputStream is = null; Workbook workbook = null; List<Dto> list = null; try { is = new FileInputStream(filePath); //創建工作簿對象 workbook = Workbook.getWorkbook(is); //獲取工作簿的個數,對應于一個excel中的工作表個數 workbook.getNumberOfSheets(); //使用索引獲取第一個工作表,也可以使用 workbook.getSheet(sheetName),其中sheetName表示工作表的名稱 Sheet sheet = workbook.getSheet(0); int rows = sheet.getRows(); //獲取工作表的總行數 int columns = sheet.getColumns();//獲取工作表的總列數 list = new ArrayList<Dto>(); for (int i = 1; i < rows; i++) { Dto dto = Dtos.newDto(); for (int j = 0; j < columns; j++) { //注意:這里的getCell方法的參數,第一個指定第幾列,第二個參數才是指第幾行 Cell cell = sheet.getCell(j, i); if(cell.getType() == CellType.DATE){ DateCell dateCell = (DateCell) cell; dto.put("a"+(j+1),AOSUtils.date2String(dateCell.getDate(), "yyyy-MM-dd") ); }else{ dto.put("a"+(j+1), cell.getContents()); } } list.add(dto); } } catch (FileNotFoundException e) { throw new AOSException("未找到該路徑下的文件",e); // e.PRintStackTrace(); } catch (BiffException e) { throw new AOSException("工作簿對象創建不成功",e); // e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }finally{ if (workbook != null) { workbook.close();//關閉工作空間 } if (is != null) { try { is.close();//關閉流 } catch (IOException e) { e.printStackTrace(); } } } return list; }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 漾濞| 敦煌市| 阳江市| 磴口县| 华亭县| 廊坊市| 荥阳市| 蚌埠市| 南木林县| 大邑县| 泰安市| 盐津县| 澳门| 南靖县| 屏东县| 杭锦后旗| 汝南县| 大宁县| 尚志市| 青田县| 瓦房店市| 东丰县| 乐都县| 洛扎县| 上饶县| 孝义市| 来宾市| 磐石市| 乐平市| 安平县| 宜川县| 龙岩市| 马尔康县| 承德市| 富蕴县| 凤翔县| 铜鼓县| 安泽县| 罗定市| 麟游县| 繁峙县|