first: poi 3.14 要求jdk1.6 或以上
jar包去apache下载就可以了.
另外,要完整运行需要xmlbeans 的jar包, 我下的是 xmlbeans-2.6.0.jar
附件里有 项目所用jar包,测试用的excel,及该项目
项目总共需要3个jar包,除jdk外:
1 poi-3.14-xxxx.jar
2 xmlbeans-2.6.jar
3 poi-ooxml-3.14-xxx.jar
代码如下:
/** * */ package helloWorld.com.cpic; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; import org.apache.poi.EncryptedDocumentException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.WorkbookFactory; /** * poi读excel文件内容 * @author c_liuhaibin * @version 2016年6月16日 */ public class ReadSXLSFile { public static void main(String[] x) throws EncryptedDocumentException, InvalidFormatException, IOException { String fullFileName ="G:/360data/重要数据/桌面/aaa.xls"; //"G:/360data/重要数据/桌面/aaa.xlsx"; ReadSXLSFile x1 = new ReadSXLSFile(); List<List> list=x1.readFile(fullFileName); for (List inlist : list) { for (Object object : inlist) { System.out.println(object.toString()); } } } /** * read excel file * @param file Ful Name:include file path * @return list * @throws EncryptedDocumentException * @throws InvalidFormatException * @throws IOException */ public List<List> readFile(String fileName) throws EncryptedDocumentException, InvalidFormatException, IOException { //官网说这种方式可以兼容两种格式的excel,03 and 07 的. List<List> list = new ArrayList<List>(); Workbook workbook = WorkbookFactory.create(new File(fileName)); List<Object> inList = null; for (Sheet sheet : workbook) { System.out.println("sheetName:" + sheet.getSheetName()); for (Row row : sheet) { inList = new ArrayList<Object>(); for (Cell cell : row) { switch (cell.getCellType()) { // 字符串 case Cell.CELL_TYPE_STRING: System.out.print("字符串:"+cell.getRichStringCellValue().getString()); //? or getStringCellValue? inList.add(cell.getRichStringCellValue()); break; case Cell.CELL_TYPE_NUMERIC: // 日期 if (DateUtil.isCellDateFormatted(cell)) { inList.add(cell.getDateCellValue()); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-mm-dd"); System.out.print("日期:"+sdf.format(cell.getDateCellValue())); } // 数字 else { inList.add(cell.getNumericCellValue()); System.out.print("数字:"+cell.getNumericCellValue()); } break; // 布尔 case Cell.CELL_TYPE_BOOLEAN: inList.add(cell.getBooleanCellValue()); System.out.print("布尔:"+cell.getBooleanCellValue()); break; // 公式 case Cell.CELL_TYPE_FORMULA: inList.add(cell.getCellFormula()); System.out.print("公式:"+cell.getCellFormula()); break; default: System.out.print("error "); } } System.out.println(); list.add(inList); } } return list; } }
只写写helloWorld 当然没问题了,不过还有两个问题,希望高人出来指点一下:
1 cell.getRichStringCellValue() 跟 getStringCellValue 有啥区别?
2 为什么我测试用的excel的日期类型总是以数字格式读出来的?
相关推荐
poi操作Excel 包含HSSF,XSSF两种方式的导入导出 支持97-2003版本的Excel与2007等高版本的Excel 下载之后eclipse导入替换jdk直接运行即可
poi3.14开发pdf,word等需要的jar包
poi3.14jar包poi3.14jar包poi3.14jar包poi3.14jar包poi3.14jar包poi3.14jar包
poi jar包,3.14版本 poi-3.14-20160307.jar poi-examples-3.14-20160307.jar poi-excelant-3.14-20160307.jar poi-ooxml-3.14-20160307.jar poi-ooxml-schemas-3.14-20160307.jar poi-scratchpad-3.14-20160307....
poi3.14支持excel 2014 包含多个jar包
poi 3.14需要的jar包
apache-poi3.14 所有的架包:curvesapi-1.03、poi-3.14、poi-ooxml-3.14、poi-ooxml-schemas-3.14、stax-api-1.0.1、xmlbeans-2.6.0
Apache POI HSSF和XSSF读写EXCEL总结
一个项目,其中实现了jxl 对于excl 的操作(单元格,图片,折线图,合并单元格)。使用poi 操作doc,excel和pdf实现相应的功能。
想尽快的使用HSSF和XSSF对电子表格进行操作吗?这个指南正是您所需要的。现在稳定的POI的版本为3.6。但最近在查阅POI的资料时发现,虽然资料很多,但是大都局限于2.x的版本,3.x中文资料比较少,查阅apache网站的...
poi-src-3.14-20160307.zip 【POI 3.14源码包src, source】, 导入Eclipse中进行源码和注释查看。
POI操作Excel详解,HSSF和XSSF文章源码 开发中经常会设计到excel的处理,如导出Excel,导入Excel到数据库中,操作Excel目前有两个框架,一个是apache 的poi
poi依赖jar包3.14
POI-HSSF和POI-XSSF和SXSSF(自POI 3.8 beta3起)-用于访问Microsoft Excel格式文件
poi excel poi excel poi excel poi excel poi excel poi excel poi excel poi excel
POI3.5_HSSF_和XSSF_Excel操作快速入门手册.pdf
jxl.jar 和 poi3.14.jar java Excel读写,jxl包无法解析xlsx格式文件
自己花了几天时间写的基于Apache POI的Java 读取excel文件,功能还是比较齐全
里面包含各种jar包,导入POI-3.14-2016..以及lib下的包即可使用!里面包含各种jar包,导入POI-3.14-2016..以及lib下的包即可使用!里面包含各种jar包,导入POI-3.14-2016..以及lib下的包即可使用!