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

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

问题描述

我正在开发 angular js 应用程序,但遇到了必须使用 angular js 将数据导出到 Xls 的情况.我在互联网上搜索了很多导出功能或角度 js 的任何库,所以我可以这样做,或者至少我可以了解如何导出.我没有任何代码或工作可以在这里展示.

我需要建议.请帮我解决这个问题.

提前致谢.

更新:

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

我的问题是,如果我们有来自服务器的数据并且我在 UI 上使用,我如何使用相同的数据通过 angular js 导出到 Xls.我不想在后端再次调用以提取数据并导出.

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

在 node.js 中,我使用了名称为 Excel 的节点模块,它可以在 nodemodules 站点上找到.

我的数据是这样的:

数据":[{"名称": "ANC101","日期": "10/02/2014",条款":[三星",诺基亚":苹果"]},{"名称": "ABC102","日期": "10/02/2014",条款":[摩托罗拉",诺基亚":iPhone"]}]

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

解决方案

一种廉价的方法是使用 Angular 生成一个

并使用 FileSaver.js 将表格输出为 .xls 文件供用户下载.Excel 将能够将 HTML 表格作为电子表格打开.

<表格宽度="100%"><头><tr><th>姓名</th><th>电子邮件</th><th>DoB</th></tr></thead>
<tr ng-repeat="项目中的项目"><td>{{item.name}}</td><td>{{item.email}}</td><td>{{item.dob |日期:'MM/dd/yy'}}</td></tr></tbody>

导出调用:

var blob = new Blob([document.getElementById('exportable').innerHTML], {类型: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/

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.

I need suggestions. Please help me on this.

Thanks in advance.

Update:

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.

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.

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

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

My data is like that:

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

I want the solution using angularjs or any angularjs library.

解决方案

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>

Export call:

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

Demo: http://jsfiddle.net/TheSharpieOne/XNVj3/1/

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

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

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