jsp导出excel
来源:互联网 发布:东莞三星视界待遇知乎 编辑:程序博客网 时间:2024/06/06 01:04
/***
* 导出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;
}
阅读全文
0 0
- jsp导出excel poi
- jsp导出Excel
- jsp导出Excel(续)
- jsp 导出 word excel
- JSP导出Excel文档
- jsp导出Excel
- jsp导出Excel
- jsp导出Excel
- JSP导出EXCEL
- jsp导出Excel
- jsp实现导出(Excel)
- jsp 导出 excel
- jsp页面导出excel
- jsp导出excel
- jsp导出excel
- jsp导出数据(excel)
- jsp数据导出excel
- [JSP] - [导出EXCEL]
- 进程学习8--进程状态和system函数
- WS2008安装IIS7时提示安装失败,错误代码0x80070643解决方案
- linux下的内存检查
- Spark集群环境搭建
- java-网络编程(socket)
- jsp导出excel
- Android几种常见的多渠道(批量)打包方式介绍
- iOS ijkplayer 音视频同步
- angularJs过滤器(货币转换,大小写,字数限制,日期)
- Go语言二维数组的传参
- Kotlin编程之类的介绍和使用
- 面试的角度诠释Java工程师(一)
- RSA 加密-重写base64 适用于反射
- VMware中解决ubuntu不能连接网络问题