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

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

jxl解析excel表格代碼

2019-11-14 11:38:31
字體:
來源:轉載
供稿:網友

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; }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 泰和县| 太白县| 海安县| 桃江县| 全南县| 泗洪县| 盐城市| 忻州市| 台湾省| 德格县| 海阳市| 余干县| 阿巴嘎旗| 昌邑市| 阳城县| 四子王旗| 广宁县| 车致| 蓝山县| 新竹县| 洞头县| 仁寿县| 临夏市| 交口县| 上虞市| 湘潭市| 天峨县| 德昌县| 墨脱县| 宣汉县| 内江市| 蕲春县| 商水县| 婺源县| 都安| 海丰县| 班玛县| 永修县| 巫溪县| 历史| 都江堰市|