【问题标题】:Export to Excel or CSV in Angular 6在 Angular 6 中导出到 Excel 或 CSV
【发布时间】:2018-09-07 05:05:51
【问题描述】:

我在 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 但无法理解如何实现上述格式。

【问题讨论】:

    标签: node.js mongodb angular6 export-to-excel export-to-csv


    【解决方案1】:

    我可以通过this example 下载 .xlsx 文件。

    【讨论】:

    • 谢谢,字体样式如何,我们有什么有用的参考吗?
    • 使用以下命令获取导入 npm install file-saver — save npm install xlsx — save
    猜你喜欢
    • 2015-02-08
    • 2011-12-30
    • 2010-09-23
    • 2010-11-01
    • 2015-09-20
    • 2017-01-03
    • 1970-01-01
    • 2019-03-30
    • 1970-01-01
    相关资源
    最近更新 更多