如何使用angular 2将我的json数据导出为pdf,excel [英] How to export my json data into pdf,excel using angular 2

查看:25
本文介绍了如何使用angular 2将我的json数据导出为pdf,excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 angular 2 网站创建了我的数据表.现在我想使用 angular 2 框架将我的 json 数据导出为 PDF,excel.

I have created my Data table from the angular 2 website. Now I want to export my json data to PDF,excel using angular 2 framework.

请给我建议,如果你有的话,我怎样才能实现那个或任何链接.

Kindly give me suggestion how can I achieve that or any link if you have.

问候

推荐答案

我可以部分回答您的问题,以便您可以将 JSON 数据导出到 excel.您可以将 XLSX 库用于 Angular 2+.

I can answer your question partially so that you can export your JSON data to excel. You can use XLSX library for Angular 2+.

假设您的 JSON 数据类似于分配给 readyToExport 的数据,因此它显示了如何导出您的 JSON 数据.

Assuming your JSON data will be something like what assigned to readyToExport and hence it is shown how to export your JSON data.

public export() {
const readyToExport = [
  {id: 1, name: 'a', address: 'x'},
  {id: 2, name: 'b', address: 'y'},
  {id: 3, name: 'c', address: 'z'}
];

const workBook = XLSX.utils.book_new(); // create a new blank book
const workSheet = XLSX.utils.json_to_sheet(readyToExport);

XLSX.utils.book_append_sheet(workBook, workSheet, 'data'); // add the worksheet to the book
XLSX.writeFile(workBook, 'temp.xlsx'); // initiate a file download in browser
}

这篇关于如何使用angular 2将我的json数据导出为pdf,excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆