我是angular的新手,目前我正在一个需要csv导出的项目中工作。在这里,我使用Angular 6作为前端,使用laravel作为后端这就是我使用mattwebsite / excel编写laravel函数的方式// Lead export to csvpublic function downloadExcel(Request $request){ $credentials = $request->only('token'); $token = $credentials['token']; $userid = $this->getUseridFromToken($token); $type = "xls"; $data = DB::table('user_mailbox AS A') ->select('A.id', 'A.name', 'A.email', 'A.phone', DB::raw('DATE_FORMAT(A.send_on, "%d / %b / %Y") as send_on'), 'B.listing_heading','B.listing_id','B.listing_heading', 'C.name') ->leftjoin('broker_listing AS B', 'B.listing_id', '=', 'A.listing_id') ->leftjoin('users AS C', 'C.id', '=', 'A.sent_by') ->where('A.sent_to', $userid) ->where('A.user_type', '1') ->orderBy('A.id', 'desc')->get()->toArray(); Excel::create('Lead_Export', function($excel) use ($data) { $excel->sheet('Lead_Export', function($sheet) use ($data) { $sheet->fromArray($data); }); })->download($type);}这就是我在角度组件中编写函数的方式 // Download leads as exceldownload_excel(){ const fd = new FormData(); fd.append('token',this.token); this.brokerleads.downloadLeads(fd).subscribe( data => this.handleResponsedwnload(data), error => this.handleErrordwnload(error) );}handleResponsedwnload(data){ console.log('test'); const blob = new Blob([data], { type: 'text/xls' }); const url= window.URL.createObjectURL(blob); window.open(url);}handleErrordwnload(data){}服务就是这样 // Download as excel downloadLeads(data):Observable<any>{ return this.http.post(`${this.baseUrl}downloadExcel`, data); }看法 <a class="export-leads" href="javascript:void(0);" (click)="download_excel()" >EXPORT LEADS</a>在执行此操作时,我收到这样的响应,但文件未下载
3 回答
- 3 回答
- 0 关注
- 171 浏览
添加回答
举报
0/150
提交
取消