@RequestMapping(value="excel.do",
produces="application/vnd.ms-excel")
@ResponseBody
public byte[] excel(
HttpServletResponse response)
throws IOException{
response.setHeader(
"Content-Disposition",
"attachment;filename=\"demo.xls\"");
HSSFWorkbook book=new HSSFWorkbook();//创建工作簿
HSSFSheet sheet = book.createSheet(
"出勤");//创建工作表
HSSFRow row = sheet.createRow(0)//创建行;
HSSFCell cell = row.createCell(0);//创建单元格
cell.setCellType(HSSFCell.CELL_TYPE_STRING);//设置单元格的类型
cell.setCellValue("Hello World!");//设置单元格的值
ByteArrayOutputStream out =
new ByteArrayOutputStream();//创建输出流
book.write(out);//写入输出流
out.close();//关闭输出流
byte[] data = out.toByteArray();将输出流转成字节数组
return data;
}
produces="application/vnd.ms-excel")
@ResponseBody
public byte[] excel(
HttpServletResponse response)
throws IOException{
response.setHeader(
"Content-Disposition",
"attachment;filename=\"demo.xls\"");
HSSFWorkbook book=new HSSFWorkbook();//创建工作簿
HSSFSheet sheet = book.createSheet(
"出勤");//创建工作表
HSSFRow row = sheet.createRow(0)//创建行;
HSSFCell cell = row.createCell(0);//创建单元格
cell.setCellType(HSSFCell.CELL_TYPE_STRING);//设置单元格的类型
cell.setCellValue("Hello World!");//设置单元格的值
ByteArrayOutputStream out =
new ByteArrayOutputStream();//创建输出流
book.write(out);//写入输出流
out.close();//关闭输出流
byte[] data = out.toByteArray();将输出流转成字节数组
return data;
}