Spring
发布时间:2019-10-07 发布网站:大佬教程 code.js-code.com
大佬教程收集整理的这篇文章主要介绍了vue+springmvc导出excel数据的实现代码,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
vue端处理
{
console.info(typeof data)
var a = document.createElement('a'
);
var url = window.UR
l.createOb
jectURL(data
);
a.href = url;
a.download = '用户统计信息.xls';
a.click(
);
window.UR
l.revokeOb
jectURL(url
);
})
web端处理
0586@l=userBs
service.getCount(
null);
List
list=userBsservice.getList(null,1,@R_992_10586@l);
String filename = new Date().getTime() + "";
XSSFWorkbook wb=new XSSFWorkbook();
Sheet sheet=wb.createSheet();
Row row0=sheet.createRow(0);
String titlename[] = {"用户账号","充值总金额","邀请总人数","社群组"};//列名
for(int i=0;i<titlename.length;i++){
sheet.setcolumnWidth(i,10 * 512);
row0.createCell(i).setCellValue(titlename[i]);
}
int i=0;
for(UserVo v:list){
Row row=sheet.createRow(i+1);
if(!StringUtils.isEmpty(v.getMobile())){
row.createCell(0).setCellValue(v.getMobile());
}else{
row.createCell(0).setCellValue(v.getEmail());
}
row.createCell(1).setCellValue(BigdecimalUtil.outputConvert(v.getamount()));
row.createCell(2).setCellValue(v.getCounts());
row.createCell(3).setCellValue(v.getGroups());
i++;
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
try{
try {
wb.write(os);
wb.close();
} catch (IOException E) {
e.printStackTrace();
}
byte[] content = os.toByteArray();
InputStream is = new ByteArrayInputStream(content);
response.reset();
response.setContentType("application/vnd.ms-excel;charset=utf-8");
response.setHeader("Content-Disposition","attachment;filename="+ new String((filename + ".xls").getBytes(),"iso-8859-1"));
ServletOutputStream out = response.getOutputStream();
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(is);
bos = new BufferedOutputStream(out);
byte[] buff = new byte[2048];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff,buff.length))) {
bos.write(buff,bytesRead);
}
} catch (final IOException E) {
throw e;
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
}catch (Exception E){
}
return null;
总结
以上所述是小编给大家介绍的vue+springmvc导出excel数据的实现代码。菜鸟教程 jb51.cc 收集整理的教程希望能对你有所帮助,如果觉得菜鸟教程不错,可分享给好友!感谢支持。
大佬总结
以上是大佬教程为你收集整理的vue+springmvc导出excel数据的实现代码全部内容,希望文章能够帮你解决vue+springmvc导出excel数据的实现代码所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。