/***
* 导出excel表格
* 提交方式只能是同步!!
* @param select
* @param model
* @param session
* @return
* @throws IOException
* @throws WriteException
* @throws ParseException
* @throws Exception
*/
@RequestMapping(value = "/insertTable.do")
public String insertTable( Model model,HttpServletResponse response,SelectCondition select) throws IOException, WriteException, ParseException {
//获取文件名字
String excelName = "兑换明细"+System.currentTimeMillis()+".xls";
//定义一个输出liu
OutputStream os = null;
//清除空白行
response.reset();
//设置响应头
response.setHeader("Content-disposition", "attachment; filename="
+ new String((excelName).getBytes("gbk"), "iso8859-1"));// 设置编码
response.setContentType("application/msexcel");// 这是输出为EXCEL格式的
os = response.getOutputStream();
// 设置第一行的字体样式
WritableFont wfh = new WritableFont(WritableFont.ARIAL, 12,
WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,
Colour.BLACK);
WritableCellFormat wcf = new WritableCellFormat(wfh);
wcf.setBackground(Colour.GOLD);
// 2.生成工作簿
WritableWorkbook wb = Workbook.createWorkbook(os);
// 3根据工作薄创建工作表
WritableSheet sheet = wb.createSheet("工作表1", 0);
sheet.setColumnView(0, 10);
sheet.setColumnView(1, 15);
sheet.setColumnView(2, 15);
sheet.setColumnView(3, 15);
sheet.setColumnView(4, 15);
sheet.setColumnView(5, 15);
sheet.setColumnView(6, 15);
sheet.setColumnView(7, 15);
// 4.生成单元格
Label label = new Label(0, 0, "玩家ID", wcf);
// 5.工作表中加入单元格
sheet.addCell(label);
label = new Label(1, 0, "用户昵称", wcf);
sheet.addCell(label);
label = new Label(2, 0, "身份", wcf);
sheet.addCell(label);
label = new Label(3, 0, "时间", wcf);
sheet.addCell(label);
label = new Label(4, 0, "兑换类型", wcf);
sheet.addCell(label);
label = new Label(5, 0, "积分消耗数量", wcf);
sheet.addCell(label);
label = new Label(6, 0, "订单号", wcf);
sheet.addCell(label);
label = new Label(7, 0, "状态", wcf);
sheet.addCell(label);
//进行查询
List list = queryModuleService.selectConvertService(select);
if(list != null && list.size()>0){
for(int i=0;i<list.size();i++){
Map map = (Map) list.get(i);
label = new Label(0, i + 1, map.get("USER_ID") + "");
sheet.addCell(label);
label = new Label(1, i + 1,map.get("NICKNAME") + "");
sheet.addCell(label);
//保存身份
String status = null;
if(Integer.parseInt(map.get("SPREAD_ACTIVE_TIME").toString())>0){
status="推广员";
}else if(map.get("IS_PROXY").toString().equals("1")){
status = "代理";
}else{
status = "会员";
}
label = new Label(2, i + 1, status + "");
sheet.addCell(label);
//时间格式
String a = map.get("CONVERT_TIM").toString();
if(!a.equals("0")){
a = DateFormatUtil.longFormatDateStr((Long.parseLong(a)));
}
label = new Label(3, i + 1,a + "");
sheet.addCell(label);
String convertType = map.get("CONVERT_TYPE").toString();
if(convertType.equals("1")){
status = "房卡";
}else if(convertType.equals("2")){
status="话费";
}else if(convertType.equals("3")){
status="流量";
}else if(convertType.equals("4")){
status="提现";
}
label = new Label(4, i + 1,status + "");
sheet.addCell(label);
//消耗积分
String score = map.get("SCORE_NUM").toString();
label = new Label(5, i + 1,score + " ");
sheet.addCell(label);
//订单号
String order_id = map.get("ORDER_ID").toString();
label = new Label(6, i + 1,order_id + "");
sheet.addCell(label);
//状态
String state = map.get("ORDER_ID").toString();
if(state.equals("1")){
status="已完成";
}else if(state.equals("2")){
status="处理中";
}else if(state.equals("3")){
status="失败";
}
label = new Label(7, i + 1,status + "");
sheet.addCell(label);
}
}
wb.write();
wb.close();
return null;
}
* 导出excel表格
* 提交方式只能是同步!!
* @param select
* @param model
* @param session
* @return
* @throws IOException
* @throws WriteException
* @throws ParseException
* @throws Exception
*/
@RequestMapping(value = "/insertTable.do")
public String insertTable( Model model,HttpServletResponse response,SelectCondition select) throws IOException, WriteException, ParseException {
//获取文件名字
String excelName = "兑换明细"+System.currentTimeMillis()+".xls";
//定义一个输出liu
OutputStream os = null;
//清除空白行
response.reset();
//设置响应头
response.setHeader("Content-disposition", "attachment; filename="
+ new String((excelName).getBytes("gbk"), "iso8859-1"));// 设置编码
response.setContentType("application/msexcel");// 这是输出为EXCEL格式的
os = response.getOutputStream();
// 设置第一行的字体样式
WritableFont wfh = new WritableFont(WritableFont.ARIAL, 12,
WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,
Colour.BLACK);
WritableCellFormat wcf = new WritableCellFormat(wfh);
wcf.setBackground(Colour.GOLD);
// 2.生成工作簿
WritableWorkbook wb = Workbook.createWorkbook(os);
// 3根据工作薄创建工作表
WritableSheet sheet = wb.createSheet("工作表1", 0);
sheet.setColumnView(0, 10);
sheet.setColumnView(1, 15);
sheet.setColumnView(2, 15);
sheet.setColumnView(3, 15);
sheet.setColumnView(4, 15);
sheet.setColumnView(5, 15);
sheet.setColumnView(6, 15);
sheet.setColumnView(7, 15);
// 4.生成单元格
Label label = new Label(0, 0, "玩家ID", wcf);
// 5.工作表中加入单元格
sheet.addCell(label);
label = new Label(1, 0, "用户昵称", wcf);
sheet.addCell(label);
label = new Label(2, 0, "身份", wcf);
sheet.addCell(label);
label = new Label(3, 0, "时间", wcf);
sheet.addCell(label);
label = new Label(4, 0, "兑换类型", wcf);
sheet.addCell(label);
label = new Label(5, 0, "积分消耗数量", wcf);
sheet.addCell(label);
label = new Label(6, 0, "订单号", wcf);
sheet.addCell(label);
label = new Label(7, 0, "状态", wcf);
sheet.addCell(label);
//进行查询
List list = queryModuleService.selectConvertService(select);
if(list != null && list.size()>0){
for(int i=0;i<list.size();i++){
Map map = (Map) list.get(i);
label = new Label(0, i + 1, map.get("USER_ID") + "");
sheet.addCell(label);
label = new Label(1, i + 1,map.get("NICKNAME") + "");
sheet.addCell(label);
//保存身份
String status = null;
if(Integer.parseInt(map.get("SPREAD_ACTIVE_TIME").toString())>0){
status="推广员";
}else if(map.get("IS_PROXY").toString().equals("1")){
status = "代理";
}else{
status = "会员";
}
label = new Label(2, i + 1, status + "");
sheet.addCell(label);
//时间格式
String a = map.get("CONVERT_TIM").toString();
if(!a.equals("0")){
a = DateFormatUtil.longFormatDateStr((Long.parseLong(a)));
}
label = new Label(3, i + 1,a + "");
sheet.addCell(label);
String convertType = map.get("CONVERT_TYPE").toString();
if(convertType.equals("1")){
status = "房卡";
}else if(convertType.equals("2")){
status="话费";
}else if(convertType.equals("3")){
status="流量";
}else if(convertType.equals("4")){
status="提现";
}
label = new Label(4, i + 1,status + "");
sheet.addCell(label);
//消耗积分
String score = map.get("SCORE_NUM").toString();
label = new Label(5, i + 1,score + " ");
sheet.addCell(label);
//订单号
String order_id = map.get("ORDER_ID").toString();
label = new Label(6, i + 1,order_id + "");
sheet.addCell(label);
//状态
String state = map.get("ORDER_ID").toString();
if(state.equals("1")){
status="已完成";
}else if(state.equals("2")){
status="处理中";
}else if(state.equals("3")){
status="失败";
}
label = new Label(7, i + 1,status + "");
sheet.addCell(label);
}
}
wb.write();
wb.close();
return null;
}