首页 > 解决方案 > 使用 Angular2Csv 插件导出到 xls

问题描述

我正在尝试将来自 api 的数据对象数组导出到 xls。我可以使用插件将数据导出到 xls 。但这里的技巧是只将选定的列导出到 xls。我有一个来自 api 的 5 个对象的数组。我只需要将其中的 2 个导出到 xls。我怎样才能做到这一点?我附上了 [![在此处输入图像描述][1]][1] 生成的报告的快照,其中包含 5 列,但我只需要其中的 2 列。请建议。

这是使用的插件:https ://www.npmjs.com/package/angular2-csv

标签: angularapiexport-to-csv

解决方案


您可以导出选定的列。有可能的。首先你声明一个数组。比从来自 api 的列表中提取要显示的所需列,然后将它们存储到变量中。之后,您使用 for 循环并将它们推入 arry `this.lstEmployees = this.employee; // 显示活跃员工 //excelSheet 开始

      for (var i = 0; i < this.lstEmployees.length; i++) {
        this.data.push(
          {
            Item_Description: this.lstEmployees[i].ITM_DES,
            Unit_Of_Measurement: this.lstEmployees[i].UOM_ABR,
            Item_Rate: this.lstEmployees[i].QTD_RTE,
            Item_Price: this.lstEmployees[i].QTY_PRC,
            Item_Quotation: this.lstEmployees[i].QTN_NUM,
            Paymen_type: this.lstEmployees[i].PMT_FLG,
            Tax_Type: this.lstEmployees[i].TAX_FLG,
            Delivery_Type: this.lstEmployees[i].DLV_FLG,
          })

      }`

这里 lstEmployee 是来自数据库的列表,数据是数组。希望你明白了


推荐阅读