Экспорт в Excel или CSV на Angular 6 - PullRequest
0 голосов
/ 07 сентября 2018

У меня есть следующая таблица в angular 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>

Я хочу экспортировать данные в настраиваемом формате, где в качестве полей будет указано 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    ...

Я перепробовал несколько методов и npm, но не смог понять, как добиться указанного выше формата.

1 Ответ

0 голосов
/ 05 октября 2018

Мне удалось загрузить файл .xlsx, следуя указаниям в этом примере .

...