Skip to content

How to add another header with one row in Angular5Csv generated Csv in Angular5? #32

@fahad88

Description

@fahad88

I have a custom component in Angular5 application named data-graph component. In that custom component i received data which i am exporting to Csv using Angular5Csv angular package which is downloading instantly on button click correctly. Here is that clicked function code from data-graph.component.ts

import { Angular5Csv } from 'angular5-csv/dist/Angular5-csv'
exportToCsv() { let fileName = this.sensors[0].meter.name + 'Sensors Report'; this.sensorsData.map(item => { if (item._id) { delete item._id; } item.Time = new Date(item.date).toLocaleString(); delete item.date; }) this.customData = this.sensorsData; let fields = Object.keys(this.customData[0]); var options = { fieldSeparator: ',', decimalseparator: '.', title: '', showLabels: true, showTitle: true, noDownload: false, headers: fields, }; new Angular5Csv(this.customData, fileName, options); let anotherCsv = new Angular5Csv(this.customData, fileName, options); }

This exports a csv with data and headers very correctly in this format :

 `F1      C1      P1        Time
 10.0   12.54    9.32   2/26/2019, 2:08:22 PM
 08.32  12.54    2.32   2/26/2019, 2:08:24 PM
 05.01  12.54    5.32   2/26/2019, 2:08:27 PM
 11.0   12.54    6.32   2/26/2019, 2:09:22 PM`

But i want to add another header with one row like this :

`Min     Max    Average
F1   05.01  11.0     09.32
C1   02.66  15.04    10.65
P1   2.32   6.32     3.44`

`F1      C1      P1        Time
10.0   12.54    9.32   2/26/2019, 2:08:22 PM
08.32  15.04    2.32   2/26/2019, 2:08:24 PM
05.01  04.33    5.32   2/26/2019, 2:08:27 PM
11.0   02.66    6.32   2/26/2019, 2:09:22 PM`

How can i achieve this result using angular5Csv?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions