javascript - How to export excel from Angular 8 with headers from string array - Stack Overflow

I want to export an excel file from my angular project. Headers of excel should be taken from a string

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
Add a ment  | 

2 Answers 2

Reset to default 2

Well, 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信