我使用角4作为前端,而内腔5.4作为后端.
我的要求是将一些数据导出为excel和zip文件.
使用{ saveAs }从'file-saver/FileSaver';包导入文件下载.
Angular 4代码:
downloadExcel() {
const type = 'application/vnd.ms-excel';
const headers = { headers: new Headers({ 'Accept': type }) };
const filename = 'file.xls';
this.http.get('http://10.2.2.109/Download/exportExcel', headers)
.toPromise()
.then(response => this.saveToFileSystem(response, type, filename));
return false;
}
private saveToFileSystem(response, __type, filename) {
const contentDispositionHeader: string = response.headers.get('Content-Disposition');
if (contentDispositionHeader !== null) {
const parts: string[] = contentDispositionHeader.split(';');
//const filename = parts[1].split('=')[1];
const blob = new Blob([response._body], { type: __type });
saveAs(blob, filename);
} else …Run Code Online (Sandbox Code Playgroud) 我正在使用Typescript在Angular2 v4应用程序中工作,我需要一种将许多图像(base64格式)下载到Zip文件中的方法。
例如:我有一个像这样的数组(例如,伪造的base64图像)
data = [
'data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA ...',
'data:image/png;base64, iVBTYu0KGgoBBBBNSUhYUgJJJJUA ...',
'data:image/png;base64, CGBHHFGY0goAAAANSUhEUgAAAAUA ...',
...
]
Run Code Online (Sandbox Code Playgroud)
我需要一种下载它的方法,该方法首先将每个图像转换为.jpg或.png图像,然后编译所有图像并将其下载为zip文件。这样的东西(我不知道代码,我只需要这样的东西)
downloadZip() {
const arrayAsJPG = [];
this.data.forEach(i => {
const imageInJpg = i.convertToJPGfile(); // this is not code, this is a function that converts the base64 to a jpg file
arrayAsJPG.push(imageInJpg);
});
ZipFileSaver.save(arrayAsJPG, 'myImageReport.zip'); // this isn't code neither, just and interpretation of what I need
}
Run Code Online (Sandbox Code Playgroud)
有什么办法做到这一点?