2016-12-07 70 views
0

在我的js文件中,我想使用ExcelPlus 2.4 js将json数据导出到excel文件。在这里检查http://aymkdn.github.io/ExcelPlus/。任何人都可以帮助我编写ExcelPlus 2.4 js语法,用于将json格式的数据从我的ajax调用成功部分导出到我的excel中。excel在客户端导出

function GetExcel() { 
     $.ajax({ 
      type: "POST", 
      url: "../TestHandler.ashx", 
      contentType: "application/json; charset=utf-8", 
      dataType: "json",   
      success: function (data) { 
       debugger; 

       ***var ep = new ExcelPlus(); 
       ep.createFile("Book1") 
        .write({ "content": data })** 
        .createSheet("Book2") 
        .write({ "cell": "A1", "content": "A1" }) 
        .write({ "sheet": "Book1", "cell": "D1", "content": new Date() }) 
        .saveAs("demo.xlsx");* 


       alert('success'); 
      }, 
      error: function (xhr, ajaxOptions, thrownError) { 
       alert("error"); 
      } 
     }); 
    } 

请帮我找到出口JSON数据到Excel(XLS/XLSX)文件的解决方案。请建议我使用JavaScript/jQuery插件,它具有所有浏览器支持。

+0

请帮我找到上面的场景一个JavaScript/jQuery插件。支持所有浏览器(ie8 +,chrome,mozilla等)。 – Sudha

回答

0

试试这个

function export() 
{ 
    var tab_text = ""; 
    var textRange; var j = 0; 
    tab = document.getElementById('your table id '); // id of table 
    for (j = 0; j < tab.rows.length; j++) { 
     tab_text = tab_text + tab.rows[j].innerHTML + "</tr>";  
    } 
    tab_text = tab_text + "</table>"; 
    tab_text = tab_text.replace(/<A[^>]*>|<\/A>/g, ""); 
    tab_text = tab_text.replace(/<img[^>]*>/gi, ""); 
    tab_text = tab_text.replace(/<input[^>]*>|<\/input>/gi, ""); 
    var ua = window.navigator.userAgent; 
    var msie = ua.indexOf("MSIE "); 
    if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))   // If Internet Explorer 
    { 
    txtArea1.document.open("txt/html", "replace"); 
    txtArea1.document.write(tab_text); 
    txtArea1.document.close(); 
    txtArea1.focus(); 
     sa = txtArea1.document.execCommand("SaveAs", true, "print.xls"); 
    } 
    else     //other browser not tested on IE 11 
     sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text)); 
    return (sa); 
} 
+0

我需要导出从我的.net应用程序后面的处理程序/代码检索的json格式数据。它将有近5lakh +行,预计excel文件大小近135MB。你可以建议一些JavaScript浏览器支持的JavaScript/jQuery插件吗? – Sudha

+0

表示您希望将json直接转换为excel或导出时出现的任何大小错误 – Pravin