国产探花免费观看_亚洲丰满少妇自慰呻吟_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; }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 如皋市| 凤冈县| 瓦房店市| 雅江县| 黄浦区| 宁阳县| 澜沧| 达州市| 姚安县| 镇坪县| 保亭| 西乌| 瑞丽市| 遂昌县| 涟水县| 通道| 泾阳县| 阳山县| 闵行区| 绥棱县| 香河县| 虞城县| 淮阳县| 房产| 涡阳县| 澄江县| 丹巴县| 临湘市| 榆中县| 岑溪市| 扎鲁特旗| 嘉鱼县| 建始县| 闵行区| 乐山市| 海林市| 聊城市| 博罗县| 仲巴县| 建水县| 顺平县|