export default { name: 'testModal', // mixins: [testService], data() { return { title: '操作', visible: false, testParam :{}, model: {}, labelCol: { xs: { span: 24 }, sm: { span: 5 } }, wrapperCol: { xs: { span: 24 }, sm: { span: 16 } }, confirmLoading: false, form: this.$form.createForm(this), validatorRules: {} } }, methods: { downFile('insert/insertTest',this.testParam).then((data) => { //弹出框隐藏 this.visible = false const fileName = '测试导出生成表格'; if (!data) { this.$notification.error({ message: '提示', description: '导出表格失败.' }) return; } if (typeof window.navigator.msSaveBlob !== 'undefined') { window.navigator.msSaveBlob(new Blob([data]), fileName + '.xls'); } else { let url = window.URL.createObjectURL(new Blob([data])); let link = document.createElement('a'); link.style.display = 'none'; link.href = url; link.setAttribute('download', fileName + '.xls'); document.body.appendChild(link); link.click(); document.body.removeChild(link); // 下载完成移除元素 window.URL.revokeObjectURL(url); // 释放掉blob对象 this.$notification.info({ message: '提示', description: '导出表格成功.' }) } that.$emit('ok') }); } }
@RequestMapping(value = "/insertTest") public void insertTest(String xxx,String fileName, HttpServletResponse response) { try { ................................ JSONArray testList = (JSONArray) jsonObject.get("data"); List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>(); List<Map<String, Object>> list = new ArrayList<>(); for (int i = 0; i <testList .size() ; i++) { Map map = new HashMap(); String testa = (String) tsList.getJSONObject(i).get("testa"); map.put("testa",testa); list.add(map); } entity.add(new ExcelExportEntity("测试导出", "testa", 200)); Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams( fileName, fileName), entity, list); ServletOutputStream out = response.getOutputStream(); workbook.write(out); out.flush(); out.close(); } catch (Exception e) { log.error("测试导出异常"+e.getMessage()); } }