欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java 导出excel,,

来源: javaer 分享于  点击 27179 次 点评:49

java 导出excel,,


	public String excel() {
try {
String filename = "RKA_"
+ DateFormatUtil.getFormatDate("yyyyMMddHHmmss");
HttpServletResponse response = getResponse();
OutputStream os = response.getOutputStream();// 取得输出流
response.reset();
response.setContentType("APPLICATION/X-MSDOWNLOAD;charset=utf-8");
response.setCharacterEncoding("utf-8");
response.setHeader(
"Content-Disposition",
new String(("attachment;filename=\"" + filename + ".xls\"")
.getBytes("utf-8"), "utf-8"));
response.setContentType("text/html");
WritableWorkbook book = null;
book = Workbook.createWorkbook(os); // 建立excel文件
WritableSheet sheet = book.createSheet("销售信息", 10); // 创建一个工作表
// -----------2--end
// 生成表格题头
Label labe0 = new Label(0, 0, "创建日期");
Label labe1 = new Label(1, 0, "微信号");
Label labe2 = new Label(2, 0, "姓名");
Label labe3 = new Label(3, 0, "电话");
Label labe4 = new Label(4, 0, "门店名称");
Label labe5 = new Label(5, 0, "数量");
Label labe6 = new Label(6, 0, "销售额");
Label labe7 = new Label(7, 0, "大区");
Label labe8 = new Label(8, 0, "标准分部");
Label labe9 = new Label(9, 0, "渠道");
Label labe10 = new Label(10, 0, "电脑型号");
// 将生成的单元格添加到工作表中
sheet.addCell(labe0);
sheet.addCell(labe1);
sheet.addCell(labe2);
sheet.addCell(labe3);
sheet.addCell(labe4);
sheet.addCell(labe5);
sheet.addCell(labe6);
sheet.addCell(labe7);
sheet.addCell(labe8);
sheet.addCell(labe9);
sheet.addCell(labe10);
//---
ISaleInfoService iSaleInfoService = (ISaleInfoService) AppContextUtil
.getBean(RKACommon.saleInfo_Servcie);
List<Saleinfo> saleinfoList =iSaleInfoService.getSaleInfo(RKACommon.sale_sqlQryByDate, getParams());
if (saleinfoList != null || saleinfoList.size() > 0) {
getAllInfoList(saleinfoList);
}
for (int i = 0; i < saleInfoAndUserList.size(); i++) {
Label label0 = new Label(0, i + 1, saleInfoAndUserList.get(i)
.getSaleDate().toString());
Label label1 = new Label(1, i + 1, saleInfoAndUserList.get(i)
.getImNumber());
Label label2 = new Label(2, i + 1, saleInfoAndUserList.get(i)
.getUserName());

Label label3 = new Label(3, i + 1, saleInfoAndUserList.get(i)
.getTelephone());
Label label4 = new Label(4, i + 1, saleInfoAndUserList.get(i)
.getStoreName());

Label label5 = new Label(5, i + 1, saleInfoAndUserList.get(i)
.getSaleCount().toString());
Label label6 = new Label(6, i + 1, saleInfoAndUserList.get(i)
.getSalePrice().toString());
Label label7 = new Label(7, i + 1, saleInfoAndUserList.get(i)
.getAreaName());
Label label8 = new Label(8, i + 1, saleInfoAndUserList.get(i)
.getStandardSegment());
Label label9 = new Label(9, i + 1, saleInfoAndUserList.get(i)
.getChannelName());
Label label10 = new Label(10, i + 1, saleInfoAndUserList.get(i)
.getProductName());
// 将生成的单元格添加到工作表中
sheet.addCell(label0);
sheet.addCell(label1);
sheet.addCell(label2);
sheet.addCell(label3);
sheet.addCell(label4);
sheet.addCell(label5);
sheet.addCell(label6);
sheet.addCell(label7);
sheet.addCell(label8);
sheet.addCell(label9);
sheet.addCell(label10);
}
book.write();
book.close();
} catch (RowsExceededException e) {
e.printStackTrace();
} catch (WriteException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

相关文章

    暂无相关文章
相关栏目:

用户点评