export HTML-table to excel/csv using javascript in IE (And all other browsers) -



export HTML-table to excel/csv using javascript in IE (And all other browsers) -

so have been trying export html-tables excel using javascript in ie. looks newer ie-browsers won't allow (version 11). different feedback ie is:

1.

webpage cannot displayed cause: •some content or files on webpage require programme don't have installed.

nothing happens...

when using activex, tells me not have supporting app this, , suggest me finding in app-store...

here of examples have tried:

var tabletoexcel = (function () { var uri = 'data:application/vnd.ms-excel;base64,' , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/tr/rec-html40"><head><!--[if gte mso 9]><xml><x:excelworkbook><x:excelworksheets><x:excelworksheet><x:name>{worksheet}</x:name><x:worksheetoptions><x:displaygridlines/></x:worksheetoptions></x:excelworksheet></x:excelworksheets></x:excelworkbook></xml><![endif]--></head><body><table>{table}</table></body></html>' , base64 = function (s) { homecoming window.btoa(unescape(encodeuricomponent(s))) } , format = function (s, c) { homecoming s.replace(/{(\w+)}/g, function (m, p) { homecoming c[p]; }) } homecoming function (table, name, filename) { if (!table.nodetype) table = document.getelementbyid(table) var ctx = { worksheet: name || 'worksheet', table: table.innerhtml } document.getelementbyid("dlink").href = uri + base64(format(template, ctx)); document.getelementbyid("dlink").download = filename; document.getelementbyid("dlink").click(); } })()

and:

<script type="text/javascript"> var tabletoexcel = (function() { var uri = 'data:application/vnd.ms-csv;base64,' , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas- microsoft-com:office:excel"' + 'xmlns="http://www.w3.org/tr/rec-html40">' + '<head><!--[if gte mso 9]><xml><x:excelworkbook><x:excelworksheets><x:excelworksheet> <x:name>{worksheet}</x:name><x:worksheetoptions>' + '<x:displaygridlines/></x:worksheetoptions></x:excelworksheet></x:excelworksheets></x:excelworkbook></xml>' + '<![endif]--></head><body><table>{table}</table></body></html>' , base64 = function(s) { homecoming window.btoa(unescape(encodeuricomponent(s))) } , format = function(s, c) { homecoming s.replace(/{(\w+)}/g, function(m, p) { homecoming c[p]; }) } homecoming function(table, name) { if (!table.nodetype) table = document.getelementbyid(table) var ctx = {worksheet: name || 'worksheet', table: table.innerhtml} window.location.href = uri + base64(format(template, ctx)) } })() </script>

and

$(document).ready(function () { console.log("hello") function exporttabletocsv($table, filename) { var $headers = $table.find('tr:has(th)') ,$rows = $table.find('tr:has(td)') // temporary delimiter characters unlikely typed keyboard // avoid accidentally splitting actual contents ,tmpcoldelim = string.fromcharcode(11) // vertical tab character ,tmprowdelim = string.fromcharcode(0) // null character // actual delimiter characters csv format ,coldelim = '";"' ,rowdelim = '"\r\n"'; // grab text table csv formatted string var csv = '"'; csv += formatrows($headers.map(grabrow)); csv += rowdelim; csv += formatrows($rows.map(grabrow)) + '"'; // info uri var csvdata = 'data:application/csv;charset=utf-8,' + encodeuricomponent(csv); $(this) .attr({ 'download': filename ,'href': csvdata //,'target' : '_blank' //if want open in new window }); //------------------------------------------------------------ // helper functions //------------------------------------------------------------ // format output has appropriate delimiters function formatrows(rows){ homecoming rows.get().join(tmprowdelim) .split(tmprowdelim).join(rowdelim) .split(tmpcoldelim).join(coldelim); } // grab , format row table function grabrow(i,row){ var $row = $(row); //for reason $cols = $row.find('td') || $row.find('th') won't work... var $cols = $row.find('td'); if(!$cols.length) $cols = $row.find('th'); homecoming $cols.map(grabcol) .get().join(tmpcoldelim); } // grab , format column table function grabcol(j,col){ var $col = $(col), $text = $col.text(); homecoming $text.replace('"', '""'); // escape double quotes } } // must hyperlink $("#export").click(function (event) { // var outputfile = 'export' var outputfile = window.prompt("what want name output file (note: won't have effect on safari)") || 'export'; outputfile = outputfile.replace('.csv','') + '.csv' // csv exporttabletocsv.apply(this, [$('#dvdata>table'), outputfile]); // if csv, don't event.preventdefault() or homecoming false // need typical hyperlink }); });

and

function fnexcelreport() { var tab_text="<table><tr>"; var textrange; tab = document.getelementbyid('testtable'); // id of actual table on page for(j = 0 ; j < tab.rows.length ; j++) { tab_text=tab_text+tab.rows[j].innerhtml; tab_text=tab_text+"</tr><tr>"; } tab_text = tab_text+"</tr></table>"; var txt = document.getelementbyid('txtarea1').contentwindow; txt.document.open("txt/html","replace"); txt.document.write(tab_text); txt.document.close(); txt.focus(); tb = txt.document.execcommand("saveas",true,"tablename.xls"); homecoming (tb); }

anyone have solution works on browsers + ie (version 7-11)?

<?php error_reporting(e_error); include("connection.php"); //header give order browser header('content-type: text/csv'); header('content-disposition: attachment;filename=exported-data.csv'); $select_table=mysql_query("select * table"); $rows = mysql_fetch_assoc($select_table); if ($rows) { getcsv(array_keys($rows)); } while($rows) { getcsv($rows); $rows = mysql_fetch_assoc($select_table); } // total number of fields nowadays in database function getcsv($no_of_field_names) { $separate = ''; // action field names field name foreach ($no_of_field_names $field_name) { if (preg_match('/\\r|\\n|,|"/', $field_name)) { $field_name = '' . str_replace('', $field_name) . ''; } echo $separate . $field_name; //sepearte comma $separate = ','; } //make new row , line echo "\r\n"; } ?>

javascript html excel internet-explorer

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -