ng-table-to-file
v0.0.5
Published
This library helps to convert and download html table to excel and csv files
Downloads
1
Maintainers
Readme
NgTableToFile
This library helps to convert and download html table to excel and csv files
Installation
Run npm i ng-table-to-file
Implementation
STEP 1:
You need to import the NgTableToFileModule
by adding the following lines to your app.module.ts file.
import { NgTableToFileModule } from 'ng-table-to-file';
…
@NgModule ({....
imports: [...,
NgTableToFileModule,
…]
})
STEP 2:
Add the <table-to-file>
tag to the component where you want to download the file like so:
<table-to-file [excelId]="'excel'" [csvId]="'csv'" [tableId]="'excel-table'" [fileName]="'dummy'" [sheetName]="'dummySheet'" [headers]="headers"></table-to-file>
Param usage:
1)'fileName' param is used to save the file in the given name.
Ex: fileName = 'your_file_name'
2)'sheetName' param is used to create the excel with the new sheet name which you provide.
Ex: sheetName = 'your_sheet_name'
3)'headers' input is used to display column header name in excel/csv. The 'headers' format should be passed like the example below. This is optional. If not passing , the default header name in the html table will be displayed.
Ex: headers = ['EmployeeId', 'Full Name', 'Age'];
4)'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'
5)'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'
6)'tableId' is to pass the id which you mapped to the html table tag
Ex: tableId = 'excel-id'
<table id="excel-id">
<tr>
<th>Id</th>
<th>Name</th>
<th>Age</th>
<th>Location</th>
</tr>
<tr>
<td>1</td>
<td>Jolly</td>
<td>30</td>
<td>chennai</td>
</tr>
</table>
Running
`ng serve`