到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();
}