|
@@ -9,21 +9,18 @@ import cn.rankin.common.utils.util.BeanUtil;
|
|
|
import cn.rankin.common.utils.util.ProvinceUtil;
|
|
|
import cn.rankin.data.api.user.dto.CampusSearchDTO;
|
|
|
import cn.rankin.data.api.user.vo.CampusVo;
|
|
|
-import org.apache.poi.hssf.usermodel.HSSFCell;
|
|
|
-import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
-import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
-import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
+import org.apache.poi.hssf.usermodel.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.OutputStream;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping(value = "/stmt")
|
|
|
-public class StmtController
|
|
|
+public class StmtCampusController
|
|
|
{
|
|
|
@Autowired
|
|
|
private StmtService StmtService;
|
|
@@ -85,48 +82,64 @@ public class StmtController
|
|
|
//创建HSSFWorkbook对象(excel的文档对象)
|
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
//建立新的sheet对象(excel的表单)
|
|
|
- HSSFSheet sheet = wb.createSheet("成绩表");
|
|
|
+ HSSFSheet sheet = wb.createSheet("已开通校区报表");
|
|
|
+ //设置单元格宽度
|
|
|
+ sheet.setColumnWidth(0,50*256);
|
|
|
+ sheet.setColumnWidth(1,10*256);
|
|
|
+ sheet.setColumnWidth(2,10*256);
|
|
|
+ sheet.setColumnWidth(3,30*256);
|
|
|
+ sheet.setColumnWidth(4,10*256);
|
|
|
+ sheet.setColumnWidth(5,15*256);
|
|
|
+ sheet.setColumnWidth(6,15*256);
|
|
|
//在sheet里创建第一行,参数为行索引(excel的行),可以是0~65535之间的任何一个
|
|
|
HSSFRow row1 = sheet.createRow(0);
|
|
|
- //创建单元格(excel的单元格,参数为列索引,可以是0~255之间的任何一个
|
|
|
- HSSFCell cell = row1.createCell(0);
|
|
|
- //设置单元格内容
|
|
|
- cell.setCellValue("学员考试成绩一览表");
|
|
|
- //合并单元格CellRangeAddress构造参数依次表示起始行,截至行,起始列, 截至列
|
|
|
- sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
|
|
|
- //在sheet里创建第二行
|
|
|
- HSSFRow row2 = sheet.createRow(1);
|
|
|
//创建单元格并设置单元格内容
|
|
|
- row2.createCell(0).setCellValue("校区名");
|
|
|
- row2.createCell(1).setCellValue("客户类型");
|
|
|
- row2.createCell(2).setCellValue("创建日期");
|
|
|
- row2.createCell(3).setCellValue("省");
|
|
|
- row2.createCell(4).setCellValue("市");
|
|
|
- row2.createCell(5).setCellValue("联系人");
|
|
|
- row2.createCell(6).setCellValue("联系方式");
|
|
|
+ row1.createCell(0).setCellValue("校区名");
|
|
|
+ row1.createCell(1).setCellValue("客户类型");
|
|
|
+ row1.createCell(2).setCellValue("省");
|
|
|
+ row1.createCell(3).setCellValue("市");
|
|
|
+ row1.createCell(4).setCellValue("联系人");
|
|
|
+ row1.createCell(5).setCellValue("联系方式");
|
|
|
+ row1.createCell(6).setCellValue("创建日期");
|
|
|
+
|
|
|
+ //单元格日期格式
|
|
|
+ HSSFCellStyle cellStyle = wb.createCellStyle();
|
|
|
+ HSSFDataFormat format = wb.createDataFormat();
|
|
|
+ cellStyle.setDataFormat(format.getFormat("yyyy/mm/dd"));
|
|
|
|
|
|
//插入数据
|
|
|
if (list != null && list.size() > 0)
|
|
|
{
|
|
|
- for (CampusVo vo : list)
|
|
|
+ for (int i = 0; i < list.size(); i++)
|
|
|
{
|
|
|
- HSSFRow row = sheet.createRow(2);
|
|
|
+
|
|
|
+ CampusVo vo = list.get(i);
|
|
|
+ String provinceCode = vo.getProvinceCode();
|
|
|
+ String provinceName = ProvinceUtil.get(provinceCode);
|
|
|
+ vo.setProvinceName(provinceName);
|
|
|
+
|
|
|
+ HSSFRow row = sheet.createRow(i + 1);
|
|
|
row.createCell(0).setCellValue(vo.getName());
|
|
|
row.createCell(1).setCellValue(vo.getMerchantName());
|
|
|
- row.createCell(2).setCellValue(vo.getGmtCreated());
|
|
|
- row.createCell(3).setCellValue(vo.getProvinceName());
|
|
|
- row.createCell(4).setCellValue(vo.getCityName());
|
|
|
- row.createCell(5).setCellValue(vo.getContactName());
|
|
|
- row.createCell(6).setCellValue(vo.getMobile());
|
|
|
+ row.createCell(2).setCellValue(vo.getProvinceName());
|
|
|
+ row.createCell(3).setCellValue(vo.getCityName());
|
|
|
+ row.createCell(4).setCellValue(vo.getContactName());
|
|
|
+ row.createCell(5).setCellValue(vo.getMobile());
|
|
|
+
|
|
|
+
|
|
|
+ HSSFCell cell = row.createCell(6);
|
|
|
+ cell.setCellValue(vo.getGmtCreated());
|
|
|
+ cell.setCellStyle(cellStyle);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
try
|
|
|
{
|
|
|
+ long currentTime = new Date().getTime();
|
|
|
//输出Excel文件
|
|
|
OutputStream output = res.getOutputStream();
|
|
|
res.reset();
|
|
|
- res.setHeader("Content-disposition", "attachment; filename=details.xls");
|
|
|
+ res.setHeader("Content-disposition", "attachment; filename=lingjiao_campus_" + currentTime + ".xls");
|
|
|
res.setContentType("application/msexcel");
|
|
|
wb.write(output);
|
|
|
output.close();
|