一.后端代码
记得引入POI依赖
后端将要下载的数据转成输出流
public void Export(HttpServletResponse response,List<ExamGrade> Listexamgrade)throws IOException {
// 创建工作空间
Workbook wb = new XSSFWorkbook();
// 创建工作表
Sheet sheet = wb.createSheet("员工成绩");
// 创建标题行(第一行)
Row row0 = sheet.createRow(0);
CellStyle style = wb.createCellStyle();
Font headerFont = wb.createFont(); // 字体
headerFont.setFontHeightInPoints((short) 14);
headerFont.setColor(HSSFColor.BLACK.index);
headerFont.setFontName("宋体");
sheet.setColumnWidth(3, 252*30);
sheet.setColumnWidth(5, 252*30);
sheet.setColumnWidth(6, 252*30);
sheet.setColumnWidth(7, 252*30);
style.setFont(headerFont);
Cell cell1 = row0.createCell(0);// 第一个参数:列数(从0开始),第二个参数:列类型
Cell cell2 = row0.createC