在Angular 6中导出为Excel或CSV

Amm*_*ang 1 export-to-excel mongodb node.js export-to-csv angular6

我有以下角度6中的表,该表是从数据库动态获取的。

<table *ngIf="attendanceModel.length > 0; else attendanceModel_else" class="table table-responsive" id="table">
    <thead>
      <tr>
        <th>Name</th>
        <th>Designation</th>
        <th>Morning Session</th>
        <th>Evening Session</th>
        <th>Total Hours</th>
        <th>Status</th>
      </tr>
    </thead>
    <tbody>
      <ng-container *ngFor="let attendance of attendanceModel | groupBy:'employee_id'">
        <tr>
          <td colspan="6" class="text-center text-muted"> &laquo; Name: {{ attendance.key }} &raquo; </td>
        </tr>
        <tr *ngFor="let attendance of attendance.value">
            <td>{{attendance.employee_id.profile.first_name}} {{attendance.employee_id.profile.last_name}}</td>
            <td>{{attendance.employee_id.designation}}</td>
            <td>{{attendance.morning_session}}</td>
            <td>{{attendance.evening_session}}</td>
            <td>{{attendance.total_hours | number:'1.0-1' }}</td>
            <td *ngIf="attendance.status == 'Verified'; else inactive_else">
              <a class="btn btn-link text-success p-0" (click)="notVerify(attendance._id)">{{attendance.status}}</a>
            </td>
            <ng-template #inactive_else>
              <td *ngIf="attendance.status == 'Not Verified'">
                <a class="btn btn-link text-danger p-0" (click)="verify(attendance._id)">{{attendance.status}}</a>
              </td>
            </ng-template>
          </tr>
      </ng-container>
    </tbody>
  </table>
Run Code Online (Sandbox Code Playgroud)

我想以自定义格式导出数据,其中字段将为employee_name,后跟任意数量的日期,具体取决于数据库。喜欢

Name            Date1       Date2        Date3      ...so on
Employee 1      1/2/2018    2/2/2018    2/3/2018    ...
Employee 2      1/2/2018    2/2/2018    2/3/2018    ...
Run Code Online (Sandbox Code Playgroud)

我已经尝试了许多方法和npm,但无法理解如何实现上述格式。

小智 7

通过遵循此示例,我能够下载.xlsx文件。