JSP 如何实现显示 Excel文件??? 谁有例子,可以给我看一下吗?非常感谢!!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用SQL或者ACCESS把EXCEL导入然后在JSP中直接引用就行了 有个包是专门针对Excel文件的操作的,具体的你可以Google一下 <%@ 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();%> java3d 与 jME 哪个更优越呢,他们2兼容吗 建行支付接口问题 [struts]表中无数据如何在页面中显示相应的信息? 求Jive源码 有没有可能把C/S结构中的表格控件做成Java的Tag ??? hibernate新手提问,有空的帮我看一下。 中文传参问题,看了很多帖子都没解决. 如何作到一个连接中产生的多个记录集都正常使用 为何我的resin不能用apache 做服务器? 请问如何多表查询主表记录和每条记录总点击数并一起返回? 这种网页用jsp可以写吗? xsl的一点问题
然后在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();
%>