如下代码主要是为了记录怎么 将数据库表的数据存入workbook后 导出到excel
@RequestMapping("download.do") public ResponseEntity<byte[]> download(String fileName) throws Exception { FileInputStream fips = new FileInputStream("D:\\test\\t_car.xls"); Workbook workbook = WorkbookFactory.create(fips); HttpHeaders headers = new HttpHeaders(); headers.add("Content-Type", "application/vnd.ms-excel"); headers.add("Connection", "close"); headers.add("Accept-Ranges", "bytes"); headers.add("Content-Disposition", "attachment;filename=t_car.xls"); ByteArrayOutputStream baops = new ByteArrayOutputStream(); workbook.write(baops); //直接将文件转换成 byte[] 的方法 // byte[] b = FileUtils.readFileToByteArray(file); return new ResponseEntity<byte[]>(baops.toByteArray(),headers,HttpStatus.CREATED);
}