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

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

问题描述

我的工作angularjs应用程序,我在,我有将数据导出到使用XLS angularjs的情况下被卡住。我有很多搜索互联网上的导出功能或angularjs任何图书馆,所以我可以做,或至少我能得到的想法如何导出。我没有任何code或工作在这里显示。

I am working on angularjs app and I stucked in a situation in which I have to export data to xls using angularjs. I have searched alot on internet for export functionality or any library for angularjs so I can do that or atleast I can get the idea how to export. I dont have any code or work to show here.

我需要建议。请帮我在这。

I need suggestions. Please help me on this.

先谢谢了。

更新:

我有一个数据是对象数组,我迭代,关于UI在表中。我的后端的Node.js和前端是angularjs。

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

我的问题是,如果我们有来自服务器的数据和我使用的UI,我怎么能使用相同的数据使用angularjs出口到XLS。我不想在后端提取数据,并导出再给打电话。

My problem is if we have the data from server and i am using on UI, how can i use the same data to export to xls using angularjs. I dont want to give a call again on backend to extract the data and export that.

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

In existing table user can select 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.

推荐答案

一个廉价的方式做到这一点是使用角度来生成一个&LT;表&gt; ,并使用< A HREF =htt​​ps://github.com/eligrey/FileSaver.js/> FileSaver.js 来输出表作为xls文件供用户下载。 Excel将能够打开HTML表为A S preadsheet。

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').innerHTM], {
        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/

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

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