/**
* 业务需求最简单的-Excel模板直接下载
* @param path fileName
* @return
*/
public static void exportExcel(String path,String fileName) throws FileNotFoundException, IOException {
Workbook book=null;
// 将该excel文件转成输入的流形式
FileInputStream is=new FileInputStream(new File(path));
//再根据后缀名转成 POI中Workbook工作薄对象
String ext = path.substring(path.lastIndexOf("."));
if(".xls".equals(ext)){
book=new HSSFWorkbook(is);
}else if(".xlsx".equals(ext)){
book=new XSSFWorkbook(is);
}
//获取当前客户端操作系统桌面路径
FileSystemView fsv = FileSystemView.getFileSystemView();
File com=fsv.getHomeDirectory();
String savePath = com.getPath();
//通过流形式下载 默认下载到当前桌面
path=savePath+"/"+fileName+ext;
book.write(new FileOutputStream(path));
}
业务需求最简单的-Excel模板直接下载
最新推荐文章于 2018-06-13 08:22:53 发布