SOURCE

console 命令行工具 X clear

                    
>
console
$(function(){
    $(".in").html("<input  onkeydown='CalSN()' class = 'newin' />");

    $("a").click(function(){exportPathMethod(exportDataSource)});

})
function CalSN() {
    if ($(".StartSN").val().length() >= 6) {
        if ($(".Amount").val() > 0 && $(".Amount").val() < 99999) {
            var count = int.parseInt($(".Amount").val());
            var StartSN = $(".StartSN").val();
            var StartTailNum = 100000 + int.parseInt(StartSN.substring(StartSN.length - 5, 5));

            var EndSN = StartSN.substring(0, StartSN.length - 5) + (StartTailNum + count - 1).toString().substring(1, 5);
            $(".EndSN").val(EndSN);
        }
    }
}


var exportDataSource = [{
                    name: '路人甲',
                    phone: '123456789',
                    email: '000@123456.com'
                }, {
                    name: '炮灰乙',
                    phone: '123456789',
                    email: '000@123456.com'
                }, {
                    name: '土匪丙',
                    phone: '123456789',
                    email: '000@123456.com'
                }, {
                    name: '流氓丁',
                    phone: '123456789',
                    email: '000@123456.com'
                }, ]; //导出json数据源

function export1() {
            JSONToOrderExcelConvertor(exportDataSource);
        }
//json数据转excel
    function JSONToOrderExcelConvertor(JSONData) {
        var str = 'NO,姓名,电话,邮箱\n';

        for(let i=0;i<JSONData.length;i++){
            var result ='';
            if (JSONData[i].orderStatusc=='0'){
                result="是";
            } else {
                result="否";
            }
            str += (i+1).toString()+','+JSONData[i].name+'\t'+','+JSONData[i].phone+'\t'+','+JSONData[i].email+'\t'+',\n'

        }
        alert(str);
        var blob = new Blob([str], {type: "text/plain;charset=utf-8"});
        //解决中文乱码问题
        blob =  new Blob([String.fromCharCode(0xFEFF), blob], {type: blob.type});
        object_url = window.URL.createObjectURL(blob);
        var link = document.createElement("a");
        link.href = object_url;
        link.download =  "导出订单.xls";
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
    }

    //json数据转excel
    function JSONToExcelConvertor(JSONData, FileName) {
        //先转化json
        var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData;
        var excel = '<table>';
        var row = "<tr>";
        //设置表头
        var keys = Object.keys(JSONData[0]);
        keys.forEach(function (item) {
            row += "<td>" + item + '</td>';
        });
        //换行
        excel += row + "</tr>";
        //设置数据
        for (var i = 0; i < arrData.length; i++) {
            var row = "<tr>";
            for (var index in arrData[i]) {
                console.log(arrData[i][index]);
                //var value = arrData[i][index] === "." ? "" : arrData[i][index];
                row += '<td>' + arrData[i][index] + '</td>';
            }
            excel += row + "</tr>";
        }

        excel += "</table>";

        var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
        excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">';
        excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel';
        excelFile += '; charset=UTF-8">';
        excelFile += "<head>";
        excelFile += "<!--[if gte mso 9]>";
        excelFile += "<xml>";
        excelFile += "<x:ExcelWorkbook>";
        excelFile += "<x:ExcelWorksheets>";
        excelFile += "<x:ExcelWorksheet>";
        excelFile += "<x:Name>";
        excelFile += "{worksheet}";
        excelFile += "</x:Name>";
        excelFile += "<x:WorksheetOptions>";
        excelFile += "<x:DisplayGridlines/>";
        excelFile += "</x:WorksheetOptions>";
        excelFile += "</x:ExcelWorksheet>";
        excelFile += "</x:ExcelWorksheets>";
        excelFile += "</x:ExcelWorkbook>";
        excelFile += "</xml>";
        excelFile += "<![endif]-->";
        excelFile += "</head>";
        excelFile += "<body>";
        excelFile += excel;
        excelFile += "</body>";
        excelFile += "</html>";

        var uri = 'data:application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent(excelFile);

        var link = document.createElement("a");
        link.href = uri;

        link.style = "visibility:hidden";
        link.download = FileName + ".xls";

        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
    }

    function exportPathMethod(data) {
        //要导出的json数据
        var jsonData = [];
        for(var i=0; i<data.length ; i++){
            jsonData.push({
                index :i+1,
                name: data[i].name,
                phone: data[i].phone,
                email :data[i].email
            });
        }

        //列标题,逗号隔开,每一个逗号就是隔开一个单元格
        let str = `index,name,phone,email\n`;
        //增加\t为了不让表格显示科学计数法或者其他格式
        for(let i = 0 ; i < jsonData.length ; i++ ){
            for(let item in jsonData[i]){
                str+=`${jsonData[i][item] + '\t'},`;
            }
            str+='\n';
        }

        //encodeURIComponent解决中文乱码
        let uri = 'data:text/csv;charset=utf-8,\ufeff' + encodeURIComponent(str);
        //通过创建a标签实现
        var link = document.createElement("a");
        link.href = uri;
        //对下载的文件命名
        link.download =  "json数据表.xls";
        document.body.appendChild(link);
        link.click();
    }
<a style="float: left;">导出下载</a>
<div  class="in">
<input/>
</div>

本项目引用的自定义外部资源