I want to export an excel file from my angular project. Headers of excel should be taken from a string array which looks like:
excelHeaders:string[] = ["Name","Age","Email","Contact Number","Location"];
Excel file will have only headers without any other data.
Please help.
I want to export an excel file from my angular project. Headers of excel should be taken from a string array which looks like:
excelHeaders:string[] = ["Name","Age","Email","Contact Number","Location"];
Excel file will have only headers without any other data.
Please help.
Share Improve this question asked Dec 17, 2019 at 5:09 AbhiAbhi 6842 gold badges15 silver badges32 bronze badges 3- give more details like what is ponent code and template code which library using for this. – Avinash Dalvi Commented Dec 17, 2019 at 5:12
- please check this answer : stackoverflow./questions/58926366/… – Joel Joseph Commented Dec 17, 2019 at 5:14
- Have you checked stackoverflow./questions/333537/… The GitHub repo URL - github./agershun/alasql – Sujit Kumar Singh Commented Dec 17, 2019 at 6:10
2 Answers
Reset to default 2Well, this xlsx documentation helped me to solve the question. XLSX
import * as XLSX from 'xlsx';
...
excelHeaders:string[] = ["Name","Age","Email","Contact Number","Location"];
templateToExcel:string[][] = [this.excelHeaders,[]];
...
exportTemplateAsExcel()
{
const ws: XLSX.WorkSheet=XLSX.utils.aoa_to_sheet(this.templateToExcel);
const wb: XLSX.WorkBook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
XLSX.writeFile(wb,"test"+".xlsx");
}
You can use any of the client side excel generation libs via npm like - XLSX, XLSX-Style, ExcelJS.
Each of them has well defined set of methods to generate the workbook and inside the workbook creating the rows, header-rows etc. For example while using excel-js -
excelHeaders:string[] = ["Name","Age","Email","Contact Number","Location"];
let workbook = new Workbook();
let worksheet = workbook.addWorksheet('Test Sheet');
let headerRow = worksheet.addRow(excelHeaders);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744839747a4596483.html
评论列表(0条)