vue+springmvc導出excel數(shù)據(jù)的實現(xiàn)代碼
更新時間:2018年06月27日 10:39:01 作者:風雨云
這篇文章主要介紹了vue+springmvc導出excel數(shù)據(jù)的實現(xiàn)代碼,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
vue端處理
this.$http.get(this.service + '/user/excel',{responseType: 'blob'}).then(({data})=> {
console.info(typeof data)
var a = document.createElement('a');
var url = window.URL.createObjectURL(data);
a.href = url;
a.download = '用戶統(tǒng)計信息.xls';
a.click();
window.URL.revokeObjectURL(url);
})
web端處理
int total=userBsService.getCount(null);
List<UserVo> list=userBsService.getList(null, 1, total);
String fileName = new Date().getTime() + "";
XSSFWorkbook wb=new XSSFWorkbook();
Sheet sheet=wb.createSheet();
Row row0=sheet.createRow(0);
String titleName[] = {"用戶賬號", "充值總金額", "邀請總?cè)藬?shù)", "社群組"};//列名
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, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
} catch (final IOException e) {
throw e;
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
}catch (Exception e){
}
return null;
總結(jié)
以上所述是小編給大家介紹的vue+springmvc導出excel數(shù)據(jù)的實現(xiàn)代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
您可能感興趣的文章:
相關(guān)文章
vue-cli3 項目從搭建優(yōu)化到docker部署的方法
這篇文章主要介紹了vue-cli3 項目從搭建優(yōu)化到docker部署的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-01-01
element-plus dialog v-loading不生效問題及解決
這篇文章主要介紹了element-plus dialog v-loading不生效問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-03-03
ElementUI級聯(lián)選擇器實現(xiàn)同一父級下最多只能選中一個子級
本文主要介紹了ElementUI級聯(lián)選擇器實現(xiàn)同一父級下最多只能選中一個子級,同一父級下的子節(jié)點單選,又可以選擇多個不同父級下的節(jié)點,具有一定參考價值,感興趣的可以了解一下2023-10-10
element根據(jù)輸入動態(tài)生成表格的示例代碼
在現(xiàn)代電商系統(tǒng)開發(fā)中,后臺管理界面經(jīng)常需要根據(jù)商品規(guī)格和規(guī)格值動態(tài)生成SKU表格,本文通過element-ui框架,展示了如何在Vue.js的環(huán)境下,利用子組件和動態(tài)綁定的方式,實現(xiàn)SKU表格的增刪改查功能2024-11-11

