导出excel文件
@ApiOperation(value = "学籍导入Excel模板下载")
@GetMapping(value = "/exportExcel")
public void exportExcel(HttpServletResponse response) {
OutputStream ouputStream = null;
try {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("sheet1");
sheet.setColumnWidth(0, 5000);
sheet.setColumnWidth(1, 5000);
sheet.setColumnWidth(2, 5000);
sheet.setColumnWidth(3, 5000);
sheet.setColumnWidth(4, 5000);
sheet.setColumnWidth(5, 5000);
sheet.setColumnWidth(6, 5000);
sheet.setColumnWidth(7, 5000);
sheet.setColumnWidth(8, 5000);
sheet.setColumnWidth(9, 5000);
sheet.setColumnWidth(10, 5000);
sheet.setColumnWidth(11, 5000);
String[] tableHeader = new String[]{
"学号", "姓名", "家长姓名", "家长年龄", "身份证号","与学生关系",
"职位", "工作单位", "职务", "联系电话", "年收入(元)",
"健康状况"
};
HSSFRow firstRow = sheet.createRow((short) 0);
HSSFCellStyle cellStyle = workbook.createCellStyle();
HSSFDataFormat format = workbook.createDataFormat();
cellStyle.setDataFormat(format.getFormat("@"));
for (int i = 1; i <= tableHeader.length; i++) {
HSSFCell cell = firstRow.createCell((short) (i - 1));
if (cell.getCellType() != 1) {
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
}
cell.setCellStyle(cellStyle);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(tableHeader[i - 1]);
}
String[] example = new String[]{
"1111", "小明", "小龙", "41","111111111111111111",
"父子", "教师", "保定中学", "Java老师", "15811111111", "60000","良好"};
HSSFRow secondRow = sheet.createRow((short) 1);
for (int i = 1; i <= examp