public static void exportExcel(HttpServletResponse response, String headName, List<数据对象> list) throws IOException {
Resource resource=new ClassPathResource("file/模板.xlsx");
Workbook workbook=new XSSFWorkbook(resource.getInputStream());
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setAlignment(HorizontalAlignment.CENTER);
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
Sheet sheet= workbook.getSheetAt(0);
Row headRow = sheet.getRow(0);
Cell headRowCell = headRow.getCell(0);
headRowCell.setCellValue(headName);
//从第表格第三行开始写入数据,根据模板设置index开始的值
Row rowData = sheet.createRow(index++);
cell=rowData.createCell(0);
cell.setCellStyle(cellStyle);
cell.setCellValue(xxx.getXXX());
cell=rowData.createCell(1);
cell.setCellStyle(cellStyle);
cell.setCellValue(xxx.getXXX());
Sheet sheet2= workbook.getSheetAt(1);
String fileName = URLEncoder.encode("表格名称", "utf-8");
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
fileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
workbook.write(response.getOutputStream());
//String fileName = URLEncoder.encode("表格名称.xlsx", "utf-8");
//response.setHeader("content-type", "application/octet-stream;charset=utf-8");
//response.setHeader("content-disposition", "attachment; ");
//response.setHeader("filename",fileName);
//workbook.write(response.getOutputStream());
