如何从 Angular Material 5 Mat-Table(Angular Material Table)导出 Excel 文件? [英] How to export Excel file from Angular Material 5 Mat-Table (Angular Material Table)?
问题描述
我是 Angular 的新手,使用 Angular 材料 5 mat-table 并尝试将表格导出到 excel 文件中.我使用了 SheetJS XLSX 包.
I am new to Angular and using Angular material 5 mat-table and trying to export the table in a excel file. I have use SheetJS XLSX package.
下面是我的代码:
Table.component.html:
<mat-table #table [dataSource]="dataSource" matSort>
<!-- ID Column -->
<!--<ng-container matColumnDef="ID">
<mat-header-cell *matHeaderCellDef mat-sort-header> UserID </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.UserID}} </mat-cell>
</ng-container>-->
<!-- Progress Column -->
<ng-container matColumnDef="MSID">
<mat-header-cell *matHeaderCellDef mat-sort-header> MSID </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.MSID}} </mat-cell>
</ng-container>
<ng-container matColumnDef="MSPW">
<mat-header-cell *matHeaderCellDef mat-sort-header> MS Password </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.MSPW}} </mat-cell>
</ng-container>
<ng-container matColumnDef="MSRequsest">
<mat-header-cell *matHeaderCellDef mat-sort-header> MS Requsest </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.MSRequsest}} </mat-cell>
</ng-container>
<ng-container matColumnDef="ClassID">
<mat-header-cell *matHeaderCellDef mat-sort-header> Class ID </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.ClassID}} </mat-cell>
</ng-container>
<ng-container matColumnDef="ClassName">
<mat-header-cell *matHeaderCellDef mat-sort-header> Class Name </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.ClassName}} </mat-cell>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="FirstName">
<mat-header-cell *matHeaderCellDef mat-sort-header> First Name </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.FirstName}} </mat-cell>
</ng-container>
<ng-container matColumnDef="LastName">
<mat-header-cell *matHeaderCellDef mat-sort-header> Last Name </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.LastName}} </mat-cell>
</ng-container>
<ng-container matColumnDef="Email">
<mat-header-cell *matHeaderCellDef mat-sort-header> Email </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.Email}} </mat-cell>
</ng-container>
<ng-container matColumnDef="Role">
<mat-header-cell *matHeaderCellDef mat-sort-header> Role </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.EmployeeRole}} </mat-cell>
</ng-container>
<ng-container matColumnDef="EmployeeRoleFrom">
<mat-header-cell *matHeaderCellDef mat-sort-header> Employee Role From </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.EmployeeRoleFrom}} </mat-cell>
</ng-container>
<ng-container matColumnDef="VendorID">
<mat-header-cell *matHeaderCellDef mat-sort-header> Vendor ID </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.VendorID}} </mat-cell>
</ng-container>
<ng-container matColumnDef="VendorNameCompany">
<mat-header-cell *matHeaderCellDef mat-sort-header> Vendor Name Company </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.VendorNameCompany}} </mat-cell>
</ng-container>
<ng-container matColumnDef="StaffID">
<mat-header-cell *matHeaderCellDef mat-sort-header> Staff ID </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.StaffID}} </mat-cell>
</ng-container>
<ng-container matColumnDef="Source">
<mat-header-cell *matHeaderCellDef mat-sort-header> Source </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.Source}} </mat-cell>
</ng-container>
<ng-container matColumnDef="HireDate">
<mat-header-cell *matHeaderCellDef mat-sort-header> Hire Date </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.HireDate}} </mat-cell>
</ng-container>
<ng-container matColumnDef="HireType">
<mat-header-cell *matHeaderCellDef mat-sort-header> Hire Type </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.HireType}} </mat-cell>
</ng-container>
<ng-container matColumnDef="EnteredDate">
<mat-header-cell *matHeaderCellDef mat-sort-header> Entered Date </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.EnteredDate}} </mat-cell>
</ng-container>
<ng-container matColumnDef="FloorDate">
<mat-header-cell *matHeaderCellDef mat-sort-header> Floor Date </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.FloorDate}} </mat-cell>
</ng-container>
<ng-container matColumnDef="SiteLocation">
<mat-header-cell *matHeaderCellDef mat-sort-header> Site Location </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.SiteLocation}} </mat-cell>
</ng-container>
<ng-container matColumnDef="EmployeeContractorID">
<mat-header-cell *matHeaderCellDef mat-sort-header> Employee Contractor ID </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.EmployeeContractorID}} </mat-cell>
</ng-container>
<ng-container matColumnDef="TransferFrom">
<mat-header-cell *matHeaderCellDef mat-sort-header> Transfer From </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.TransferFrom}} </mat-cell>
</ng-container>
<ng-container matColumnDef="Notes">
<mat-header-cell *matHeaderCellDef mat-sort-header> Notes </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.Notes}} </mat-cell>
</ng-container>
<ng-container matColumnDef="Status">
<mat-header-cell *matHeaderCellDef mat-sort-header> Status </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.Status}} </mat-cell>
</ng-container>
<!-- Action Column -->
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;">
</mat-row>
</mat-table>
<mat-paginator [pageSizeOptions]="[5, 10, 25, 100]"></mat-paginator>
</div>
Table.component.ts:
I am using npm i XLSX and getting some error.
我正在使用 npm i XLSX 并遇到一些错误.
ERROR:
错误:
错误范围 (0):A1:A0
Bad range (0): A1:A0
[object Error]{description: "Bad range (...", message: "Bad range (...", name: "Error", ngDebugContext: Object {...},堆栈:错误:错误..."}
[object Error]{description: "Bad range (...", message: "Bad range (...", name: "Error", ngDebugContext: Object {...}, stack: "Error: Bad ..."}
这里出了什么问题?
有没有其他方法可以从 Angular Material Table 导出 excel,我还需要表格的分页.
is there any other way to export excel from Angular Material Table, I also need the pagination for my table.
推荐答案
太晚了,但我尝试...我发现了同样的问题并以这种方式修复:从
Too late, but I try... I found the same problem and fixed this way: Change HTML tags from
到 ...
就是这样,XLSX 不识别材料标签,而是识别材料属性. That's all, XLSX not recognize material tags, but the material attributes. 这篇关于如何从 Angular Material 5 Mat-Table(Angular Material Table)导出 Excel 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
到
到 ...
登录
关闭