1.导入POI包
poi-3.6-20091214.下载地址:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="java.io.OutputStream"%>
<%@ page import="org.apache.poi.hssf.usermodel.* "%>
<%
//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();
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();
%>