站内搜索: 请输入搜索关键词

当前页面: 开发资料首页J2EE 专题用POI组件导出数据到EXCEL里,为什么不能在客户端导出呢?有什么好的办法。。。。

用POI组件导出数据到EXCEL里,为什么不能在客户端导出呢?有什么好的办法。。。。

摘要: 用POI组件导出数据到EXCEL里,为什么不能在客户端导出呢?有什么好的办法。。。。


用POI组件导出数据到EXCEL里,为什么不能在客户端导出呢?有什么好的办法。。。。


到www.apache.org下载poi,在工程中引入然后:

doGet(HttpServletRequest request,HttpServletResponse response) {
response.setContentType("application/vnd.ms-excel;charset=GBK");
response.setHeader("Content-Disposition","attachment;Filename=Report.xls");

OutputStream outStream = response.getOutputStream();

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");

// Create a row and put some cells in it. Rows are 0 based.
HSSFRow row = sheet.createRow((short)0);
// Create a cell and put a value in it.
HSSFCell cell = row.createCell((short)0);
cell.setCellValue(1);

// Or do it on one line.
row.createCell((short)1).setCellValue(1.2);
row.createCell((short)2).setCellValue("This is a string");
row.createCell((short)3).setCellValue(true);

wb.write(outStream);
outStream.flush();
}




用这种方法在服务器上面可以导出数据,但是在客户端就不能用了


客户端导出,什么意思?


就是在使用的客户也可以导出数据到他们本地硬盘上面(EXCEL格式)


客户端上点另存为就可以了,用什么导出?


学习


我也用这种方式(dreamover(梦醒了〖http://hellfire.cn〗) )试了一下,但是为什么我的生成的excel文件包含网页的所有内容,而数据并没有导呢?谁知道么?


↑返回目录
前一篇: 请问用hibernate新增一个记录后如何返回这条记录的自增ID?
后一篇: session里面的值又自动的给复制了,奇怪