2015-02-07 8 views
6

Użyłem kodu jQuery eksportować dane z tabeli do pliku excel, dostaje kod z herePodanie niestandardowej nazwy pliku nie działa w jQuery table2excel?

ale zapewnienie nazwa pliku custome nie działa ona bierze losową nazwę.
jak podać niestandardową nazwę pliku z kodu.

<script> 
$(function() { 
     $("button").click(function(){ 
     $("#example").table2excel({ 
       exclude: ".noExl", 
     name: "Employee" 
     }); 
     }); 
}); 
</script> 

Odpowiedz

0

name zmienna w tej wtyczki odnosi się do nazwy arkusza, a nie nazwa pliku Excel.

Jeśli chcesz mieć możliwość zmiany nazwy pliku, musisz trochę zhackować kod wtyczki lub po prostu użyć innej wtyczki lub fragmentu kodu, który odpowiada Twoim potrzebom, np. this one (gdzie możesz umieścić nazwę pliku w zmiennej postfix).

+0

Będziesz musiał dodać kilka wierszy html na początku elementu div zawierającego tabelę. Zobacz [to] (http://forums.codecharge.com/posts.php?post_id=107155), aby uzyskać więcej informacji. – Linostar

0

można siekać table2excel jQuery dać dostosowane nazwy do pobrania następujące:

z Twojego JS:

<script> 
 
$(function() { 
 
     $("button").click(function(){ 
 
     $("#example").table2excel({ 
 
       exclude: ".noExl", 
 
     name: "Employee.txt" //This name will be passed for download 
 
     }); 
 
     }); 
 
}); 
 
</script>

Następnie zmień getfilename (e.settings) połączenia w table2excel .js do nazwy jak następuje:

if (typeof msie !== "undefined" && msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))  // If Internet Explorer 
 
      { 
 
       if (typeof Blob !== "undefined") { 
 
        //use blobs if we can 
 
        fullTemplate = [fullTemplate]; 
 
        //convert to array 
 
        var blob1 = new Blob(fullTemplate, { type: "text/html" }); 
 
        window.navigator.msSaveBlob(blob1, name); // Changed Here 
 
       } else { 
 
        //otherwise use the iframe and save 
 
        //requires a blank iframe on page called txtArea1 
 
        txtArea1.document.open("text/html", "replace"); 
 
        txtArea1.document.write(e.format(fullTemplate, e.ctx)); 
 
        txtArea1.document.close(); 
 
        txtArea1.focus(); 
 
        sa = txtArea1.document.execCommand("SaveAs", true, name); // Changed Here 
 
       } 
 

 
      } else { 
 
       link = e.uri + e.base64(e.format(fullTemplate, e.ctx)); 
 
       a = document.createElement("a"); 
 
       a.download = name; // Changed Here 
 
       a.href = link; 
 

 
       document.body.appendChild(a); 
 

 
       a.click(); 
 

 
       document.body.removeChild(a); 
 
      }

0

1.Open jquery.table2excel.js

2.Find function getFileName(settings)

3. Zmień go

function getFileName(settings) { 
     return (settings.filename ? settings.filename : settings.name) + 
       (settings.fileext ? settings.fileext : ".xls"); 
} 

settings.name jest zmienna z niestandardowym js skrypty kiedy Wywołujesz jquery2excel W moim przykładzie wygląda on na:

$(".generateXLS").click(function(){ 
    var idOfTable = $(this).attr("data-rel"); 
    var tableName = $(this).attr("data-table-name"); 
    $("#tableN"+idOfTable).table2excel({ 
     name: tableName 
    }); 
}); 
Powiązane problemy