标签:excel
try{
OutputStream os = response.getOutputStream();
response.reset();// 清空输出流
String filename = "查询结果.xls"; //文件名
response.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition","attachment;filename=\""
+ new String(name.getBytes("gb2312"),"ISO8859-1") + "\"");// 设定输出文件头
response.setContentType("application/msexcel");// 定义输出类型
WritableWorkbook wwb= Workbook.createWorkbook(os);//建立excel文件
WritableFont font1= new WritableFont(WritableFont.TIMES,12,WritableFont.BOLD);
WritableCellFormat format1=new WritableCellFormat(font1);
format1.setAlignment(jxl.format.Alignment.CENTRE);
format1.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
WritableSheet ws= wwb.createSheet("查询结果",10); //创建表单
ws.addCell(new jxl.write.Label(j, i, "内容",format1));//往第i行、第j列添加内容为“内容”,格式为format1
ws.setRowView(0,300);//指定行的宽度,可省
ws.setColumnView(1,25);//指定列的宽度,可省
ws.mergeCells(0,0,9,0); //合并单元格从0行0列到0行第9列
ws.addCell(new jxl.write.Label(0, 0, "查询结果",format1)); //插入标题
wwb.write(); //将数据写入所见的excel
wwb.close();
os.close(); // 关闭流
}catch (Exception e) {
e.printStackTrace();
}
本文出自 “HAPPY_CANDY” 博客,谢绝转载!
标签:excel
原文地址:http://florait.blog.51cto.com/7692437/1600955