一、定义
Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能。
二、所需jar包:
三、简单的一个读取excel的demo
1、读取文件方法
/*** 读取出filePath中的所有数据信息
*@paramfilePath excel文件的绝对路径
**/
public static voidgetDataFromExcel(String filePath)
{//String filePath = "E:\\123.xlsx";//判断是否为excel类型文件
if(!filePath.endsWith(".xls")&&!filePath.endsWith(".xlsx"))
{
System.out.println("文件不是excel类型");
}
FileInputStream fis=null;
Workbook wookbook= null;try{//获取一个绝对地址的流
fis = newFileInputStream(filePath);
}catch(Exception e)
{
e.printStackTrace();
}try{//2003版本的excel,用.xls结尾
wookbook = new HSSFWorkbook(fis);//得到工作簿
}catch(Exception ex)
{//ex.printStackTrace();
try{//2007版本的excel,用.xlsx结尾
wookbook= new XSSFWorkbook(fis);//得到工作簿
} catch(IOException e)
{//TODO Auto-generated catch block
e.printStackTrace();
}
}//得到一个工作表
Sheet sheet = wookbook.getSheetAt(0);//获得表头
Row rowHead = sheet.getRo