java Excel导出
来源:互联网 发布:临沂嘎嘎网络 编辑:程序博客网 时间:2024/05/21 22:45
package com.duia.web.controller.learn;
import com.duia.model.learn.PrizeBankAccount;
import com.duia.service.learn.spi.IPrizeBankAccountService;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
* Created by xiaochao on 2016/11/2.
*/
@Controller
@RequestMapping("/prizeBankAccount")
public class PrizeBankAccountController {
@RequestMapping(value = "/d", method = RequestMethod.GET)
public void d (HttpServletResponse response,MyPageModel page, Long skuId, Long classType, Long clazz, Long userId){
Map<String,Object> params = new HashMap<String,Object>();
params.put("firstIndex",(page.getPageIndex() - 1) * page.getPageSize());
params.put("pageSize",page.getPageSize());
params.put("skuId",skuId);
params.put("classType",classType);
params.put("clazz",clazz);
params.put("userId",userId);
page.setParams(params);
page = this.msbUserScoresService.pageModel(page);
XSSFWorkbook xb = new XSSFWorkbook();
XSSFSheet sheet = xb.createSheet();
//样式修改
// XSSFCellStyle cellStyle = xb.createCellStyle();
// cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中
StringBuffer fileName = new StringBuffer();
fileName.append(new SimpleDateFormat("yyyyMMdd_hhmmss").format(new Date())).append(".xlsx");
List<MsbUserScores> list = page.getData();
if (!CollectionUtils.isEmpty(list)) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd:HH:mm:ss");
//第一行
XSSFRow row0 = sheet.createRow(0);
XSSFCell cell0 = row0.createCell(0);
cell0.setCellValue("面试宝评分表");
//合并单元格CellRangeAddress构造参数依次表示起始行,截至行,起始列, 截至列
sheet.addMergedRegion(new CellRangeAddress(0,0,0,3));
//第二行
XSSFRow row = sheet.createRow(1);
XSSFCell cell = row.createCell(1);
cell.setCellValue("老师");
cell = row.createCell(1);
cell.setCellValue("评价时间");
cell = row.createCell(2);
cell.setCellValue("大标题");
cell = row.createCell(3);
cell.setCellValue("评价全面");
cell = row.createCell(4);
cell.setCellValue("评价精准");
cell = row.createCell(5);
cell.setCellValue("批改及时");
cell = row.createCell(6);
cell.setCellValue("建议中肯");
//数据填充
for (int i = 0; i < list.size(); i++) {
row = sheet.createRow(i + 1);
row.createCell(0).setCellValue(list.get(i).getMsbTeacherName());
row.createCell(1).setCellValue(dateFormat.format(list.get(i).getReplyTime()));
row.createCell(2).setCellValue(list.get(i).getBigTitle());
row.createCell(3).setCellValue(list.get(i).getScore1());
row.createCell(4).setCellValue(list.get(i).getScore2());
row.createCell(5).setCellValue(list.get(i).getScore3());
row.createCell(6).setCellValue(list.get(i).getScore4());
}
}else {
sheet.setColumnWidth(0, 1500 * 5);
XSSFRow row2 = sheet.createRow(0);
row2.createCell(0).setCellValue("记录为空");
}
try {
response.setContentType("application/x-excel");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName.toString());
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
xb.write(out);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
import com.duia.model.learn.PrizeBankAccount;
import com.duia.service.learn.spi.IPrizeBankAccountService;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
* Created by xiaochao on 2016/11/2.
*/
@Controller
@RequestMapping("/prizeBankAccount")
public class PrizeBankAccountController {
@RequestMapping(value = "/d", method = RequestMethod.GET)
public void d (HttpServletResponse response,MyPageModel page, Long skuId, Long classType, Long clazz, Long userId){
Map<String,Object> params = new HashMap<String,Object>();
params.put("firstIndex",(page.getPageIndex() - 1) * page.getPageSize());
params.put("pageSize",page.getPageSize());
params.put("skuId",skuId);
params.put("classType",classType);
params.put("clazz",clazz);
params.put("userId",userId);
page.setParams(params);
page = this.msbUserScoresService.pageModel(page);
XSSFWorkbook xb = new XSSFWorkbook();
XSSFSheet sheet = xb.createSheet();
//样式修改
// XSSFCellStyle cellStyle = xb.createCellStyle();
// cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中
StringBuffer fileName = new StringBuffer();
fileName.append(new SimpleDateFormat("yyyyMMdd_hhmmss").format(new Date())).append(".xlsx");
List<MsbUserScores> list = page.getData();
if (!CollectionUtils.isEmpty(list)) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd:HH:mm:ss");
//第一行
XSSFRow row0 = sheet.createRow(0);
XSSFCell cell0 = row0.createCell(0);
cell0.setCellValue("面试宝评分表");
//合并单元格CellRangeAddress构造参数依次表示起始行,截至行,起始列, 截至列
sheet.addMergedRegion(new CellRangeAddress(0,0,0,3));
//第二行
XSSFRow row = sheet.createRow(1);
XSSFCell cell = row.createCell(1);
cell.setCellValue("老师");
cell = row.createCell(1);
cell.setCellValue("评价时间");
cell = row.createCell(2);
cell.setCellValue("大标题");
cell = row.createCell(3);
cell.setCellValue("评价全面");
cell = row.createCell(4);
cell.setCellValue("评价精准");
cell = row.createCell(5);
cell.setCellValue("批改及时");
cell = row.createCell(6);
cell.setCellValue("建议中肯");
//数据填充
for (int i = 0; i < list.size(); i++) {
row = sheet.createRow(i + 1);
row.createCell(0).setCellValue(list.get(i).getMsbTeacherName());
row.createCell(1).setCellValue(dateFormat.format(list.get(i).getReplyTime()));
row.createCell(2).setCellValue(list.get(i).getBigTitle());
row.createCell(3).setCellValue(list.get(i).getScore1());
row.createCell(4).setCellValue(list.get(i).getScore2());
row.createCell(5).setCellValue(list.get(i).getScore3());
row.createCell(6).setCellValue(list.get(i).getScore4());
}
}else {
sheet.setColumnWidth(0, 1500 * 5);
XSSFRow row2 = sheet.createRow(0);
row2.createCell(0).setCellValue("记录为空");
}
try {
response.setContentType("application/x-excel");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName.toString());
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
xb.write(out);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
阅读全文
0 0
- struts2导出excel java 导出excel
- struts2导出excel java 导出excel
- java导出EXCEL
- JAVA 导入导出Excel
- Java jxl导出excel
- java导出Excel
- java 导出 Excel 报表
- java excel导入导出
- java excel导入导出
- JAVA导出EXCEL心得
- 【Java】导出excel表格
- java poi 导出excel
- java怎么导出excel
- java 导出Excel
- JAVA导出EXCEL
- JAVA导出EXCEL心得 .
- java导出Excel例子
- java 导出 excel
- JavaScript 对象拷贝与Object.assign
- Ubuntu的软件源更新常见问题及解决
- Win7 x64 Eclipse无法识别手机 / adb interface有黄色感叹号,无法识别
- Android,沉浸式模式
- Oracle(二)函数,与各种连接查询
- java Excel导出
- 网站无非复制右键禁止特效药
- The Haskell process `xx’ has died issue
- web项目中使用多线程的一些坑
- 5.Spring Boot部署
- 函数对象与闭包详解,函数式编程
- 专业人士如何做自媒体
- 认识HTML5的WebSocket
- Android开发 ---RecyclerView基本用法