Я хочу иметь возможность экспортировать в формате Excel файлы моих таблиц DOM.
Моя функция (Typescript 3.5 / Angular 8)
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.xls');
}
Моя таблица:
<table id="serversTable" mat-table [dataSource]="serverArray" multiTemplateDataRows>
<ng-container matColumnDef="number">
<th mat-header-cell *matHeaderCellDef>Qty</th>
<td mat-cell *matCellDef="let resourceGroup">
...
</td>
</ng-container>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef>name</th>
<td mat-cell *matCellDef="let resourceGroup">
...
</td>
</ng-container>
<!-- Other columns -->
<ng-container matColumnDef="expandedDetail">
...
</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>
expandedDetail
- это столбец, который я не хочу, чтобы он был в файле, записанном функцией ExportTOExcel
. Этот столбец является последним столбцом моей таблицы.
Я пытался
ws['!cols'] = [];
ws['!cols'][0] = { hidden: true };
, но не работает.