导出excel

https://blog.csdn.net/weixin_43527496/article/details/95479513

springboot+vue实现导出excel表

 

前端vue代码:

const excApiBase = ‘/api/excel’
import {exportCompanyExcel} from ‘@/api/axios’

// 导出Excel文件
export const exportClientInfoExcel = (params) => {
return exportCompanyExcel(${excApiBase}/companyExcel,params)
}

import axios from ‘axios’;

/**

导出产品信息表

@param url

@param params

@returns {AxiosPromise}
*/
export const exportCompanyExcel = ( id,contacts,contactsPhone ) => {
return axios({
method: ‘post’,
url: /api/excel/companyExcel,
params: {id,contacts,contactsPhone},
responseType: ‘blob’,
headers: {
}
});
};

   <el-form-item>
       <el-button type="primary" icon="el-icon-download" @click="exportClientInfoExcel">导出</el-button>
     </el-form-item>

 

 

//js代码

import {exportCompanyExcel} from ‘@/api/axios’

exportClientInfoExcel() {
  const that = this
  //that.filters.id,that.filters.contacts,that.filters.contactsPhone  通过id 联系人  联系电话 导出excel
  exportCompanyExcel(that.filters.id,that.filters.contacts,that.filters.contactsPhone).then(response => {
    that.downloadFile(response.data);
  })
},
downloadFile(data) {
  // 文件导出
  if (!data) {
    return
  }
  let url = window.URL.createObjectURL(new Blob([data]));
  let link = document.createElement('a');
  link.style.display = 'none';
  link.href = url;
  link.setAttribute('download', '委托方信息表.xls');
  document.body.appendChild(link);
  link.click()
}  }}

 

posted @ 2020-09-12 17:25  怪糟糟的人  阅读(155)  评论(0)    收藏  举报