1.首先需要设置格式response.setContentType("application/vnd.ms-excel;charset=UTF-8");
//Excel文件名称,及其编码格式
response.setHeader("Content-Disposition",
"attachment; filename=\""
+ URLEncoder.encode("文件名称" + ".xls", "utf-8") + "\"");
2.// 新建工作簿
WritableWorkbook wbook = Workbook.createWorkbook(response.getOutputStream());
// 新建sheet
WritableSheet sheet = wbook.createSheet("sheet", 0);
//新建单元格
Label lable = null;
//Excel文件字体颜色等信息
jxl.write.WritableFont wfc = new jxl.write.WritableFont(
WritableFont.ARIAL, 9, WritableFont.NO_BOLD, false,
jxl.format.UnderlineStyle.NO_UNDERLINE,
jxl.format.Colour.BLACK);
jxl.write.WritableCellFormat wcfFC = new jxl.write.WritableCellFormat(wfc);
lable = new Label(i, 0, "单元格内容", wcfFC);
//sheet增加单元格
sheet.addCell(lable);
//设置列的宽度
sheet.setColumnView(0, 18);
//Excel文件名称,及其编码格式
response.setHeader("Content-Disposition",
"attachment; filename=\""
+ URLEncoder.encode("文件名称" + ".xls", "utf-8") + "\"");
2.// 新建工作簿
WritableWorkbook wbook = Workbook.createWorkbook(response.getOutputStream());
// 新建sheet
WritableSheet sheet = wbook.createSheet("sheet", 0);
//新建单元格
Label lable = null;
//Excel文件字体颜色等信息
jxl.write.WritableFont wfc = new jxl.write.WritableFont(
WritableFont.ARIAL, 9, WritableFont.NO_BOLD, false,
jxl.format.UnderlineStyle.NO_UNDERLINE,
jxl.format.Colour.BLACK);
jxl.write.WritableCellFormat wcfFC = new jxl.write.WritableCellFormat(wfc);
lable = new Label(i, 0, "单元格内容", wcfFC);
//sheet增加单元格
sheet.addCell(lable);
//设置列的宽度
sheet.setColumnView(0, 18);