2014-10-10 21 views
0

我從前同事接管了一個C#實體框架項目。他用我不熟悉Javascript的方式設置了幾個表格。我需要將這個數據表的內容導出到一個Excel和PDF文件(每個單獨的按鈕)。我願意使用C#,Javascript或JQuery。C#/ Javascript數據表導出爲Excel和PDF

最近我一直在做ColdFusion,在將近一年的時間裏甚至都沒有看過任何.NET相關的東西,所以我想要得到一個複習以及找出以前從未見過的東西,所以我的思想油炸。

JavaScript代碼用於填充數據表:

   $(document).ready(function() { 

        var active = true; 

        GetList(active); 
       }); 

       function ChangeList() 
       { 
        GetList($("#ddlRiderType").val()); 
       } 

       function GetList(isActive) { 

        $('#dataTable').dataTable({ 
         "sDom": '<"top"lf>rt<"bottom"ip><"clear">', 
         "bAutoWidth": false, 
         "bProcessing": true, 
         "bSort": true, 
         "bDestroy": true, 
         "sPaginationType": "full_numbers", 
         "bServerSide": true, 
         "sAjaxSource": "Instructor.aspx/GetAllInstructors", 
         "fnServerData": function (sSource, aoData, fnCallback) { 

          var jsonData = "{jsonAOData : '" + JSON.stringify(aoData) + "', isActive: '" + isActive + "'}"; 

          $.ajax({ 
           //dataType: 'json', 
           contentType: "application/json; charset=utf-8", 
           type: "POST", 
           url: sSource, 
           data: jsonData, 
           complete: function() { Init(); }, 
           success: function (msg) { 
            if (msg.d != null) 
             fnCallback(msg.d); 
           }, 
           error: function (XMLHttpRequest, textStatus, errorThrown) { 
            ntfy_push("Error", ServerFail()); 
           } 
          }); 
         }, 
         "aoColumnDefs": [ 

       { "sName": "Cipher", 
        "aTargets": [0], 
        "bVisible": false, 
        "bSearchable": false 
       }, 
       { "sName": "firstName", 
        "aTargets": [1] 
       }, 
       { "sName": "lastName", 
        "aTargets": [2] 
       }, 
       { "sName": "org", 
        "aTargets": [10] 
       }, 
       { "sName": "workPhone", 
        "aTargets": [4] 
       }, 
       { "sName": "altPhone", 
        "aTargets": [5], 
        "bVisible": false, 
        "bSearchable": false 
       }, 
       { "sName": "cellPhone", 
        "aTargets": [6], 
        "bVisible": false, 
        "bSearchable": false 
       }, 
       { "sName": "email", 
        "aTargets": [7] 
       }, 
       { "sName": "riderCoach", 
        "aTargets": [8], 
        "bVisible": false, 
        "bSearchable": false 
       }, 
       { "sName": "rangeAid", 
        "aTargets": [9], 
        "bVisible": false, 
        "bSearchable": false 
       }, 
       { "sName": "admin", 
        "aTargets": [3] 
       }, 
       { "sName": "seniorInst", 
        "aTargets": [11], 
        "bVisible": false, 
        "bSearchable": false 
       }, 
       { "sName": "dateAdded", 
        "aTargets": [12], 
        "bVisible": false, 
        "bSearchable": false 
       }, 
       { "sName": "dateMod", 
        "aTargets": [13], 
        "bVisible": false, 
        "bSearchable": false 
       }, 
       { "sName": "modBy", 
        "aTargets": [14], 
        "bVisible": false, 
        "bSearchable": false 
       }, 
       { "sName": "active", 
        "aTargets": [15], 
        "bVisible": false, 
        "bSearchable": false 
       }, 
       { "sName": "delete", 
        "aTargets": [16], 
        "bVisible": false, 
        "bSearchable": false 
       }, 
       { "fnRender": function() { 
        return "Edit"; 
       }, 
        "aTargets": [17] 
       }, 
       { "fnRender": function() { 
        return "Delete"; 
       }, 
        "aTargets": [18] 
       } 
      ], 
         "sDom": '<"toolbar">flrtip' 
        }); 

        $("div.toolbar").html("<div class = 'tableOption'><img src = 'image/button/new-icon.png'/ alt= 'Add New Class' style = 'cursor:pointer' onclick = 'Show_New_Instructor()'></div>"); 
       } 

的DataTable用於頭

<table id = "dataTable"> 
<thead> 
    <tr> 
     <th>Instructor ID</th> 
     <th>First Name</th> 
     <th>Last Name</th> 
     <th>Admin</th> 
     <th>Work Phone</th> 
     <th>Alt Phone</th> 
     <th>Cell Phone</th> 
     <th>Email Address</th> 
     <th>Rider Coach</th> 
     <th>Range Aid</th> 
     <th>Organ</th> 
     <th>Senior Inst</th> 
     <th>Date Added</th> 
     <th>Date Modified</th> 
     <th>Mod By</th> 
     <th>Active</th> 
     <th></th> 
    </tr> 
</thead> 

<tbody></tbody> 
</table> 

的Excel按鈕:

PDF按鈕:

我謝謝ü提前尋求幫助,如果這已經發布在某個地方,我會爲眺望它而道歉。

回答