标签:orm ++ isp div mat dal 字节 warning work
java代码
@GetMapping("/exportExcel") public void exportExcel(@RequestParam(value = "ztId") int ztId, HttpServletResponse response) throws IOException { XSSFWorkbook xssfWorkbook = new XSSFWorkbook(); XSSFSheet sheet = xssfWorkbook.createSheet("测试"); XSSFRow row0 = sheet.createRow(0); row0.createCell(0).setCellValue("编码"); row0.createCell(1).setCellValue("名称"); List<Ce> ces = ceRepository.findAllByZtId(ztId); int num=0; for(var it : ces){ num++; XSSFRow row = sheet.createRow(num); row.createCell(0).setCellValue(it.getCode()); row.createCell(1).setCellValue(it.getName()); } response.setHeader("Content-Disposition", "attachment; filename=Cs.xlsx"); // 响应类型,编码 response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); // 将指定的字节写入此输出流 xssfWorkbook.write(response.getOutputStream()); response.flushBuffer(); xssfWorkbook.close(); }
前端代码:
<el-button type="warning" size="small" @click="exportExcel">导出</el-button> ......... methods: { exportExcel() { httpDownload(`/exportExcel/?ztId=${this.ztId}`, "Ajgl.xlsx"); } } .....
标签:orm ++ isp div mat dal 字节 warning work
原文地址:https://www.cnblogs.com/pzw23/p/12786744.html