使用angularjs导出到xls [英] Export to xls using angularjs

查看:127
本文介绍了使用angularjs导出到xls的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用角度的js应用程序,我遇到了一种情况,我必须使用角度js将数据导出到Xls。我在互联网上搜索了很多出口功能或任何图书馆的角度js,所以我可以做到这一点,或至少我可以得到如何导出的想法。我没有任何代码或工作来显示这里。

I am working on angular js app and I stuck in a situation in which I have to export data to Xls using angular js. I have searched a lot on the internet for export functionality or any library for angular js so I can do that or at least I can get the idea how to export. I don't have any code or work to show here.

我需要建议。请帮忙我

提前感谢

更新:

我有一个数据是一个对象数组,我在一个表中的UI上迭代。我的后端是node.js,前端是角度js。

I have a data which is an array of objects and I am iterating that on UI in a table. My backend is node.js and frontend are angular js.

我的问题是如果我们有来自服务器的数据,我在UI上使用,我该怎么用使用角度js将相同的数据导出到Xls。我不想再在后端再次打电话来提取数据并导出。

My problem is if we have the data from the server and I am using on UI, how can I use the same data to export to Xls using angular js. I don't want to give a call again on the backend to extract the data and export that.

在现有表格中,用户可以选择复选框(任意数量的行或所有行)将数据提取到Xls。

In the existing table, the user can select the checkbox (Any number of rows or all rows) to extract the data to Xls.

在node.js中,我使用的名称为:Excel的节点模块,它在nodemodules网站上可用。

In node.js I have used node module whose name is: Excel and it is available on nodemodules site.

我的数据是这样的:

"data": [
    {
        "Name": "ANC101",
        "Date": "10/02/2014",
        "Terms": ["samsung", "nokia": "apple"]
    },{
        "Name": "ABC102",
        "Date": "10/02/2014",
        "Terms": ["motrolla", "nokia": "iPhone"]
    }
]

我想要使用angularjs或任何angularjs库的解决方案。

I want the solution using angularjs or any angularjs library.

推荐答案

这样做的一个便宜方法是使用Angular生成一个< table> 并使用 FileSaver.js 将表格输出为.xls文件供用户下载。 Excel将能够打开HTML表作为电子表格。

A cheap way to do this is to use Angular to generate a <table> and use FileSaver.js to output the table as an .xls file for the user to download. Excel will be able to open the HTML table as a spreadsheet.

<div id="exportable">
    <table width="100%">
        <thead>
            <tr>
                <th>Name</th>
                <th>Email</th>
                <th>DoB</th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="item in items">
                <td>{{item.name}}</td>
                <td>{{item.email}}</td>
                <td>{{item.dob | date:'MM/dd/yy'}}</td>
            </tr>
        </tbody>
    </table>
</div>

出口电话:

var blob = new Blob([document.getElementById('exportable').innerHTML], {
        type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
    });
    saveAs(blob, "Report.xls");
};

演示: http://jsfiddle.net/TheSharpieOne/XNVj3/1/

通过复选框功能和问题数据更新演示。
演示: http://jsfiddle.net/TheSharpieOne/XNVj3/3/

Updated demo with checkbox functionality and question's data. Demo: http://jsfiddle.net/TheSharpieOne/XNVj3/3/

这篇关于使用angularjs导出到xls的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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