6 changed files with 72 additions and 3 deletions
@ -0,0 +1,3 @@
|
||||
<div class="box"> |
||||
<button mat-raised-button color="primary" (click)="export()">导出excel表格</button> |
||||
</div> |
@ -0,0 +1,7 @@
|
||||
.box{ |
||||
width: 100%; |
||||
height: 100%; |
||||
display: flex; |
||||
align-items: center; |
||||
justify-content: center; |
||||
} |
@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; |
||||
|
||||
import { ExportExcelComponent } from './export-excel.component'; |
||||
|
||||
describe('ExportExcelComponent', () => { |
||||
let component: ExportExcelComponent; |
||||
let fixture: ComponentFixture<ExportExcelComponent>; |
||||
|
||||
beforeEach(async(() => { |
||||
TestBed.configureTestingModule({ |
||||
declarations: [ ExportExcelComponent ] |
||||
}) |
||||
.compileComponents(); |
||||
})); |
||||
|
||||
beforeEach(() => { |
||||
fixture = TestBed.createComponent(ExportExcelComponent); |
||||
component = fixture.componentInstance; |
||||
fixture.detectChanges(); |
||||
}); |
||||
|
||||
it('should create', () => { |
||||
expect(component).toBeTruthy(); |
||||
}); |
||||
}); |
@ -0,0 +1,31 @@
|
||||
import { HttpClient } from '@angular/common/http'; |
||||
import { Component, OnInit } from '@angular/core'; |
||||
|
||||
@Component({ |
||||
selector: 'app-export-excel', |
||||
templateUrl: './export-excel.component.html', |
||||
styleUrls: ['./export-excel.component.scss'] |
||||
}) |
||||
export class ExportExcelComponent implements OnInit { |
||||
|
||||
constructor(public http:HttpClient) { } |
||||
|
||||
ngOnInit(): void { |
||||
} |
||||
export(){ |
||||
const httpOptions = { |
||||
responseType: 'blob' as 'json' |
||||
}; |
||||
this.http.get('/api/StatisticsAnalysis/ExportToExcel',httpOptions).subscribe((data:any) => { |
||||
// // 文件名中有中文 则对文件名进行转码
|
||||
const link = document.createElement('a'); |
||||
const blob = new Blob([data], {type: 'application/vnd.ms-excel'}); |
||||
link.setAttribute('href', window.URL.createObjectURL(blob)); |
||||
link.setAttribute('download', '统计信息'+'.xlsx'); |
||||
link.style.visibility = 'hidden'; |
||||
document.body.appendChild(link); |
||||
link.click(); |
||||
document.body.removeChild(link); |
||||
}) |
||||
} |
||||
} |
Loading…
Reference in new issue