JQuery Import Export Excel

Source: Internet
Author: User

Working on a small project, querying data from the database in an HTML table. Now you want to export data from this table. Another user needs to select the exported columns. This needs to be done using the JQuery export plugin.

jQuery Plugin to Export HTML Tables

Example:

Import Plugins:

<script src= "Jquery-tableexport/tableexport.js" ></script><script src= "jquery-tableexport/ Jquery.base64.js "></script>
Html:

<a href="#" OnClick ="$(' #table-name ').Tableexport({type:' Excel ',Separator:'; ',Escape:' false '});" ID="Buttonexportdata" class="ui-btn ui-btn-inline ui-mini ui-shadow ui-corner-all">Export XLS</a>
The plugin also has these parameter options:

Separator: ', 'Ignorecolumn: [2,3],TableName:' Yourtablename 'type:' CSV 'pdffontsize: -Pdfleftmargin: -Escape:' true 'htmlcontent:' false 'ConsoleLog:' false '

You can specify which columns are not exported by Ignorecolumn.


Js-xlsx

You can use the JS-XLSX plug-in to import more than 2007 versions of Excel. First, import the JS package:

<!--https://github.com/SheetJS/js-xlsx/blob/master/jszip.js--><script src= "/path/to/jszip.js" ></ script><!--https://github.com/SheetJS/js-xlsx/blob/master/xlsx.js--><script src= "/path/to/xlsx.js" ></script>

node. JS Installation:

$ npm install xlsx $ node > require( ‘xlsx‘ ).readFile( ‘excel_file.xlsx‘ );

You can then use this plugin to convert the XLSX file to JSON, CSV, Formula output.

function Get_radio_value (radioname) {var radios = Document.getelementsbyname (radioname);        for (var i = 0; i < radios.length; i++) {if (radios[i].checked) {return radios[i].value;    }}} function To_json (workbook) {var result = {}; Workbook. Sheetnames.foreach (function (sheetname) {var roa = XLSX.utils.sheet_to_row_object_array (workbook.        Sheets[sheetname]);        if (Roa.length > 0) {result[sheetname] = Roa;    }    }); return result;}    function To_csv (workbook) {var result = []; Workbook. Sheetnames.foreach (function (sheetname) {var csv = XLSX.utils.sheet_to_csv (workbook.        Sheets[sheetname]);            if (Csv.length > 0) {result.push ("SHEET:" + sheetname);            Result.push ("");        Result.push (CSV);    }    }); return Result.join ("\ n");}    function To_formulae (workbook) {var result = []; Workbook. Sheetnames.foreach (function (sheetname) {var formulae = xlsx.uTils.get_formulae (workbook.        Sheets[sheetname]);            if (Formulae.length > 0) {result.push ("SHEET:" + sheetname);            Result.push ("");        Result.push (Formulae.join ("\ n"));    }    }); return Result.join ("\ n");}    var tarea = document.getElementById (' b64data '), function b64it () {var wb = Xlsx.read (Tarea.value, {type: ' base64 '}); PROCESS_WB (WB);}    function PROCESS_WB (WB) {var output = "";            Switch (get_radio_value ("format")) {case "json": output = Json.stringify (To_json (WB), 2, 2);        Break            Case "form": output = to_formulae (WB);         Break    Default:output = To_csv (WB);    } if (Out.innertext = = = undefined) out.textcontent = output; else Out.innertext = output;}    var drop = document.getElementById (' drop '), function Handledrop (e) {e.stoppropagation ();    E.preventdefault ();    var files = e.datatransfer.files;    var i,f; for (i = 0, f = files[i]; I! = Files.length; ++i) {       var reader = new FileReader ();        var name = F.name;            Reader.onload = function (e) {var data = E.target.result;            var wb = Xlsx.read (data, {type: ' binary '});            var arr = String.fromCharCode.apply (null, new Uint8array (data));            var wb = Xlsx.read (Btoa (arr), {type: ' base64 '});        PROCESS_WB (WB);        };        Reader.readasbinarystring (f);    Reader.readasarraybuffer (f);    }} function Handledragover (e) {e.stoppropagation ();    E.preventdefault (); E.datatransfer.dropeffect = ' copy ';}    if (Drop.addeventlistener) {drop.addeventlistener (' DragEnter ', Handledragover, false);    Drop.addeventlistener (' DragOver ', Handledragover, false); Drop.addeventlistener (' drop ', Handledrop, false);}
Plugin Author Address: author

JQuery Import Export Excel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.