2015-02-07 2 views
6

मैं एक्सेल फ़ाइल में तालिका डेटा निर्यात करने jQuery कोड का इस्तेमाल किया है, hereकस्टम फ़ाइल नाम प्रदान करना table2excel jquery में काम नहीं कर रहा है?

से कोड मिला है लेकिन प्रदान custome फ़ाइल नाम काम नहीं कर रहा यह यादृच्छिक फ़ाइल नाम ले रही है।
कोड से कस्टम फ़ाइल नाम कैसे प्रदान करें।

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

उत्तर

0

इस प्लगइन में name चर वर्कशीट, Excel फ़ाइल की नहीं नाम के नाम का उल्लेख है।

यदि आप फ़ाइल नाम बदलने में सक्षम होना चाहते हैं, तो आपको प्लगइन कोड को थोड़ा सा हैक करना होगा, या सिर्फ this one (जहां आप फ़ाइल नाम डाल सकते हैं) जैसी अन्य प्लगइन या कोड का टुकड़ा उपयोग करना होगा postfix परिवर्तनीय में)।

+0

आपको अपनी तालिका वाली div की शुरुआत में कुछ HTML लाइनें जोड़नी होंगी। अधिक जानकारी के लिए [यह] (http://forums.codecharge.com/posts.php?post_id=107155) देखें। – Linostar

0

आप इस प्रकार डाउनलोड के लिए अनुकूलित नाम देने के लिए table2excel jQuery हैक कर सकते हैं:

अपने js से:

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

फिर बदल table2excel में getFileName (e.settings) कॉल .js का पालन करने के लिए नाम:

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.Change यह

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

settings.name अपने कस्टम js स्क्रिप्ट जब से चर रहा है आप jquery2excel पर कॉल करें मेरे उदाहरण में यह

जैसा दिखता है
संबंधित मुद्दे