我正在构建一个Angular应用程序,需要将表格数据导出为Excel文件。在ride success组件中,我有一个表格,该表格显示通过Angular服务获取的数据。现在我需要从我的浏览器下载这个表格数据到Excel文件。
ridesuccess组件:
export class RideSuccessComponent implements OnInit {
p = 1;
myForm: FormGroup;
rideSuccess: RideSuccess[];
rsuccess: RideSuccess = '';
constructor(private adminService: AdminService) {}
ngOnInit() {
this.rsuccess = '';
this.adminService.getRideSuccess()
.subscribe(
(rideSuccess: RideSuccess[]) => {
this.rideSuccess = rideSuccess;
}
);
成功的搭乘 HTML:
<table class="responstable" id="responsetable">
<tr>
<th data-th="Driver details"><span>Driver name</span></th>
<th>Rider Name</th>
<th>Pool ID</th>
<th>Amount</th>
<th>Source</th>
<th>Destination</th>
<th>Sum ID</th>
<th></th>
</tr>
<tr *ngFor="let ridesuccess of rideSuccess| paginate: { itemsPerPage: 5, currentPage: p }; let i = index" >
<td>{{ridesuccess.driverName}}</td>
<td>{{ridesuccess.riderName}}</td>
<td>{{ridesuccess.poolId}}</td>
<td>{{ridesuccess.amount}}</td>
<td>{{ridesuccess.source}}</td>
<td>{{ridesuccess.destination}}</td>
<td>{{ridesuccess.sumId}}</td>
<td><button type="button" class="btn btn-success" data-toggle="modal" data-target="#myModal" (click)="setmodal(ridesuccess)">Gratify</button></td>
</tr>
</table>
<pagination-controls (pageChange)="p = $event" class="my-pagination" style="float: right"></pagination-controls>
现在我想在HTML中实现一个按钮,点击后将完整的表格数据下载到Excel文件中。
注意:我有所有数据在我的Angular服务(getRideSuccess())中。我想从我的Angular对象中下载数据,该对象使用服务(getRideSuccess())进行填充。
Package.json:
{
"name": "pagination",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www",
"build": "del-cli public/js/app && webpack --config webpack.config.dev.js --progress --profile --watch",
"build:prod": "del-cli public/js/app && ngc -p tsconfig.aot.json && ngc -p tsconfig.aot.json && webpack --config webpack.config.prod.js --progress --profile --bail && del-cli 'public/js/app/**/*.js' 'public/js/app/**/*.js.map' '!public/js/app/bundle.js' '!public/js/app/*.chunk.js' 'assets/app/**/*.ngfactory.ts' 'assets/app/**/*.shim.ts' 'assets/app/**/*.ngsummary.json' 'assets/app/**/*.ngstyle.ts'"
},
"dependencies": {
"@angular/animations": "^4.0.0",
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/compiler-cli": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/forms": "^4.0.0",
"@angular/http": "^4.0.0",
"@angular/platform-browser": "^4.0.0",
"@angular/platform-browser-dynamic": "^4.0.0",
"@angular/platform-server": "^4.0.0",
"@angular/router": "^4.0.0",
"@angular/upgrade": "^4.0.0",
"angular2-bootstrap-confirm": "^1.0.4",
"angular2-csv": "^0.2.5",
"bcryptjs": "^2.4.3",
"body-parser": "~1.15.2",
"chart.js": "^2.5.0",
"cookie-parser": "~1.4.3",
"core-js": "^2.4.1",
"debug": "~2.2.0",
"express": "~4.14.0",
"hbs": "~3.1.0",
"jsonwebtoken": "^7.4.0",
"mongoose": "^4.9.6",
"mongoose-sequence-plugin": "^1.0.5",
"mongoose-unique-validator": "^1.0.5",
"morgan": "~1.6.1",
"ng2-charts": "^1.5.0",
"ngx-pagination": "^3.0.1",
"reflect-metadata": "^0.1.3",
"rxjs": "^5.2.0",
"serve-favicon": "~2.3.0",
"shortid": "^2.2.8",
"zone.js": "^0.8.5"
},
"devDependencies": {
"@types/core-js": "0.9.36",
"@types/node": "^6.0.45",
"angular-router-loader": "^0.5.0",
"angular2-template-loader": "^0.5.0",
"awesome-typescript-loader": "^3.1.2",
"del-cli": "^0.2.0",
"html-loader": "^0.4.4",
"raw-loader": "^0.5.1",
"ts-loader": "^2.0.3",
"typescript": "^2.1.4",
"webpack": "^2.2.1",
"webpack-merge": "^4.1.0"
},
"main": "app.js",
"author": "",
"license": "ISC",
"description": ""
}