我的功能:
ExportTOExcel() {
const ws: XLSX.WorkSheet=XLSX.utils.table_to_sheet(document.getElementById('serversTable'));
const wb: XLSX.WorkBook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'Servers');
/* save to file */
XLSX.writeFile(wb, 'myproject.xlsx');
}
我的桌子:
<table id="serversTable" mat-table [dataSource]="serverArray" multiTemplateDataRows>
<ng-container matColumnDef="number">
<th mat-header-cell *matHeaderCellDef>Qty</th>
<td mat-cell ...>
...
</td>
</ng-container>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef>name</th>
<td mat-cell ...>
...
</td>
</ng-container>
<!-- Other columns -->
<ng-container matColumnDef="osType">
<th mat-header-cell *matHeaderCellDef>OS</th>
<td mat-cell *matCellDef="let resourceGroup">
<img src="..\..\assets\images\... alt="myimage">
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let resourceGroup; columns: displayedColumns;" class="example-
element-row" [class.example-expanded-row]="expandedElement === resourceGroup
(click)="clickOnRowDisk(resourceGroup)">
</tr>
<tr mat-row *matRowDef="let row; columns: ['expandedDetail']" class="example-detail-row"></tr>
</table>
当我执行我的函数时,出现“OS”列但它的单元格是空的,看起来 XLSX<img>
自己无法读取 html 标签。有解决方案吗?也许告诉他拿走alt
财产<img>
?(如果是的话如何)