Today in the project, encountered the front-end download Excel function, the result of the original code, as follows:
function Generate_excel (tableid) {
var table = document.getElementById (TableID);
var html = table.outerhtml;
window.open (' data:application/vnd.ms-excel;base64, ' + base64_encode (HTML));
}
This kind of writing, can only support ff,chrome, cannot support under IE. Search on the Internet, you can not find a better jquery plug-in, the ability to cross three platforms simultaneously, through the jquery way to export HTML table Excel.
Later, a chance coincidence, found a flash, can support a variety of browsers at the same time. For sites that do not repel the use of flash, it may be a solution.
However, currently used, this method has two drawbacks
You need to allow the flash to run in 1.firefox
Export in 2.IE, Excel line slightly somewhat problematic
Here's how to use
Flash: https://github.com/dcneiner/Downloadify
Example code:
In HTML
<p id= "Downloadify" >
<object id= "downloadify_obj" width= "" "height=" "type=" Application/x-shockwave-flash "name=" Downloadify_obj " Data= ". /.. /scripts/tableexport/downloadify.swf ">
<param name= "allowscriptaccess" value= "Always" >
<param name= "wmode" value= "Transparent" >
<param name= "Flashvars" value= "queue_name=downloadify&width=100&height=30&downloadimage=images/ Download.png ">
</object>
</p>
Among them, Data= ". /.. /scripts/tableexport/downloadify.swf ", downloadimage=images/download.png" need to change to their own corresponding path
JS in
<script type= "Text/javascript" >//<! [cdata[
Downloadify.create (' downloadify ', {
Filename:function () {
return "Data.xls";
},
Data:function () {
var table = document.getElementById (' table ');
var html = table.outerhtml;
return HTML;
},
Oncomplete:function () {
Alert (' Your File has Been saved! ');
},
Oncancel:function () {
Alert (' You are cancelled the saving of this file. ');
},
Onerror:function () {
Alert (' You must put something in the File Contents or there would be is nothing to save! ');
},
Transparent:false,
SWF: '.. /.. /scripts/tableexport/downloadify.swf ',
Downloadimage: '. /.. /scripts/tableexport/download.png ',
WIDTH:100,
Height:30,
Transparent:true,
Append:false
});
]]></script>
which
The name of filename was modified by itself,
In data, write the name of your table
SWF: '.. /.. /scripts/tableexport/downloadify.swf ',
Downloadimage: '. /.. /scripts/tableexport/download.png ',
Write your own corresponding path. Others can find their own online API
Support Ie,firefox,chrome three major browsers, through Js+flash way to export the table Excel file