通过cell.getNumericCellValue() 读取时异常,如:
读取出来的值变成 1.324654678E9
解决方案:
cell.setCellType(1); cellValue = cell.getStringCellValue() + "";
设置类型,并以字符串的方式直接读取。会发现有如下变化:
变成
setCellType(int cellType); 设置单元格的类型(数字,公式或字符串)。
Poi核心类:http://blog.csdn.net/seven__________7/article/details/53332365
简易导入dome(转载)
下载地址:http://download.csdn.net/download/dcb_ripple/10187759
版本兼容问题2003/2007
由于版本问题存在,2003使用
HSSFWorkbook 而2007支持XSSFWorkbook
File file = new File(path); //解决版本兼容问题 Workbook wb = null; try { wb = new HSSFWorkbook(new FileInputStream(file));//支持excel 2003 } catch (Exception e) { wb = new XSSFWorkbook(new FileInputStream(file));//支持excel 2007 } //获取第一张表 Sheet sheet = wb.getSheetAt(0);
也可以通过后缀名判断
//文件的后缀名 String suffix = url.substring(url.lastIndexOf(".")); if(".xls".equals(suffix)){ //支持07版本以前的excel book= new HSSFWorkbook(inputStream); }else if(".xlsx".equals(suffix)){ //支持07版本以后的excel book = new XSSFWorkbook(inputStream); }else{ System.out.println("不支持的文件类型!"); }版本兼容:https://www.cnblogs.com/liuyanxia/p/6732067.html
Struts2文件上传时会将所上传文件变成.tmp后缀的临时文件,可以通过前端获取后缀名。
var files = document.getElementById("files").value; if (null == files || '' == files) { $.messager.alert('温馨提示','请先选择文件!','info'); return false; } var ldot = files.lastIndexOf("."); var type = files.substring(ldot + 1); if(type == "XLS" || type =="XLSX" || type == "xls" || type =="xlsx") { //后台操作.... }else{ $.messager.alert('温馨提示','上传的文件类型不支持!','info'); //清除当前所选文件 var file = $("#files"); file.after(file.clone().val("")); file.remove(); }
End.