/** * 读取Excel测试,兼容 Excel 2003/2007/2010 */ public String readExcel() { SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); try { //同时支持Excel 2003、2007 File excelFile = new File("d:\\车贷452423197602010016徐华昌.xlsx"); //创建文件对象 FileInputStream is = new FileInputStream(excelFile); //文件流 Workbook workbook = WorkbookFactory.create(is); //这种方式 Excel 2003/2007/2010 都是可以处理的 int sheetCount = workbook.getNumberOfSheets(); //Sheet的数量 //遍历每个Sheet for (int s = 0; s < sheetCount; s++) { Sheet sheet = workbook.getSheetAt(s); int rowCount = sheet.getPhysicalNumberOfRows(); //获取总行数 //遍历每一行 for (int r = 0; r < rowCount; r++) { Row row = sheet.getRow(r); int cellCount = row.getPhysicalNumberOfCells(); //获取总列数 //遍历每一列 for (int c = 0; c < cellCount; c++) { Cell cell = row.getCell(c); if(cell!=null ){ int cellType = cell.getCellType(); String cellValue = null; switch(cellType) { case Cell.CELL_TYPE_STRING: //文本 cellValue = cell.getStringCellValue(); break; case Cell.CELL_TYPE_NUMERIC: //数字、日期 if(DateUtil.isCellDateFormatted(cell)) { cellValue = fmt.format(cell.getDateCellValue()); //日期型 } else { cellValue = String.valueOf(cell.getNumericCellValue()); //数字 } break; case Cell.CELL_TYPE_BOOLEAN: //布尔型 cellValue = String.valueOf(cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_BLANK: //空白 cellValue = cell.getStringCellValue(); break; case Cell.CELL_TYPE_ERROR: //错误 cellValue = "错误"; break; case Cell.CELL_TYPE_FORMULA: //公式 cellValue = "错误"; break; default: cellValue = "错误"; } System.out.print(cellValue + " "); } } System.out.println(); } } } catch (Exception e) { e.printStackTrace(); } return "success"; }
相关推荐
JS 读取Excel文件(xls) 兼容Chrome/IE/Firefox 文章配套工具
java 读取 Excel 读取 兼容2003,2007
java读取excel,并且兼容2003和2007. 附带实例 可自定义表头,行读取开始位置、结束位置,列开始位置、结束位置
java代码读取excel文件,同时兼容2003和2007
java读取excel的工具类型,可同时支持excel2003和2007版本
java读取excel(兼容2003和2007)[定义].pdf
/*** * 读取Excel文件里数据... * 读取Excel的兼容性/03/07以上 * 参数一读取所需的文件对象 * 参数二自定义需要对应实体对象相关的属性 * 参数三将数据转化成对应的class实体对象 * 参数四从文档的第几行读取 */
poi读取excel2007和2003兼容工具例子.利用简单工厂方法
java 读取 Excel兼容2003,2007的项目,里面有需要的jar包和类
java 读取 Excel兼容2003,2007的项目,里面有需要的jar包和类
之前用jxl发现不支持excel2007,不得以就去用poi实现excel的读取了!本人亲测的一个实例,支持excel2007!
NULL 博文链接:https://cgs1999.iteye.com/blog/1525665
java编写的兼容2003、2007Excel文件读取工程,本人亲自编写
读取excel的时候,引用最高版本的dll,低版的客户端就无法加载excel实例,导致程序无法运行。使用NPOI,客户机可以不按照OFFICE,兼容32位和64位,可以导入导出,可以读取任意单元格。
NULL 博文链接:https://ahomeeye.iteye.com/blog/1571090
直接读取excel,兼容2003,以及2007以上版本,发送邮件源码,有问题可以直接加我
兼容解析 Excel2003 Excel2007 的工具 将Excel 每一行数据封装成map集合 方便开发者读取excel中数据 用到的jar包有 xmlbeans-5.1.6.jar 和 poi-bin-3.8-20120326.zip中的包
JAVA用POI读取和创建2003和2007版本Excel完美示例 同时还有相关的类包 注意工程里面别存在冲突类包
ExcelUtil万能读取类兼容03/07
c# .net 兼容Excel2003与2007上传 IWorkbook wk =null; if (filename.IndexOf(".xlsx") > 0) { wk = new XSSFWorkbook(fs); //把xlsx文件中的数据写入wk中 } else { wk = new HSSFWorkbook(fs); //把xls文件...