我做的是导入学生信息包括每个学生对应的证件照图片,所以此处不仅需要获取excel中的图片,还需要获取图片的位置信息,比如--哪行哪列的图片对应的是哪个学生,具体代码如下:
public static void getDataFromExcel(String filePath) throws IOException
{
//String filePath = "E:\\123.xlsx";
//判断是否为excel类型文件
if(!filePath.endsWith(".xls")&&!filePath.endsWith(".xlsx"))
{
System.out.println("文件不是excel类型");
}
FileInputStream fis =null;
Workbook wookbook = null;
Sheet sheet =null;
try
{
//获取一个绝对地址的流
fis = new FileInputStream(filePath);
}
catch(Exception e)
{
e.printStackTrace();
}
try
{
//2003版本的excel,用.xls结尾
wookbook = new HSSFWorkbook(fis);//得到工作簿
}
catch (Exception ex)
{
//ex.printStackTrace();
try
{
//2007版本的excel,用.xlsx结尾
fis = new FileInputStream(filePath);
wookbook = new XSSFWorkbook(fis);//得到工作簿
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}