Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaScript Get Table Without First Column
    text
    copied!<p>I'm using a JavaScript function that I found on SO to export an HTML table to Excel. It works pretty well but I would like to exclude the first column of the HTML table when exporting to Excel. I can do this easily in jQuery but the function is in JS and I'm having trouble getting this to work. Can anyone suggest how I would modify this line of code to ignore the first column?</p> <pre><code>var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML} </code></pre> <p>where <code>table = document.getElementById("exporttable")</code></p> <p>EDIT - full code</p> <pre><code>&lt;script type="text/javascript"&gt; var tableToExcel = (function() { var uri = 'data:application/vnd.ms-excel;base64,' , template = '&lt;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"&gt;&lt;head&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;&lt;x:ExcelWorkbook&gt;&lt;x:ExcelWorksheets&gt;&lt;x:ExcelWorksheet&gt;&lt;x:Name&gt;{worksheet}&lt;/x:Name&gt;&lt;x:WorksheetOptions&gt;&lt;x:DisplayGridlines/&gt;&lt;/x:WorksheetOptions&gt;&lt;/x:ExcelWorksheet&gt;&lt;/x:ExcelWorksheets&gt;&lt;/x:ExcelWorkbook&gt;&lt;/xml&gt;&lt;![endif]--&gt;&lt;/head&gt;&lt;body&gt;&lt;table&gt;{table}&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;' , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) } , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) } return 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)) } })() &lt;/script&gt; &lt;input id="exporttoexcel" name="ExportToExcel" type="button" onclick="tableToExcel('exporttable', 'Tab Name')" value="Export to Excel"&gt; </code></pre>
 

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