有什么简单的方法可以把.jsp中的数据导出到excel中. 如题,谢谢了. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 刚写好的代码,还热的呢<%@ page import="java.io.OutputStream" %><%@ page import="org.apache.poi.hssf.usermodel.*,java.util.*,"%><%//Get criteriaString xlsName =request.getParameter("xlsName");if (xlsName == null || xlsName.equals("")) xlsName = "newexcel.xls";else xlsName =xlsName + ".xls";//Set respond type for excelresponse.reset();response.setContentType("application/vnd.ms-excel");response.setHeader("Content-Disposition", "attachment;filename=" + xlsName);OutputStream os=response.getOutputStream();//Create excel workbookHSSFRow row;HSSFCell cell;HSSFWorkbook wb = new HSSFWorkbook();HSSFSheet sheet = wb.createSheet("Records"); row = sheet.createRow( (short) 0); cell = row.createCell((short) 0);cell.setCellValue("ACCOUNT");cell = row.createCell((short) 1);cell.setCellValue("Fund");cell = row.createCell((short) 2);cell.setCellValue("Old Balance");cell = row.createCell((short) 3);cell.setCellValue("New Balance");cell = row.createCell((short) 4);cell.setCellValue("Charge Time");cell = row.createCell((short) 5);cell.setCellValue("Charge Type");cell = row.createCell((short) 6);cell.setCellValue("Operator");for (int i=1; i<100;i++){ pay=(PaymentVO)allRecord.get(i-1); row = sheet.createRow( (short) i); cell = row.createCell((short) 0); cell.setCellValue("12345"); //cell.setCellValue(cdrVO.getCallNumber()); cell = row.createCell((short) 1); cell.setCellValue("100"); //cell.setCellValue cell = row.createCell((short) 2); cell.setCellValue("0.0") cell = row.createCell((short) 3); cell.setCellValue("100.0"); cell = row.createCell((short) 4); cell.setCellValue("2006-08-25"); cell = row.createCell((short) 5); cell.setCellValue("web"); cell = row.createCell((short) 6); cell.setCellValue("123456"); } //Write to client sidewb.write(os); os.flush();os.close();%> <%@ page import="java.io.OutputStream" %><%@ page import="org.apache.poi.hssf.usermodel.*,java.util.*,"%><%//Get criteriaString xlsName =request.getParameter("xlsName");if (xlsName == null || xlsName.equals("")) xlsName = "newexcel.xls";else xlsName =xlsName + ".xls";//Set respond type for excelresponse.reset();response.setContentType("application/vnd.ms-excel");response.setHeader("Content-Disposition", "attachment;filename=" + xlsName);OutputStream os=response.getOutputStream();//Create excel workbookHSSFRow row;HSSFCell cell;HSSFWorkbook wb = new HSSFWorkbook();HSSFSheet sheet = wb.createSheet("Records"); row = sheet.createRow( (short) 0); cell = row.createCell((short) 0);cell.setCellValue("ACCOUNT");cell = row.createCell((short) 1);cell.setCellValue("Fund");cell = row.createCell((short) 2);cell.setCellValue("Old Balance");cell = row.createCell((short) 3);cell.setCellValue("New Balance");cell = row.createCell((short) 4);cell.setCellValue("Charge Time");cell = row.createCell((short) 5);cell.setCellValue("Charge Type");cell = row.createCell((short) 6);cell.setCellValue("Operator");for (int i=1; i<100;i++){ pay=(PaymentVO)allRecord.get(i-1); row = sheet.createRow( (short) i); cell = row.createCell((short) 0); cell.setCellValue("12345"); //cell.setCellValue cell = row.createCell((short) 1); cell.setCellValue("100"); //cell.setCellValue cell = row.createCell((short) 2); cell.setCellValue("0.0") cell = row.createCell((short) 3); cell.setCellValue("100.0"); cell = row.createCell((short) 4); cell.setCellValue("2006-08-25"); cell = row.createCell((short) 5); cell.setCellValue("web"); cell = row.createCell((short) 6); cell.setCellValue("123456"); } //Write to client sidewb.write(os); os.flush();os.close();%> 上面仁兄的代码太复杂,我也用过,还的用java的类,有没有简单的方法,比如一个纯粹的.htm或.jsp,怎么能转换成excel. 呵呵,有一个更好的方法,给钱请别人做!或者用crl+c和ctr+v慢慢弄,什么都不用想! 这个我做过,用excel做一个文件另存为jsp。然后把这个jsp放到工程里面,就像一个普通的jsp一样,把要导出的数据用<%%>写到页面里面。当客户端请求这个页面时就会弹出保存为excel的对话框了。 刚才说的少了一点。在文件头加<%@ page language="java" pageEncoding="GBK" contentType="application/vnd.ms-excel; charset=GBK"%> 这么一句,才能下载。 jsp cookie 有效期问题 各位帮帮小弟,tomcat修改默认目录出错 传输问题 url传繁体字怎么做? 求救struts项目 发布后启动jboss 老是报错 TOMACT5.0+AXIS1_2的问题?(急,在线等) jsp,有关session过期问题,各位大虾们请速度帮小弟解决啊! 预编译的问题,急! 求jspsmart上传附件到ORACLE代码!谢谢. 新人请教 jsp如何比较日期!!急急急 jsp怎样将文件从一个文件夹转移到另外的一个文件夹
<%@ page import="org.apache.poi.hssf.usermodel.*,java.util.*,"%>
<%
//Get criteria
String xlsName =request.getParameter("xlsName");
if (xlsName == null || xlsName.equals("")) xlsName = "newexcel.xls";
else xlsName =xlsName + ".xls";
//Set respond type for excel
response.reset();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=" + xlsName);
OutputStream os=response.getOutputStream();
//Create excel workbook
HSSFRow row;
HSSFCell cell;
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Records"); row = sheet.createRow( (short) 0);
cell = row.createCell((short) 0);
cell.setCellValue("ACCOUNT");
cell = row.createCell((short) 1);
cell.setCellValue("Fund");
cell = row.createCell((short) 2);
cell.setCellValue("Old Balance");
cell = row.createCell((short) 3);
cell.setCellValue("New Balance");
cell = row.createCell((short) 4);
cell.setCellValue("Charge Time");
cell = row.createCell((short) 5);
cell.setCellValue("Charge Type");
cell = row.createCell((short) 6);
cell.setCellValue("Operator");for (int i=1; i<100;i++)
{
pay=(PaymentVO)allRecord.get(i-1);
row = sheet.createRow( (short) i);
cell = row.createCell((short) 0);
cell.setCellValue("12345"); //cell.setCellValue(cdrVO.getCallNumber());
cell = row.createCell((short) 1);
cell.setCellValue("100"); //cell.setCellValue
cell = row.createCell((short) 2);
cell.setCellValue("0.0")
cell = row.createCell((short) 3);
cell.setCellValue("100.0");
cell = row.createCell((short) 4);
cell.setCellValue("2006-08-25");
cell = row.createCell((short) 5);
cell.setCellValue("web");
cell = row.createCell((short) 6);
cell.setCellValue("123456");
}
//Write to client side
wb.write(os);
os.flush();
os.close();
%>
<%@ page import="org.apache.poi.hssf.usermodel.*,java.util.*,"%>
<%
//Get criteria
String xlsName =request.getParameter("xlsName");
if (xlsName == null || xlsName.equals("")) xlsName = "newexcel.xls";
else xlsName =xlsName + ".xls";
//Set respond type for excel
response.reset();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=" + xlsName);
OutputStream os=response.getOutputStream();
//Create excel workbook
HSSFRow row;
HSSFCell cell;
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Records"); row = sheet.createRow( (short) 0);
cell = row.createCell((short) 0);
cell.setCellValue("ACCOUNT");
cell = row.createCell((short) 1);
cell.setCellValue("Fund");
cell = row.createCell((short) 2);
cell.setCellValue("Old Balance");
cell = row.createCell((short) 3);
cell.setCellValue("New Balance");
cell = row.createCell((short) 4);
cell.setCellValue("Charge Time");
cell = row.createCell((short) 5);
cell.setCellValue("Charge Type");
cell = row.createCell((short) 6);
cell.setCellValue("Operator");for (int i=1; i<100;i++)
{
pay=(PaymentVO)allRecord.get(i-1);
row = sheet.createRow( (short) i);
cell = row.createCell((short) 0);
cell.setCellValue("12345"); //cell.setCellValue
cell = row.createCell((short) 1);
cell.setCellValue("100"); //cell.setCellValue
cell = row.createCell((short) 2);
cell.setCellValue("0.0")
cell = row.createCell((short) 3);
cell.setCellValue("100.0");
cell = row.createCell((short) 4);
cell.setCellValue("2006-08-25");
cell = row.createCell((short) 5);
cell.setCellValue("web");
cell = row.createCell((short) 6);
cell.setCellValue("123456");
}
//Write to client side
wb.write(os);
os.flush();
os.close();
%>
有没有简单的方法,比如一个纯粹的.htm或.jsp,怎么能转换成excel.
contentType="application/vnd.ms-excel; charset=GBK"%> 这么一句,才能下载。