首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

关于Action处置导出Excel

2012-08-25 
关于Action处理导出ExcelInputStream inputStreamnull??try {???inputStream new FileInputStream(fil

关于Action处理导出Excel
InputStream inputStream=null;
??try {
???inputStream = new FileInputStream(filePath);
???ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); // 下面5行代码实现从输入流?FileInputStream 到 输出流 ByteArrayOutputStream 写入的过程
???byte[] buffer = new byte[inputStream.available()];
???int iLength = 0;
???while ((iLength = inputStream.read(buffer)) != -1) {
????outputStream.write(buffer, 0, iLength);
???} // 通知response的输出类型,输出方式及输出内容
???fileName=new String(fileName.getBytes("GBK"),"ISO-8859-1");
???response.addHeader("Content-Disposition",
?????"attachment; filename="+fileName+"");
???response.setContentType("application/octet-stream");
???response.setContentLength(outputStream.size());
???ServletOutputStream out = response.getOutputStream();
???outputStream.writeTo(out);
???out.flush();
???inputStream.close();
???outputStream.close();

热点排行