package com.envision.hr.portal.center.mvc;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
public static void main(String[]args){
//=============================================================Controller=============================================================================>>>
public class DownloadExcelController {
@Autowired
DownloadExcelService downloadExcelService;
@PostMapping(value = "downloadExcel")
public void downloadExcel(HttpServletResponse response, @RequestBody String a) throws IOException {
downloadExcelService.downloadExcel(response, "a");
}
}
//=============================================================service=============================================================================>>>
public class DownloadExcelService {
public void downloadExcel(HttpServletResponse response, String a) throws IOException {
ArrayList header_list = new ArrayList();
header_list.add(0, "工号");
header_list.add(1, "姓名");
header_list.add(2, "级别");
header_list.add(3, "总分");
header_list.add(4, "满意度");
header_list.add(5, "优化人才");
header_list.add(6, "人才发展体系");
header_list.add(7, "得分");
header_list.add(8, "价值传承");
header_list.add(9, "规则");
header_list.add(10, "能力");
header_list.add(11, "氛围");
header_list.add(12, "梯队");
header_list.add(13, "组织");
ArrayList header_code_list = new ArrayList();
header_code_list.add(0, "a");
header_code_list.add(1, "b");
header_code_list.add(2, "c");
header_code_list.add(3, "d");
header_code_list.add(4, "e");
header_code_list.add(5, "dd");
header_code_list.add(6, "ee");
header_code_list.add(7, "ww");
header_code_list.add(8, "ss");
header_code_list.add(9, "cc");
header_code_list.add(10, "gg");
header_code_list.add(11, "aa");
header_code_list.add(12, "zz");
header_code_list.add(13, "bb");
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("report");
String fileName = "人才" + ".xls";
int rowNum = 1;
String[] headers = (String[]) header_list.toArray(new String[0]);
HSSFRow row = sheet.createRow(0);
//在excel表中添加表头
for (int i = 0; i < headers.length; i++) {
HSSFCell cell = row.createCell(i);
HSSFRichTextString text = new HSSFRichTextString(headers[i]);
cell.setCellValue(text);
}
JdbcTemplate jdbcTemplate = DataSourcePageConfig.obtainJdbcConnect();
StringBuffer nativeSql = new StringBuffer();
nativeSql.append("select * from t ");
List