2016-04-01 33 views
2

我從數據表導出excel表使用插件。在工作表中,除零(0)值之外,所有值均正確。In Datatable Excel導出零值在PHP中出錯錯誤

這是datatable的代碼。

$('#example').DataTable({ 
        //"scrollY": 300, 
        //"scrollX": true 
         dom: 'Bfrtip', 
        buttons: [ 
         { extend: 'excelHtml5', text: 'Get Excel' } 
        ], 
         "sScrollY" : "300", 
         "sScrollX" : true, 
         "bScrollCollapse" : true, 
         "bSort" : true, 
         "iDisplayLength": 5 


        }); 

我附上了錯誤的屏幕截圖。 enter image description here

+0

你需要檢查插件的出口代碼,並需要做修改那裏。還有其他值被視爲數字,除了0?是嗎? –

+0

如何知道其他值是否被視爲數字或字符串。你能幫我做些什麼修改,我需要做的插件。 –

回答

0

嘗試使用您的插件將字段類型設置爲數字值。

看起來像0被解釋爲字符串,這可以解釋左對齊。

+0

如何使用插件將字段類型設置爲數字值。你能解釋一下嗎? –

0

您必須對buttons.html5.min.js文件進行一些修改。 在buttons.html5.min.js和push方法中找到excelHtml5這個單詞 「number」=== typeof a [c] || a [c] .match & & g.trim(a [c])。match(/^- ?\ d +(。\ d +)?$ /)& & 「0」!== a [c]。的charAt(0) 取代「0」
或另一種方式只是加一個條件 !==(一個並[c] .charAt(0)& &一個並[c]。長度> 1) 它將工作,希望它會滿足您的要求。 所有最好.. !!

0

只需使用代替了Xcel按鈕CSV按鈕,它工作得很好: https://datatables.net/extensions/buttons/examples/html5/simple.html

要麼

$(document).ready(function() { 
    $('#example').DataTable({ 
     dom: 'Bfrtip', 
     buttons: [ 
      'copyHtml5', 
      'excelHtml5', 
      'csvHtml5', 
      'pdfHtml5' 
     ] 
    }); 
}) 

或更加人性化的方法(假設字體真棒,並應用一些CSS使其看起來更好一點)

//initialise the main table 
table = $('#report').DataTable({ 
    "bFilter": true, 
     "bSort": true, 
     "bInfo": true, 
     "scrollX": scrollX, 
    lengthChange: true, 
    fixedHeader: { 
     header: true, 
     footer: footerFixed 
    }, 
    buttons: [ 
     { 
      extend: 'copy', 
      text: '<i class="fa fa-files-o"></i>', 
      titleAttr: 'Copy' 
     }, 
     { 
      extend: 'csv', 
      text:  '<i class="fa fa-file-excel-o"></i>', 
      titleAttr: 'CSV', 
      title: 'Subscribers' 
     }, 
     { 
      extend: 'colvis', 
      text:  '<i class="fa fa-columns"></i>', 
      titleAttr: 'Columns' 
     }, 

    ], 
}); 

table.buttons().container() 
    .appendTo('#report_length'); 

$('#report_length > label').css('padding-right', '10px'); 
+0

總是歡迎與潛在解決方案的鏈接,但請在鏈接被刪除的情況下爲未來訪問者添加一些詳細信息。 –