Note that there are some explanatory texts on larger screens.

plurals
  1. POExport to CSV using jQuery and html
    text
    copied!<p>I have a tabular data which I need to export to csv without using any external plugin or api. I used the <code>window.open</code> method passing the mime types but faced issues like below:</p> <p><a href="https://stackoverflow.com/questions/15918173/how-to-determine-whether-microsoft-excel-or-open-office-is-installed-on-the-syst">How to determine whether Microsoft Excel or Open Office is installed on the system using jquery</a></p> <p>The code should be independent of the fact that what is being installed on the system i.e., openoffice or ms excel. I believe CSV is the format which can be expected to show in both the editors.</p> <p><strong>CODE</strong></p> <pre><code> &lt;html&gt; &lt;head&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/JavaScript"&gt; $(document).ready(function(){ $("#btnExport").click(function(e) { var msg = GetMimeTypes(); //OpenOffice window.open('data:application/vnd.oasis.opendocument.spreadsheet,' + $('#dvData').html()); //MS-Excel window.open('data:application/vnd.ms-excel,' + $('#dvData').html()); //CSV window.open('data:application/csv,charset=utf-8,' + $('#dvData').html()); e.preventDefault(); }); }); function GetMimeTypes () { var message = ""; // Internet Explorer supports the mimeTypes collection, but it is always empty if (navigator.mimeTypes &amp;&amp; navigator.mimeTypes.length &gt; 0) { var mimes = navigator.mimeTypes; for (var i=0; i &lt; mimes.length; i++) { message += "&lt;b&gt;" + mimes[i].type + "&lt;/b&gt; : " + mimes[i].description + "&lt;br /&gt;"; } } else { message = "Your browser does not support this "; //sorry! } return ( message); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="dvData"&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt;Column One &lt;/th&gt; &lt;th&gt;Column Two&lt;/th&gt; &lt;th&gt;Column Three&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;row1 Col1&lt;/td&gt; &lt;td&gt;row1 Col2&lt;/td&gt; &lt;td&gt;row1 Col3&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;row2 Col1&lt;/td&gt; &lt;td&gt;row2 Col2&lt;/td&gt; &lt;td&gt;row2 Col3&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;row3 Col1&lt;/td&gt; &lt;td&gt;row3 Col2&lt;/td&gt; &lt;td&gt;row3 Col3&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;br/&gt; &lt;input type="button" id="btnExport" value=" Export Table data into Excel " /&gt; &lt;/body&gt; </code></pre> <p>Errors:</p> <p><strong>CSV:</strong> Unrecognised over the browsers</p> <p><strong>ODS &amp; Excel:</strong> is working but I am not able to find which one to generate when system is having an excel installed or openoffice installed?</p> <p><strong>IE</strong> version 8 : it is totally not working, opens in a new window and as below screenshot.</p> <p><img src="https://i.stack.imgur.com/Ms7KU.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload