728x90
반응형
@PostMapping("/ModelAndViewTEST")
public ModelAndView TEST(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("excel", 데이터 생성해서 넣어 );
modelAndView.setViewName("soobin.excelTest");
return modelAndView;
}
@Component("soobin.excelTest")
public class excelTest extends AbstractXlsxView {
@Override
protected void buildExcelDocument(Map<String, Object> model, Workbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception {
Sheet sheet = workbook.createSheet("첫번째 시트");
Row row = null;
Cell cell = null;
int rowNum = 0;
row = sheet.createRow(rowNum++);
cell = row.createCell(0);
cell.setCellValue("테스트");
response.setContentType("ms-vnd/excel");
response.setHeader("Content-Disposition", "attachment;filename=example.xlsx");
workbook.write(response.getOutputStream());
workbook.close();
}
}
728x90
반응형
댓글