java获取excel里面的内容(点提取)
来源:互联网 发布:java怎么上传图片 编辑:程序博客网 时间:2024/06/05 00:45
1.HSSF获取
File file = new File(filePath);FileInputStream inputExcel = null;inputExcel = new FileInputStream(file);//xls读取POIFSFileSystem fsExcel = null; HSSFWorkbook wbExcel = null; fsExcel = new POIFSFileSystem(inputExcel);wbExcel = new HSSFWorkbook(fsExcel);//0为sheet页HSSFSheet sheet = wbExcel.getSheetAt(0);2.XSSF读取
File file = new File(filePath);FileInputStream inputExcel = null;inputExcel = new FileInputStream(file);//xlsx读取XSSFWorkbook XSSFwb = new XSSFWorkbook(inputExcel);XSSFSheet sheet = XSSFwb.getSheetAt(0); inSaveExcel(null,sheet,tokenID,sampleNo);
-----------excel点提取---------------------
点提取首先确定好需要提取的单元格
例如 String []cellPosList = {“A12”,“B2”,“C1”};
List<String> strList = new ArrayList<String>();for (String s : cellPosList){String st = null;//指定单元格(点读取)if(HSSFsheet != null){HSSFRow rowNumber = HSSFsheet.getRow(SMSReportUtils.findCurrentRow(s));HSSFCell cell = rowNumber.getCell(SMSReportUtils.findCurrentColumn(s));st = getCellValue(cell);}if(XSSFsheet != null){XSSFRow row = XSSFsheet.getRow(SMSReportUtils.findCurrentRow(s));XSSFCell cell = row.getCell(SMSReportUtils.findCurrentColumn(s)); st = getCellValue(cell);}if(StringUtils.isBlank(st)){st = " ";}strList.add(st);}根据单元格的type获取相应的value
public static String getCellValue(Cell cell){String value = null;if(cell != null){switch(cell.getCellType()){case HSSFCell.CELL_TYPE_FORMULA:cell.getCellFormula(); try {value = String.valueOf(cell.getNumericCellValue());} catch (IllegalStateException e) {value = String.valueOf(cell.getRichStringCellValue());}break;case HSSFCell.CELL_TYPE_NUMERIC:int style = cell.getCellStyle().getDataFormat(); if (HSSFDateUtil.isCellDateFormatted(cell)) { Date date = cell.getDateCellValue(); switch (style) { case 178: value = new SimpleDateFormat("yyyy'年'M'月'd'日'").format(date); break; case 14: value = new SimpleDateFormat("yyyy/MM/dd").format(date); break; case 179: value = new SimpleDateFormat("yyyy/MM/dd HH:mm").format(date); break; case 181: value = new SimpleDateFormat("yyyy/MM/dd HH:mm a ").format(date); break; case 22: value = new SimpleDateFormat(" yyyy/MM/dd HH:mm:ss ").format(date); break; default: break; } }else{HSSFDataFormatter dataFormatter = new HSSFDataFormatter(); String cellFormatted = dataFormatter.formatCellValue(cell);//double dou = cell.getNumericCellValue();//BigDecimal bd = new BigDecimal(Double.toString(dou)); //读取-0.000125的值等等。。。//value = bd.toPlainString(); value = cellFormatted;}break;case HSSFCell.CELL_TYPE_STRING:value = String.valueOf(cell.getStringCellValue());break;}}return value;}
阅读全文
0 0
- java获取excel里面的内容(点提取)
- 正则那点事之如何提取字符串中方括号里面的内容
- 获取EXCEL里面的数据
- java获取Excel单元格内容
- VB.NET读取EXCEL 里面的内容
- BeautifulSoup 提取某个tag标签里面的内容
- 提取字符串里面的数字【java】
- [MFC]获取文本框里面的内容
- VB 获取 Internet Explorer_Server 里面的内容
- VB 获取 Internet Explorer_Server 里面的内容
- 微信小程序获取input里面的内容
- js获取div对象里面的内容
- JavaScript获取iframe里面的src路径里面的内容
- java读取excel、txt 文件内容,传到、显示到另一个页面的文本框里面。
- java获取excel指定行内容
- 用正则表达式获取网页里面的内容/java面试题
- 常见的 特征点 提取 概念等内容
- 一个将数据库里面的内容生成EXCEL的例子
- HDU
- 马虎的算式
- [arc066f]Contest with Drinks Hard
- 171116 Keras-Multiple inputs and outputs
- linux中一个tomcat的一个端口可以启动多个工程(工程名要不一样)
- java获取excel里面的内容(点提取)
- hadoop2.7.1对应的hadoop.dll,winutils.exe
- 廖雪峰——作业
- 信息学奥赛一本通(C++版) 第二部分 基础算法 第七章 分治算法
- bootstrapvalidator 验证用户名存在
- select 不可编辑样式 后端无法取值
- spring boot 配置 https|ssl
- 使用RecyclerView实现QQ空间广告位一个位置两个图时偶遇bug
- CentOS用yum安装X Window