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

首頁(yè) > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

POI解析excel表格數(shù)據(jù)例子

2019-11-14 11:32:36
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
例子包含解析2003及之前版本和2007及之后版本。
/** * @author Yuansheng.Lei * Excel表格導(dǎo)入工具類 */public class PoiExcel { public static List<Dto> getDataByPoi(String filePath){ Workbook wb = null; InputStream stream = null; Sheet sheet = null; try { stream = new FileInputStream(filePath); if (filePath.endsWith(".xls")) { wb = (Workbook)new HSSFWorkbook(stream); }else if (filePath.endsWith(".xlsx")) { wb = (Workbook)new XSSFWorkbook(stream); } sheet = wb.getSheetAt(0); }catch (Exception e) { e.PRintStackTrace(); }finally{ if (stream != null) { try { stream.close(); } catch (IOException e) { e.printStackTrace(); } } } List<Dto> list = null; if( sheet != null ){ int count_row = sheet.getLastRowNum();//獲取最后一行行數(shù) int count_cell= sheet.getRow(1).getPhysicalNumberOfCells();//獲取第一行單元格數(shù) Row row = null; Cell cell = null; list = new ArrayList<Dto>(); for (int i = 1; i <= count_row; i++) { Dto dto = Dtos.newDto(); row = sheet.getRow((short)i); for (int j = 0; j < count_cell; j++) { cell = row.getCell((short)j); dto.put("a"+(j+1), getValue(cell)); } list.add(dto); } } return list; } @SuppressWarnings("deprecation") public static String getValue(Cell cell){ String cellvalue = ""; if(cell != null){ switch (cell.getCellType()) { case Cell.CELL_TYPE_STRING: cellvalue = cell.getRichStringCellValue().getString(); //獲取字符串 break; case Cell.CELL_TYPE_FORMULA: case Cell.CELL_TYPE_NUMERIC: if (HSSFDateUtil.isCellDateFormatted(cell)) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); cellvalue = sdf.format(cell.getDateCellValue()); //獲取時(shí)間 }else if(cell.getCellStyle().getDataFormatString().indexOf("%") != -1){ ellvalue = (new DecimalFormat("0").format(cell.getNumericCellValue()*100))+"%"; //獲取帶%的百分比 }else { cellvalue = String.valueOf(new DecimalFormat("0").format(cell.getNumericCellValue())); //獲取數(shù)字 } break; case Cell.CELL_TYPE_BOOLEAN: cellvalue = String.valueOf(cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_BLANK: cellvalue = ""; break; default : cellvalue = ""; break; } } return cellvalue; }}

相關(guān)jar包如下: 這里寫圖片描述


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 盐山县| 密山市| 蒙城县| 兴仁县| 潍坊市| 嘉义市| 肥西县| 周至县| 唐河县| 咸丰县| 沙坪坝区| 雷山县| 甘洛县| 达尔| 高台县| 阿勒泰市| 盐池县| 丁青县| 德格县| 五河县| 普兰县| 无锡市| 娄烦县| 许昌市| 安新县| 申扎县| 万安县| 顺义区| 丹棱县| 长岭县| 安仁县| 民丰县| 吐鲁番市| 呼玛县| 海阳市| 自治县| 祁东县| 临猗县| 信宜市| 云霄县| 宣化县|