springboot +vue excel导出

592 阅读1分钟

摘要

springboot +vue如何导出excel,这里我给大家说一下传统的一些导出excel的方式

效果图

image.png

image.png

EXCEL导出结果

image.png

代码实现

后台

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("学生数据");
HSSFRow row = null;
row = sheet.createRow(0);
row.setHeight((short) (22.50 * 20));//设置行高
row.createCell(0).setCellValue("公司");//为第一个单元格设值
row.createCell(1).setCellValue("罐");//为第一个单元格设值
row.createCell(2).setCellValue("液位");
row.createCell(3).setCellValue("日使用量");
row.createCell(4).setCellValue("时间");
List<Potdetail> list=potdetailService.exportList(potdetail);
int index=0;
for(int i=0;i<list.size();i++)
{

Potdetail u=list.get(i);
row = sheet.createRow((i + 1) - (index * 65535));
row.createCell(0).setCellValue(u.getCompanyName());
row.createCell(1).setCellValue(u.getName());//为第一个单元格设值
row.createCell(2).setCellValue(u.getLevelData());
row.createCell(3).setCellValue(u.getDayQua());
row.createCell(4).setCellValue(u.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));

}


response.setContentType("application/vnd.ms-excel;charset=utf-8");
OutputStream os = response.getOutputStream();
response.setHeader("Content-disposition", "data.xls");//默认Excel名称
wb.write(os);
os.flush();
os.close();

前台代码

  <el-button type="info" size="mini" icon="el-icon-download" @click="exportExcel">导出
  </el-button>
 </el-form-item>
   exportExcel() {
       this.param.companyName=this.value
        this.param.start = this.workDateArr[0];
        this.param.end = this.workDateArr[1];
        download('/app/potdetail/pageListExport',this.param);
      },

总结

以上就是springboot +vue实现excel导出的功能,其实没有想象中的复杂,希望可以帮到需要的人