使用Angular2Csv插件导出到xls

时间:2018-04-25 19:29:29

标签: angular api export-to-csv

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

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

1 个答案:

答案 0 :(得分:0)

您可以导出选定的列。有可能的。首先,您声明一个数组。比从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是来自数据库的列表,数据是and数组。希望你明白了

相关问题