Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ng-json-to-file

shiny14105ISC0.0.3TypeScript support: included

This library helps to convert and download json data to excel and csv files

json to file converter, file converter, excel converter, csv converter, json to excel, json to csv, download excel, download csv

readme

NgJsonToFile

This library helps to convert and download json data to excel and csv files

Installation

Run npm i ng-json-to-file

Implementation

STEP 1:

You need to import the NgJsonToFileModule by adding the following lines to your app.module.ts file.

import { NgJsonToFileModule } from 'ng-json-to-file';
…
@NgModule ({....
imports: [...,
NgJsonToFileModule,
…]
})

STEP 2:

Add the <json-to-file> tag to the component where you want to download the file like so:

```
<json-to-file [headers]="headers" [columnNames]="columns" 

[fileName]="'fileName'" [sheetName]="'sheetName'" [jsonData]="jsonData" [excelId]="''excelId'" [csvId]="'csvId'"></json-to-file> `

Param usage:

1)`jsonData` input is used to pass your json data in a predefined format as mentioned in the below example.

Ex: jsonData = [{ empId: 'EMP001', fName: 'Jolly', age: 25, location: 'somthing' }, { empId: 'EMP002', fName: 'Macias', age: 29, location: 'somthing' }, { empId: 'EMP003', fName: 'Lucian', age: 25, location: 'somthing' }]

 2)'headers' input is used to display column header name in excel/csv. The 'headers' format should be passed like the example below.

Ex: headers = ['EmployeeId', 'Full Name', 'Age'];

 3)'columnNames' is used  to map the property in json data that you passed, to show in the respective column in the excel. 'columnNames' input is used to pass the column names corresponding to headers passed. Column name should be matching with the attribute of json data passed.

Ex: columnNames = ['empId', 'fName', 'age']; jsonData = [{ empId: 'EMP001', fName: 'Jolly', age: 25, location: 'somthing' }]

NOTE: The length of headers and column names should be equal else it will lead to empty cells in the excel/csv

Ex: headers = ['EmployeeId', 'Full Name', 'Age']; length(3) columnNames = ['empId', 'fName', 'age']; length(3)

4)'fileName' param is used to save the file in the given name.
Ex: fileName = 'your_file_name'

5)'sheetName' param is used to create the excel with the new sheet name which you provide.
Ex: sheetName = 'your_sheet_name'

6)'excelId' is to pass your tag id on click of which you want to download the files (excel/csv)
Ex: <button id="excelId">download excel</button>
     excelId = 'excelId'

6)'csvId' is to pass your tag id on click of which you want to download the files (excel/csv)
Ex: <button id="csvId">download csv</button>
     csvId = 'csvId'

Running

`ng serve`