public void exportExcel(HttpServletRequest request,
HttpServletResponse response) {
try {
String fname = "test";// Excel文件名
OutputStream os = response.getOutputStream();
response.setHeader("Content-disposition", "attachment; filename="+ fname + ".xls");
response.setContentType("application/msexcel");
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
wb.setSheetName(0,"话费详单",HSSFWorkbook.ENCODING_UTF_16); //具体含义展位秦楚
HSSFRow row=sheet.createRow((short)0);
sheet.createFreezePane(0,1);
cteateCell(wb,row,(short)0,"手机号码");
cteateCell(wb,row,(short)1,"呼叫类型");
cteateCell(wb,row,(short)2,"对方号码");
cteateCell(wb,row,(short)3,"起始时间");
cteateCell(wb,row,(short)4,"通话时间");
cteateCell(wb,row,(short)5,"通话地点");
cteateCell(wb,row,(short)6,"长途类型");
cteateCell(wb,row,(short)7,"基本话费");
cteateCell(wb,row,(short)8,"长话费");
cteateCell(wb,row,(short)9,"总话费");
wb.write(os);
os.flush();
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}// 取得输出流
}
private void cteateCell(HSSFWorkbook wb,HSSFRow row,short col,String val){
HSSFCell cell=row.createCell(col);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(val);
HSSFCellStyle cellstyle=wb.createCellStyle();
cellstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION);
cell.setCellStyle(cellstyle);
}
这代码导不出excel啊
HttpServletResponse response) {
try {
String fname = "test";// Excel文件名
OutputStream os = response.getOutputStream();
response.setHeader("Content-disposition", "attachment; filename="+ fname + ".xls");
response.setContentType("application/msexcel");
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
wb.setSheetName(0,"话费详单",HSSFWorkbook.ENCODING_UTF_16); //具体含义展位秦楚
HSSFRow row=sheet.createRow((short)0);
sheet.createFreezePane(0,1);
cteateCell(wb,row,(short)0,"手机号码");
cteateCell(wb,row,(short)1,"呼叫类型");
cteateCell(wb,row,(short)2,"对方号码");
cteateCell(wb,row,(short)3,"起始时间");
cteateCell(wb,row,(short)4,"通话时间");
cteateCell(wb,row,(short)5,"通话地点");
cteateCell(wb,row,(short)6,"长途类型");
cteateCell(wb,row,(short)7,"基本话费");
cteateCell(wb,row,(short)8,"长话费");
cteateCell(wb,row,(short)9,"总话费");
wb.write(os);
os.flush();
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}// 取得输出流
}
private void cteateCell(HSSFWorkbook wb,HSSFRow row,short col,String val){
HSSFCell cell=row.createCell(col);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(val);
HSSFCellStyle cellstyle=wb.createCellStyle();
cellstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION);
cell.setCellStyle(cellstyle);
}
这代码导不出excel啊
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货