Javascript 或 Flash 导出到 CSV/Excel [英] Javascript or Flash export to CSV/Excel

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

问题描述

有没有办法在不与服务器端进行任何交互的情况下将 JSON 数据导出到 CSV/Excel?只使用 Javascript?或闪存?我目前正在使用 ZeroClipboard 将值复制到剪贴板,但我想从浏览器(FF、Chrome、IE 等...)直接将生成的值打开到 Excel 中.

Is there anyway to export JSON data to CSV/Excel without any interaction with the server side? Using Javascript only? or Flash? I'm currently using ZeroClipboard to copy the value into the clipboard but I'd like to open directly the generated value into Excel from the browser (FF, Chrome, IE, etc...).

谢谢.

推荐答案

从表到 Excel 的最干净、最简单的导出是Jquery DataTables 表格工具插件.您将获得一个用于对数据进行排序、过滤、排序和分页的网格,只需添加几行额外代码和两个小文件,您就可以导出到 ExcelPDFstrong>、CSV剪贴板打印机.

Far and away, the cleanest, easiest export from tables to Excel is Jquery DataTables Table Tools plugin. You get a grid that sorts, filters, orders, and pages your data, and with just a few extra lines of code and two small files included, you get export to Excel, PDF, CSV, to clipboard and to the printer.

这是所有需要的代码:

$(document).ready( function () {
    $('#example').dataTable( {
        "sDom": 'T<"clear">lfrtip',
        "oTableTools": {
        "sSwfPath": "/swf/copy_cvs_xls_pdf.swf"
        }
    } );
} );

因此,部署速度快,没​​有浏览器限制,不需要服务器端语言,而且最重要的是非常容易理解.这是一个双赢.但是,它确实有限制的一件事是列的严格格式.

So, quick to deploy, no browser limitations, no server-side language required, and most of all very EASY to understand. It's a win-win. The one thing it does have limits on, though, is strict formatting of columns.

这篇关于Javascript 或 Flash 导出到 CSV/Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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