poi实现Excel模板化数据读写
来源:互联网 发布:火绒 windows defender 编辑:程序博客网 时间:2024/05/20 23:07
模板实例
生成临时Excel文件
String newPath="临时文件存放路径";
ExcelHandle handle = new ExcelHandle();String path=newPath+"\\"+fileName;handle.writeListData(modelPath, infoMap, 0);File file = new File(path);OutputStream os = new FileOutputStream(file);//写到输出流并关闭资源handle.writeAndClose(modelPath, os);os.flush();os.close();handle.readClose(path);
excel下载
{ OutputStream os = null; FileInputStream fis = null; File destFile = null;
//获取文件名称 String fileName=path.substring(path.lastIndexOf("\\")+1,path.lastIndexOf(".")); try { // compress(path, destPath); destFile = new File(path); fileName = new String(fileName.getBytes("gbk"), "ISO-8859-1"); response.setContentType("application/xlsx"); response.addHeader("Content-Length", "" + destFile.length()); response.setHeader("Content-disposition", "attachment; filename=" + fileName + ".xlsx"); fis = new FileInputStream(destFile); os = response.getOutputStream(); byte[] buf = new byte[1024]; int len = 0; while ((len = fis.read(buf)) != -1) { os.write(buf, 0, len); } } catch (Exception e) { e.printStackTrace(); } finally { try { if (null != os) { os.close(); } if (null != fis) { fis.close(); } } catch (Exception e) { e.printStackTrace(); } finally { File file = new File(path.substring(0, path.lastIndexOf(File.separator))); File[] files = file.listFiles(); for (File temp : files) { if(null != temp && temp.exists() && temp.isFile()){ temp.delete(); } } if(null != destFile && destFile.exists() && destFile.isFile()){ destFile.delete(); } } }}
0 0
- poi实现Excel模板化数据读写
- poi读写excel数据
- poi实现根据excel模板,生成excel并导入数据
- 使用POI读写excel数据
- poi实现Excel文件读写
- Java poi实现导出excel,添加数据有效性,生成模板
- java的poi技术读写excel数据
- POI实现超大数据的Excel的读写操作,支持Excel最大行数。
- 用poi实现excel的读写
- Poi 读写Excel 合并ExcelSheet Struts2实现
- 使用POI实现Java读写Excel文件
- POI:实现读写Excel完整示例
- 使用Poi实现Java读写Excel (一)
- Java POI 读写Excel 文件简单实现
- Apache POI 实现对 Excel 文件读写
- 用poi,加载excel模板导出数据
- POI按照模板导出Excel数据
- poi实现Excel模板的报表导出
- WebSocket在ASP.NET MVC4中的简单实现
- js 实现自动更新倒计时效果
- 集合的子集
- 使用Crontab定时执行任务
- Vertica 安装,建库,新建测试用户并授予权限,建表,入库
- poi实现Excel模板化数据读写
- Intersection of Two Linked Lists
- 02 讲:用 Python 设计第一个游戏
- 王朝 是否有B或b
- 知识点随记
- 项目初识
- Struts入门实例(2)--Action<1>
- 交换--Swap
- ArrayList的排序